1
|
import { Injectable } from '@angular/core';
|
2
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
3
|
import { catchError } from 'rxjs/operators';
|
4
|
|
5
|
import { BasicService } from './basic.service';
|
6
|
import { Settings } from '../../models/settings.model';
|
7
|
import {Languages} from '../../enums/common.enum';
|
8
|
import {MatSnackBar} from '@angular/material';
|
9
|
import {TranslateService} from '@ngx-translate/core';
|
10
|
import { Config } from '../util/config.service';
|
11
|
|
12
|
@Injectable({
|
13
|
providedIn: 'root'
|
14
|
})
|
15
|
export class SettingsService extends BasicService {
|
16
|
defaultSettingsUrl = this.baseUrl + '/api/settings';
|
17
|
|
18
|
constructor(protected config: Config, protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
|
19
|
super(config, http, snackBar, translateService);
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* Returns default application settings
|
24
|
* with sickday count and notification
|
25
|
*/
|
26
|
getDefaultSettings() {
|
27
|
return this.makeGetSettingsApiCall(null);
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* Returns default application settings
|
32
|
* with sickday count and notification
|
33
|
* @param language filter by language
|
34
|
*/
|
35
|
getDefaultSettingsWithLanguage(language: Languages) {
|
36
|
return this.makeGetSettingsApiCall(language);
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* Získání aktuálně použitého výchozího nastavení v aplikaci
|
41
|
* GET /setttings?[lang=<CZ,EN>]
|
42
|
* @param language filter with language
|
43
|
*/
|
44
|
private makeGetSettingsApiCall(language: string) {
|
45
|
const httpParams: HttpParams = this.createParams({lang: language});
|
46
|
const options = {params: httpParams};
|
47
|
|
48
|
return this.http.get<Settings>(this.defaultSettingsUrl, options)
|
49
|
.pipe(
|
50
|
catchError(err => this.handleError(err))
|
51
|
);
|
52
|
}
|
53
|
|
54
|
postDefaultSettings(settings: Settings) {
|
55
|
return this.postDefaultSettingsWithOptions(settings, null);
|
56
|
}
|
57
|
|
58
|
postDefaultSettingsWithLanguage(settings: Settings, language: Languages) {
|
59
|
return this.postDefaultSettingsWithOptions(settings, language);
|
60
|
}
|
61
|
|
62
|
private postDefaultSettingsWithOptions(settings: Settings, language: Languages) {
|
63
|
const httpParams: HttpParams = this.createParams({lang: language});
|
64
|
const options = {params: httpParams};
|
65
|
|
66
|
return this.http.post<Settings>(this.defaultSettingsUrl, settings, options)
|
67
|
.pipe(
|
68
|
catchError(err => this.handleError(err))
|
69
|
);
|
70
|
}
|
71
|
}
|