Self hosted FLOSS fitness/workout, nutrition and weight tracker
Show difference in weight and days
Roland Geider62eb2f742d92
diff --git a/angular/src/app/weight/weight-detail/weight-detail.component.html b/angular/src/app/weight/weight-detail/weight-detail.component.htmlindex f0327442e..cd44605df 100644--- a/angular/src/app/weight/weight-detail/weight-detail.component.html+++ b/angular/src/app/weight/weight-detail/weight-detail.component.html@@ -13,10 +13,18 @@</div><div class="col-3">- +/-+ <div *ngIf="weightDiff !== null">+ {{weightDiff}}+ </div></div>- <div class="col-3">+ <div class="col-2">+ <div *ngIf="dayDiff !== null">+ {{dayDiff}}+ </div>+ </div>++ <div class="col-1"><div ngbDropdown class="text-right"><button class="btn btn-link" id="dropdownBasic1" ngbDropdownToggle></button><div ngbDropdownMenu aria-labelledby="dropdownBasic1">diff --git a/angular/src/app/weight/weight-detail/weight-detail.component.ts b/angular/src/app/weight/weight-detail/weight-detail.component.tsindex bdb7a277f..12516ac10 100644--- a/angular/src/app/weight/weight-detail/weight-detail.component.ts+++ b/angular/src/app/weight/weight-detail/weight-detail.component.ts@@ -10,6 +10,8 @@ import {WeightService} from '../weight.service';export class WeightDetailComponent implements OnInit {@Input() entry!: WeightEntry;+ @Input() weightDiff?: number;+ @Input() dayDiff?: number;showForm = false;constructor(private weightService: WeightService) {diff --git a/angular/src/app/weight/weight-list/weight-list.component.html b/angular/src/app/weight/weight-list/weight-list.component.htmlindex 7eadf7aaa..93d0b7ad6 100644--- a/angular/src/app/weight/weight-list/weight-list.component.html+++ b/angular/src/app/weight/weight-list/weight-list.component.html@@ -6,9 +6,36 @@<div class="row"><div class="col-12">- <ul *ngFor="let entry of weightEntries | slice: (page-1) * pageSize : page * pageSize"- class="list-group">- <app-weight-detail [entry]="entry"></app-weight-detail>+ <ul class="list-group">+ <li class="list-group-item">+ <div class="row">+ <div class="col-3">+ <div i18n>+ Date+ </div>+ </div>++ <div class="col-3" i18n>+ Gewicht+ </div>++ <div class="col-3" i18n>+ Change+ </div>++ <div class="col-2" i18n>+ Days+ </div>++ <div class="col-1">+ </div>+ </div>+ </li>+ <app-weight-detail+ [entry]="entry.entry"+ [dayDiff]="entry.dayDiff"+ [weightDiff]="entry.weightDiff"+ *ngFor="let entry of weightEntries | slice: (page-1) * pageSize : page * pageSize" ></app-weight-detail></ul><ngb-paginationdiff --git a/angular/src/app/weight/weight-list/weight-list.component.ts b/angular/src/app/weight/weight-list/weight-list.component.tsindex 993645dcd..0cd878ec6 100644--- a/angular/src/app/weight/weight-list/weight-list.component.ts+++ b/angular/src/app/weight/weight-list/weight-list.component.ts@@ -9,7 +9,7 @@ import {WeightService} from '../weight.service';styleUrls: ['./weight-list.component.css']})export class WeightListComponent implements OnInit {- weightEntries: WeightEntry[] = [];+ weightEntries: { entry: WeightEntry, weightDiff: number, dayDiff: number }[] = [];/**Starting page for the pagination@@ -32,11 +32,27 @@ export class WeightListComponent implements OnInit {) { }ngOnInit(): void {- this.getWeightEntries();+ this.processWeightEntries();}- async getWeightEntries(): Promise<void> {- this.weightEntries = await this.service.loadWeightEntries();+ /**+ * Processes the+ */+ async processWeightEntries(): Promise<void> {+ const entries = await this.service.loadWeightEntries();+ const nrOfEntries = entries.length;++ entries.forEach((currentEntry, index) => {++ // Newest entries are the first+ const prevIndex = index + 1;++ const weightDiff = prevIndex < nrOfEntries ? currentEntry.weight - entries[prevIndex].weight : 0;+ const dayDiff = prevIndex < nrOfEntries ? (currentEntry.date.getTime() - entries[prevIndex].date.getTime()) / (1000 * 3600 * 24) : 0;++ this.weightEntries.push({entry: currentEntry, weightDiff: weightDiff, dayDiff: dayDiff});+ });+}open(content: any) {