Self hosted FLOSS fitness/workout, nutrition and weight tracker
Improve form UI
Roland Geider5f02533f60a9
diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.tsindex 8f2959267..1c6a9b196 100644--- a/angular/src/app/app.module.ts+++ b/angular/src/app/app.module.ts@@ -32,6 +32,7 @@ import {WeightListComponent} from './weight/weight-list/weight-list.component';import { WeightDetailComponent } from './weight/weight-detail/weight-detail.component';import { WeightEditComponent } from './weight/weight-edit/weight-edit.component';import { WeightChartComponent } from './weight/weight-chart/weight-chart.component';+import {WeightService} from './weight/weight.service';@NgModule({declarations: [@@ -52,7 +53,10 @@ import { WeightChartComponent } from './weight/weight-chart/weight-chart.componeNgxChartsModule,BrowserAnimationsModule],- providers: [ExerciseService],+ providers: [+ ExerciseService,+ WeightService,+ ],bootstrap: [AppComponent]})export class AppModule { }diff --git a/angular/src/app/weight/weight-chart/weight-chart.component.ts b/angular/src/app/weight/weight-chart/weight-chart.component.tsindex 84da3b42d..b97464dd6 100644--- a/angular/src/app/weight/weight-chart/weight-chart.component.ts+++ b/angular/src/app/weight/weight-chart/weight-chart.component.ts@@ -34,7 +34,10 @@ export class WeightChartComponent implements OnInit {}async ngOnInit(): Promise<void> {++ // TODO: only load service data onceawait this.service.loadWeightEntries();+const out: {name: Date, value: number}[] = this.service.entries.map(entry => {return {name: entry.date, value: entry.weight};});diff --git a/angular/src/app/weight/weight-edit/weight-edit.component.html b/angular/src/app/weight/weight-edit/weight-edit.component.htmlindex 43557cf93..1f7519880 100644--- a/angular/src/app/weight/weight-edit/weight-edit.component.html+++ b/angular/src/app/weight/weight-edit/weight-edit.component.html@@ -1,28 +1,32 @@<form [formGroup]="group" (ngSubmit)="onSubmit()">- <div class="form-group">- <div class="form-group">- <label for="date">Date</label>- <input- type="date"- id="date"- formControlName="date"- class="form-control">- </div>+ <div class="form-row">+ <div class="col">+ <label for="date">Date</label>+ <input+ type="date"+ id="date"+ formControlName="date"+ class="form-control">+ </div>- <div class="form-group">- <label for="weight">Weight</label>- <input- type="text"- id="weight"- formControlName="weight"- class="form-control">+ <div class="col">+ <label for="weight">Weight</label>+ <input+ type="text"+ id="weight"+ formControlName="weight"+ class="form-control">+ </div>+ </div>+ <div class="form-row">+ <div class="col">+ <button+ type="submit"+ class="btn btn-success"+ [disabled]="group.invalid">Save+ </button></div>-- <button- type="submit"- class="btn btn-success"- [disabled]="group.invalid">Save- </button></div>+</form>diff --git a/angular/src/app/weight/weight-edit/weight-edit.component.ts b/angular/src/app/weight/weight-edit/weight-edit.component.tsindex 31da2da97..5a12a280c 100644--- a/angular/src/app/weight/weight-edit/weight-edit.component.ts+++ b/angular/src/app/weight/weight-edit/weight-edit.component.ts@@ -21,7 +21,7 @@ export class WeightEditComponent implements OnInit {ngOnInit(): void {if(!this.weight) {- console.log("thi weight is not defined");+ console.log("this weight is not defined");this.weight = new WeightEntry(new Date(), 0);}diff --git a/angular/src/app/weight/weight.service.ts b/angular/src/app/weight/weight.service.tsindex 5d8ff4b8f..e62720efe 100644--- a/angular/src/app/weight/weight.service.ts+++ b/angular/src/app/weight/weight.service.ts@@ -17,6 +17,12 @@ export class WeightService {) {}+ /**+ * Sorts weight entries by date.+ *+ * While they are already sorted server side, this is necessary, e.g. when+ * adding or deleting+ */sortEntries() {this.entries.sort((a, b) => (a.date > b.date ? -1 : 1));}@@ -41,7 +47,8 @@ export class WeightService {updateWeightEntry(weight: WeightEntry) {this.http.patch<any>(this.weightEntryUrl + weight.id + '/', this.weightAdapter.toJson(weight), {headers: environment.headers- }).subscribe(value => { });+ }).subscribe(value => {+ });}/**@@ -49,7 +56,7 @@ export class WeightService {** @param data: the weight entry data*/- addWeightEntry(data: {weight: number, date: Date}) {+ addWeightEntry(data: { weight: number, date: Date }) {this.http.post<any>(this.weightEntryUrl, data, {headers: environment.headers}).subscribe(value => {@@ -69,7 +76,6 @@ export class WeightService {headers: environment.headers}).subscribe();-this.entries.forEach((value: WeightEntry, index: number) => {if (value.id == id) {this.entries.splice(index, 1);