This repository was archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathoperators.service.ts
60 lines (49 loc) · 1.67 KB
/
operators.service.ts
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
import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { OperatorDoc } from '../../../operator-docs';
import { LanguageService } from './language.service';
import { Lang } from '../models/language.model';
import { MenuOperator } from '../../../operator-docs/operator.model';
@Injectable()
export class OperatorsService {
readonly currentLang: Lang;
private _operators = new BehaviorSubject([]);
operators = this._operators.asObservable();
constructor(private languageService: LanguageService) {
this.currentLang = this.languageService.getCurrentLang();
this.initOperators(this.currentLang.code);
}
initOperators(code: string): void {
switch (code) {
case 'ru':
import('../../../i18n/ru').then(module => {
this._operators.next(module.ALL_OPERATORS_RU);
});
break;
default:
import('../../../operator-docs').then(module => {
this._operators.next(module.ALL_OPERATORS_EN);
});
break;
}
}
changeOperatorsLang(lang: Lang): void {
this.initOperators(lang.code);
}
getOperators(): Observable<OperatorDoc[]> {
return this.operators;
}
getOperatorsForMenu(): Promise<MenuOperator[]> {
return import('../../../operator-docs').then(module => {
return module.ALL_OPERATORS_EN.map(operator => {
const { name, operatorType } = operator;
return { name, operatorType };
});
});
}
getDefaultOperator(name: string): Promise<OperatorDoc | undefined> {
return import('../../../operator-docs').then(module => {
return module.ALL_OPERATORS_EN.find(operator => operator.name === name);
});
}
}