|
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +import { AppService } from '../app.service'; |
| 3 | +import { FormBuilder, FormGroup } from '@angular/forms'; |
| 4 | +import { CloudAppSettingsService } from '@exlibris/exl-cloudapp-angular-lib'; |
| 5 | +import { ToastrService } from 'ngx-toastr'; |
| 6 | +import { Settings } from '../models/settings'; |
| 7 | + |
| 8 | +@Component({ |
| 9 | + selector: 'app-settings', |
| 10 | + templateUrl: './settings.component.html', |
| 11 | + styleUrls: ['./settings.component.scss'] |
| 12 | +}) |
| 13 | +export class SettingsComponent implements OnInit { |
| 14 | + form: FormGroup; |
| 15 | + saving = false; |
| 16 | + |
| 17 | + constructor( |
| 18 | + private appService: AppService, |
| 19 | + private fb: FormBuilder, |
| 20 | + private settingsService: CloudAppSettingsService, |
| 21 | + private toastr: ToastrService |
| 22 | + ) { } |
| 23 | + |
| 24 | + ngOnInit() { |
| 25 | + this.appService.setTitle('Settings'); |
| 26 | + this.form = this.fb.group({ |
| 27 | + showValue: this.fb.control(false), |
| 28 | + pageSize: this.fb.control(10) |
| 29 | + }); |
| 30 | + //this.settingsService.remove().subscribe(()=>this.load()); |
| 31 | + this.load(); |
| 32 | + } |
| 33 | + |
| 34 | + load() { |
| 35 | + this.settingsService.getAsFormGroup().subscribe( settings => { |
| 36 | + if (Object.keys(settings.value).length!=0) { |
| 37 | + this.form = settings; |
| 38 | + } |
| 39 | + }); |
| 40 | + } |
| 41 | + |
| 42 | + save() { |
| 43 | + this.saving = true; |
| 44 | + this.settingsService.set(this.form.value).subscribe( |
| 45 | + response => { |
| 46 | + this.toastr.success('Settings successfully saved.'); |
| 47 | + this.form.markAsPristine(); |
| 48 | + }, |
| 49 | + err => this.toastr.error(err.message), |
| 50 | + () => this.saving = false |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments