Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {Component, OnDestroy, OnInit} from '@angular/core';
import {SettingsService} from "../services/settings.service";
import {Observable, Subscription} from "rxjs";
import {QueueSetting, Setting} from "../model/setting";
import {AlertService} from "../services/alert.service";
@Component({
selector: 'app-settings',
templateUrl: './settings.component.html',
styleUrls: ['./settings.component.scss']
})
export class SettingsComponent implements OnInit, OnDestroy {
settings$: Subscription;
settings: Setting;
queueSettings: Observable<Array<QueueSetting>>;
constructor(
private settingService: SettingsService,
private alertService: AlertService
) {
}
ngOnInit() {
this.queueSettings = this.settingService.getQueueSettings();
this.getSettings();
}
getSettings(): void {
this.alertService.info("Retrieving Settings");
this.settings$ = this.settingService.getSettings().subscribe((s: Setting) => {
if (s) {
this.settings = s;
this.alertService.success('Settings Retrieved');
} else {
this.alertService.error('Setting could not be retrieved');
}
}, error => {
this.alertService.error('Settings could not be retrieved. ' + error);
});
}
updateSettings(key: string, value: boolean): void {
if (this.settings.hasOwnProperty(key) && this.settings[key] !== value) {
this.alertService.info('Updating settings');
this.settings[key] = value;
this.settingService.setSettings(this.settings).subscribe((s: Setting) => {
if (s) {
this.settings = s;
this.alertService.success('Settings Updated');
} else {
this.alertService.error('Setting could not be updated');
}
},
error => {
this.alertService.error('Settings could not be updated');
})
}
}
ngOnDestroy(): void {
if (this.settings$) {
this.settings$.unsubscribe();
}
}
}