Self hosted FLOSS fitness/workout, nutrition and weight tracker
More integration of angular
Roland Geider86ef5d5a0062
diff --git a/angular/src/app/app.component.html b/angular/src/app/app.component.htmlindex 197f55db2..c26b8874d 100644--- a/angular/src/app/app.component.html+++ b/angular/src/app/app.component.html@@ -1,13 +1,2 @@-<div class="container">-<div class="row">- <div class="col-12">-- <app-weight-list></app-weight-list>- <!--- <app-exercise-list></app-exercise-list>- -->- </div>-</div>-</div>-+ <router-outlet></router-outlet>diff --git a/angular/src/app/app.component.ts b/angular/src/app/app.component.tsindex 5629554a3..d069cb219 100644--- a/angular/src/app/app.component.ts+++ b/angular/src/app/app.component.ts@@ -3,8 +3,7 @@ import {Component} from '@angular/core';@Component({selector: 'app-root',templateUrl: './app.component.html',- styleUrls: ['./app.component.css']+ styleUrls: ['./app.component.css'],})export class AppComponent {- title = 'angular';}diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.tsindex a3a609048..85e3c3b3e 100644--- a/angular/src/app/app.module.ts+++ b/angular/src/app/app.module.ts@@ -16,11 +16,13 @@* along with this program. If not, see <http://www.gnu.org/licenses/>.*/+import {APP_BASE_HREF} from '@angular/common';import {HttpClientModule} from '@angular/common/http';import {NgModule} from '@angular/core';import {ReactiveFormsModule} from '@angular/forms';import {BrowserModule} from '@angular/platform-browser';import {BrowserAnimationsModule} from '@angular/platform-browser/animations';+import {RouterModule, Routes} from '@angular/router';import {NgbDropdownModule, NgbModalModule, NgbPaginationModule} from '@ng-bootstrap/ng-bootstrap';import {NgxChartsModule} from '@swimlane/ngx-charts';@@ -35,6 +37,12 @@ import {WeightEditComponent} from './weight/weight-edit/weight-edit.component';import {WeightListComponent} from './weight/weight-list/weight-list.component';import {WeightService} from './weight/weight.service';+const appRoutes: Routes = [+ {path: '', component: WeightListComponent},+ {path: ':lang/dashboard', component: WeightChartComponent},+ {path: ':lang/weight/overview', component: WeightListComponent},+];+@NgModule({declarations: [AppComponent,@@ -56,11 +64,15 @@ import {WeightService} from './weight/weight.service';NgbPaginationModule,NgxChartsModule,ReactiveFormsModule,+ RouterModule.forRoot(appRoutes),],providers: [ExerciseService,WeightService,+ {provide: APP_BASE_HREF, useValue: '/'}+ ],+ bootstrap: [+ AppComponent,],- bootstrap: [AppComponent]})export class AppModule { }diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.html b/angular/src/app/weight/weight-chart/weight-chart.component.htmlindex 6a5b10ea2..d3095441a 100644--- a/angular/src/app/weight/weight-chart/weight-chart.component.html+++ b/angular/src/app/weight/weight-chart/weight-chart.component.html@@ -1,20 +1,23 @@-<ngx-charts-line-chart- *ngIf="data !== null"+<!--[view]="view"-->+<div #containerRef>+ <ngx-charts-line-chart+ *ngIf="data !== null"- [view]="view"- [scheme]="colorScheme"- [legend]="legend"- [showXAxisLabel]="showXAxisLabel"- [showYAxisLabel]="showYAxisLabel"- [xAxis]="xAxis"- [yAxis]="yAxis"+ [view]="[containerRef.offsetWidth, 250]"+ [scheme]="colorScheme"+ [legend]="legend"+ [showXAxisLabel]="showXAxisLabel"+ [showYAxisLabel]="showYAxisLabel"+ [xAxis]="xAxis"+ [yAxis]="yAxis"- [timeline]="timeline"- [results]="data"- [autoScale]="autoScale"- (select)="onSelect($event)"- (activate)="onActivate($event)"- (deactivate)="onDeactivate($event)"->-</ngx-charts-line-chart>+ [timeline]="timeline"+ [results]="data"+ [autoScale]="autoScale"+ (select)="onSelect($event)"+ (activate)="onActivate($event)"+ (deactivate)="onDeactivate($event)"+ >+ </ngx-charts-line-chart>+</div>diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.ts b/angular/src/app/weight/weight-chart/weight-chart.component.tsindex 81259bc35..9815d35f7 100644--- a/angular/src/app/weight/weight-chart/weight-chart.component.ts+++ b/angular/src/app/weight/weight-chart/weight-chart.component.ts@@ -40,6 +40,8 @@ export class WeightChartComponent implements OnInit, OnDestroy {) { }ngOnInit(): void {+ // TODO: only load weight entries once+ this.service.loadWeightEntries();this.subscription = this.service.weightChanged.subscribe((newEntries: WeightEntry[]) => {this.weightEntries = newEntries;diff --git a/angular/src/index.html b/angular/src/index.htmlindex aa0630613..43f269798 100644--- a/angular/src/index.html+++ b/angular/src/index.html@@ -8,6 +8,13 @@<link rel="icon" type="image/x-icon" href="favicon.ico"></head><body>- <app-root></app-root>+ <div class="container">+ <div class="row">+ <div class="col-12">++ <app-root></app-root>+ </div>+ </div>+ </div></body></html>diff --git a/wger/core/templates/index.html b/wger/core/templates/index.htmlindex da01b2e73..8abf1f2bf 100644--- a/wger/core/templates/index.html+++ b/wger/core/templates/index.html@@ -7,14 +7,17 @@{# Header #}{# #}{% block header %}--{% if plan %}-<script>-$(document).ready(function () {- wgerDrawNutritionDiaryChart({{ plan.pk }});-});-</script>-{% endif %}+ <script src="{% static 'angular/en/runtime.js' %}" defer></script>+ <script src="{% static 'angular/en/polyfills.js' %}" defer></script>++ {# Manually load the appropriate language if it's available #}+ {% if language.short_name in languages_angular %}+ {% with 'angular/'|add:language.short_name|add:"/main.js" as test %}+ <script src="{% static test %}" defer></script>+ {% endwith %}+ {% else %}+ <script src="{% static 'angular/en/main.js' %}" defer></script>+ {% endif %}{% endblock %}@@ -237,9 +240,7 @@ day in your current workout:{% endblocktranslate %} <strong>{{current_workout}}<{% endfor %}</table>{% endif %}-- <div id="current-username" data-current-username="{{ owner_user.username }}"></div>- <div id="weight_diagram"></div>+ <app-root></app-root></div></div><div class="card-footer">diff --git a/wger/core/views/misc.py b/wger/core/views/misc.pyindex e7c89d3c0..95ce13ed9 100644--- a/wger/core/views/misc.py+++ b/wger/core/views/misc.py@@ -113,28 +113,28 @@ def dashboard(request):and the current weight"""- template_data = {}+ context = {}# Load the last workout, either from a schedule or a 'regular' one(current_workout, schedule) = Schedule.objects.get_current_workout(request.user)- template_data['current_workout'] = current_workout- template_data['schedule'] = schedule+ context['current_workout'] = current_workout+ context['schedule'] = schedule# Load the last nutritional plan, if one existstry:plan = NutritionPlan.objects.filter(user=request.user).latest('creation_date')except ObjectDoesNotExist:plan = False- template_data['plan'] = plan+ context['plan'] = plan# Load the last logged weight entry, if one existstry:weight = WeightEntry.objects.filter(user=request.user).latest('date')except ObjectDoesNotExist:weight = False- template_data['weight'] = weight- template_data['last_weight_entries'] = get_last_entries(request.user)+ context['weight'] = weight+ context['last_weight_entries'] = get_last_entries(request.user)# Format a bit the days so it doesn't have to be done in the templateused_days = {}@@ -154,14 +154,14 @@ def dashboard(request):if not day_has_workout:week_day_result.append((_(week.day_of_week), _('Rest day'), False))- template_data['weekdays'] = week_day_result+ context['weekdays'] = week_day_resultif plan:# Load the nutritional info- template_data['nutritional_info'] = plan.get_nutritional_values()+ context['nutritional_info'] = plan.get_nutritional_values()- return render(request, 'index.html', template_data)+ return render(request, 'index.html', context)class ContactClassView(TemplateView):