forked from nartc/ng-auth-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.component.ts
executable file
·70 lines (63 loc) · 2.2 KB
/
app.component.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
61
62
63
64
65
66
67
68
69
70
import { Component, OnInit } from '@angular/core';
import { ResolveEnd, Router } from '@angular/router';
import { AuthService, AuthStateService } from '@volt/common/auth';
import { defaultPieChartColors } from '@volt/common/constants';
import { FeatureFlagService } from '@volt/common/feature-flags';
import { PermissionService } from '@volt/common/permissions';
import { PageTitleService } from '@volt/common/services';
import { TranslationService } from '@volt/common/translations';
import * as Highcharts from 'highcharts';
import { filter } from 'rxjs/operators';
@Component({
selector: 'volt-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
constructor(
private readonly router: Router,
private readonly authStateService: AuthStateService,
private readonly authService: AuthService,
private readonly translationService: TranslationService,
private readonly permissionService: PermissionService,
private readonly featureFlagService: FeatureFlagService,
private readonly pageTitleService: PageTitleService,
) {}
ngOnInit() {
this.translationService.setupTranslation();
this.setupRouteTitleListener();
this.authService.retrieveTokenOnPageLoad(); // setup authState
this.authStateService.isAuthorized$.subscribe(() => {
this.permissionService.loadPermissions();// setup permissionState
this.featureFlagService.loadFeatures();
});
this.setupHighchartsGlobalOptions();
}
private setupRouteTitleListener() {
this.router.events
.pipe(filter((ev) => ev instanceof ResolveEnd))
.subscribe((ev: ResolveEnd) => {
this.pageTitleService.setPageTitleByRouteSnapshot(ev.state.root);
});
}
private setupHighchartsGlobalOptions() {
Highcharts.setOptions({
colors: defaultPieChartColors,
credits: {
enabled: false,
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: true,
distance: -50,
format: '{point.percentage:.0f}% ({point.y})',
},
},
},
});
}
}