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