Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Allow editing weight entries by clicking on the chart

Roland Geidere3d32ead94b2
diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.html b/angular/src/app/weight/weight-chart/weight-chart.component.html
index d3095441a..5a517eb8d 100644
--- a/angular/src/app/weight/weight-chart/weight-chart.component.html
+++ b/angular/src/app/weight/weight-chart/weight-chart.component.html
@@ -1,4 +1,3 @@
-
<!--[view]="view"-->
<div #containerRef>
<ngx-charts-line-chart
@@ -11,13 +10,29 @@
[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>
+
+ <ng-template #content let-modal>
+ <div class="modal-header">
+ <h4 class="modal-title" id="modal-basic-title" i18n>Add entry</h4>
+ <button type="button" class="close" (click)="modal.dismiss()">
+ <span aria-hidden="true">&times;</span>
+ </button>
+ </div>
+ <div class="modal-body">
+ <app-weight-edit (closeEdit)="onFormCancelled()" [weight]="selectedEntry"></app-weight-edit>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')" i18n>Close</button>
+ </div>
+ </ng-template>
+
</div>
diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.ts b/angular/src/app/weight/weight-chart/weight-chart.component.ts
index 81259bc35..0655867c5 100644
--- a/angular/src/app/weight/weight-chart/weight-chart.component.ts
+++ b/angular/src/app/weight/weight-chart/weight-chart.component.ts
@@ -1,7 +1,7 @@
-import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
+import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
+import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {Subscription} from 'rxjs';
import {WeightEntry} from '../models/weight.model';
-import {WeightEditComponent} from '../weight-edit/weight-edit.component';
import {WeightService} from '../weight.service';
@Component({
@@ -27,17 +27,20 @@ export class WeightChartComponent implements OnInit, OnDestroy {
};
data: any;
+
private weightEntries: WeightEntry[] = [];
- selectedEntry?: WeightEntry;
+ selectedEntry!: WeightEntry;
+
private subscription!: Subscription;
- @ViewChild(WeightEditComponent)
- edit!: WeightEditComponent;
+ @ViewChild('content') input!: ElementRef;
constructor(
private service: WeightService,
- ) { }
+ private modalService: NgbModal,
+ ) {
+ }
ngOnInit(): void {
this.subscription = this.service.weightChanged.subscribe(
@@ -46,8 +49,6 @@ export class WeightChartComponent implements OnInit, OnDestroy {
this.processData();
}
);
-
-
}
@@ -74,6 +75,7 @@ export class WeightChartComponent implements OnInit, OnDestroy {
}
this.selectedEntry = entry;
console.log(`Loaded entry ${entry.id}`);
+ this.openModal(this.input);
}
onActivate(data: any): void {
@@ -84,5 +86,22 @@ export class WeightChartComponent implements OnInit, OnDestroy {
console.log('Deactivate', JSON.parse(JSON.stringify(data)));
}
+ /*
+ * Open the modal allowing editing the entry
+ */
+ openModal(content: any) {
+ this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
+ console.log(`Closed with: ${result}`);
+ }, (reason) => {
+ console.log(`Dismissed`);
+ });
+ }
+
+ /**
+ * The form should be closed
+ */
+ onFormCancelled() {
+ this.modalService.dismissAll();
+ }
}
diff --git a/angular/src/app/weight/weight-list/weight-list.component.html b/angular/src/app/weight/weight-list/weight-list.component.html
index 7a5110914..8cda89b70 100644
--- a/angular/src/app/weight/weight-list/weight-list.component.html
+++ b/angular/src/app/weight/weight-list/weight-list.component.html
@@ -33,20 +33,3 @@
class="d-flex justify-content-center mt-2"></ngb-pagination>
</div>
</div>
-
-<ng-template #content let-modal>
- <div class="modal-header">
- <h4 class="modal-title" id="modal-basic-title" i18n>Add entry</h4>
- <button type="button" class="close" (click)="modal.dismiss('Cross click')">
- <span aria-hidden="true">&times;</span>
- </button>
- </div>
- <div class="modal-body">
- <app-weight-edit (closeEdit)="onFormCancelled()"></app-weight-edit>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')" i18n>Close</button>
- </div>
-</ng-template>
-
-<button class="btn btn-primary" (click)="openModal(content)" i18n>Add entry</button>
diff --git a/angular/src/app/weight/weight-list/weight-list.component.ts b/angular/src/app/weight/weight-list/weight-list.component.ts
index 1b24e12b6..38833fb6f 100644
--- a/angular/src/app/weight/weight-list/weight-list.component.ts
+++ b/angular/src/app/weight/weight-list/weight-list.component.ts
@@ -1,5 +1,4 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
-import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {Subscription} from 'rxjs';
import {WeightEntry} from '../models/weight.model';
import {WeightService} from '../weight.service';
@@ -30,7 +29,6 @@ export class WeightListComponent implements OnInit, OnDestroy {
constructor(
private service: WeightService,
- private modalService: NgbModal
) {
}
@@ -47,8 +45,8 @@ export class WeightListComponent implements OnInit, OnDestroy {
}
/**
- * Processes the weight entries and calculates the difference in days between
- * entries.
+ * Processes the weight entries and calculates the difference in weight and
+ * days between entries.
*
* This could potentially be moved to the model
*/
@@ -67,19 +65,4 @@ export class WeightListComponent implements OnInit, OnDestroy {
this.weightEntriesProcessed.push({entry: currentEntry, weightDiff: weightDiff, dayDiff: dayDiff});
});
}
-
- openModal(content: any) {
- this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
- console.log(`Closed with: ${result}`);
- }, (reason) => {
- console.log(`Dismissed`);
- });
- }
-
- /**
- * The form should be closed
- */
- onFormCancelled() {
- this.modalService.dismissAll();
- }
}