fixed some issues with preferences editing

pull/3/head
Chris Veilleux 2019-03-21 15:14:37 -05:00
parent a68fda4735
commit a10a2efa90
4 changed files with 24 additions and 7 deletions

View File

@ -108,7 +108,7 @@ export class DeviceAddComponent implements OnInit {
}
onPreferencesSubmit() {
this.deviceService.addAccountPreferences(this.preferencesForm);
this.deviceService.addAccountPreferences(this.preferencesForm).subscribe();
}
onDefaultsSubmit() {

View File

@ -41,9 +41,18 @@ export class DeviceComponent implements OnInit {
);
this.preferencesForm = this.formBuilder.group(
{
dateFormat: [null, Validators.required],
measurementSystem: [null, Validators.required],
timeFormat: [null, Validators.required],
dateFormat: [
this.preferences ? this.preferences.dateFormat : null,
Validators.required
],
measurementSystem: [
this.preferences ? this.preferences.measurementSystem : null,
Validators.required
],
timeFormat: [
this.preferences ? this.preferences.timeFormat : null,
Validators.required
],
}
);

View File

@ -1,4 +1,4 @@
<mat-card class="mat-elevation-z0" id="required-settings-card">
<mat-card class="mat-elevation-z0" id="required-settings-card" [formGroup]="preferencesForm">
<mat-card-title *ngIf="deviceSetup">Setup your device preferences</mat-card-title>
<mat-card-title *ngIf="!deviceSetup">Manage your device preferences</mat-card-title>
<mat-card-content fxLayout="column">
@ -26,7 +26,7 @@
</account-option-buttons>
</mat-card-content>
<mat-card-actions align="right" *ngIf="!deviceSetup">
<button mat-button type="submit">SAVE</button>
<button mat-button (click)="onSave()" [disabled]="!preferencesForm.valid">SAVE</button>
</mat-card-actions>
</mat-card>

View File

@ -71,6 +71,14 @@ export class PreferencesComponent implements OnInit {
}
onSave() {
this.deviceService.updateAccountPreferences(this.preferencesForm);
if (this.preferences) {
this.deviceService.updateAccountPreferences(this.preferencesForm).subscribe(
() => { this.preferences = this.preferencesForm.value; }
);
} else {
this.deviceService.addAccountPreferences(this.preferencesForm).subscribe(
() => { this.preferences = this.preferencesForm.value; }
);
}
}
}