Projekt

Obecné

Profil

Stáhnout (2.2 KB) Statistiky
| Větev: | Tag: | Revize:
1 41741550 Hung Hoang
import { Injectable } from '@angular/core';
2 4bcef705 Hung Hoang
import {HttpClient, HttpParams} from '@angular/common/http';
3 41741550 Hung Hoang
import { catchError } from 'rxjs/operators';
4
5
import { BasicService } from './basic.service';
6 fd5ab42e Hung Hoang
import { Settings } from '../../models/settings.model';
7
import {Languages} from '../../enums/common.enum';
8 1d169f6d Hung Hoang
import {MatSnackBar} from '@angular/material';
9 5d32cbea Václav Jirák
import {TranslateService} from '@ngx-translate/core';
10 41741550 Hung Hoang
11
@Injectable({
12
  providedIn: 'root'
13
})
14
export class SettingsService extends BasicService {
15 4bcef705 Hung Hoang
  defaultSettingsUrl = this.baseUrl + '/api/settings';
16 41741550 Hung Hoang
17 5d32cbea Václav Jirák
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
18
    super(http, snackBar, translateService);
19 4bcef705 Hung Hoang
  }
20
21
  /**
22
   * Returns default application settings
23
   * with sickday count and notification
24
   */
25 41741550 Hung Hoang
  getDefaultSettings() {
26 4bcef705 Hung Hoang
    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 41741550 Hung Hoang
      .pipe(
49
        catchError(err => this.handleError(err))
50
      );
51
  }
52
53 4bcef705 Hung Hoang
  postDefaultSettings(settings: Settings) {
54
    return this.postDefaultSettingsWithOptions(settings, null);
55 41741550 Hung Hoang
  }
56
57 4bcef705 Hung Hoang
  postDefaultSettingsWithLanguage(settings: Settings, language: Languages) {
58
    return this.postDefaultSettingsWithOptions(settings, language);
59 41741550 Hung Hoang
  }
60
61 4bcef705 Hung Hoang
  private postDefaultSettingsWithOptions(settings: Settings, language: Languages) {
62
    const httpParams: HttpParams = this.createParams({lang: language});
63
    const options = {params: httpParams};
64
65 41741550 Hung Hoang
    return this.http.post<Settings>(this.defaultSettingsUrl, settings, options)
66
      .pipe(
67
        catchError(err => this.handleError(err))
68
      );
69
  }
70
}