Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Hide form when the user cancels it

Roland Geider82d86fee1b7a
diff --git a/angular/src/app/weight/weight-detail/weight-detail.component.html b/angular/src/app/weight/weight-detail/weight-detail.component.html
index 9e008c416..5e91f1d05 100644
--- a/angular/src/app/weight/weight-detail/weight-detail.component.html
+++ b/angular/src/app/weight/weight-detail/weight-detail.component.html
@@ -32,7 +32,7 @@
</div>
</div>
- <app-weight-edit *ngIf="showForm" [weight]="entry"></app-weight-edit>
+ <app-weight-edit *ngIf="showForm" [weight]="entry" (closeEdit)="onFormCancelled()"></app-weight-edit>
</li>
diff --git a/angular/src/app/weight/weight-detail/weight-detail.component.ts b/angular/src/app/weight/weight-detail/weight-detail.component.ts
index 12516ac10..74b222dc8 100644
--- a/angular/src/app/weight/weight-detail/weight-detail.component.ts
+++ b/angular/src/app/weight/weight-detail/weight-detail.component.ts
@@ -24,6 +24,15 @@ export class WeightDetailComponent implements OnInit {
this.showForm = !this.showForm;
}
+ /**
+ * The form should be closed
+ */
+ onFormCancelled() {
+ this.showForm = false;
+ }
+
+
+
/**
* Deletes this weight entry
*/
diff --git a/angular/src/app/weight/weight-edit/weight-edit.component.html b/angular/src/app/weight/weight-edit/weight-edit.component.html
index 2e323416c..c3fde284a 100644
--- a/angular/src/app/weight/weight-edit/weight-edit.component.html
+++ b/angular/src/app/weight/weight-edit/weight-edit.component.html
@@ -24,4 +24,9 @@
type="submit"
class="btn btn-success mt-2"
[disabled]="group.invalid" i18n>Save</button>
+ <button
+ type="submit"
+ class="btn btn-secondary mt-2 ml-2"
+ i18n
+ (click)="closeEdit.emit()">Cancel</button>
</form>
diff --git a/angular/src/app/weight/weight-edit/weight-edit.component.ts b/angular/src/app/weight/weight-edit/weight-edit.component.ts
index 5a12a280c..9e97d46d1 100644
--- a/angular/src/app/weight/weight-edit/weight-edit.component.ts
+++ b/angular/src/app/weight/weight-edit/weight-edit.component.ts
@@ -1,4 +1,4 @@
-import {Component, Input, OnInit} from '@angular/core';
+import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {WeightEntry} from '../models/weight.model';
import {WeightService} from '../weight.service';
@@ -10,6 +10,7 @@ import {WeightService} from '../weight.service';
})
export class WeightEditComponent implements OnInit {
+ @Output() closeEdit = new EventEmitter<void>();
@Input() weight?: WeightEntry;
group!: FormGroup;
@@ -57,6 +58,7 @@ export class WeightEditComponent implements OnInit {
this.service.addWeightEntry(this.group.value);
}
+ this.closeEdit.emit();
this.group.reset();
}
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 93d0b7ad6..d3361840e 100644
--- a/angular/src/app/weight/weight-list/weight-list.component.html
+++ b/angular/src/app/weight/weight-list/weight-list.component.html
@@ -57,11 +57,11 @@
</button>
</div>
<div class="modal-body">
- <app-weight-edit></app-weight-edit>
+ <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')">Close</button>
</div>
</ng-template>
-<button class="btn btn-primary" (click)="open(content)" i18n>Add entry</button>
+<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 0cd878ec6..f4d337f6c 100644
--- a/angular/src/app/weight/weight-list/weight-list.component.ts
+++ b/angular/src/app/weight/weight-list/weight-list.component.ts
@@ -55,11 +55,18 @@ export class WeightListComponent implements OnInit {
}
- open(content: any) {
+ 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();
+ }
}