|
@@ -18,13 +18,14 @@ import { Injectable } from '@angular/core'; |
|
@@ -18,13 +18,14 @@ import { Injectable } from '@angular/core'; |
18
|
import { AuthService } from '../auth/auth.service';
|
18
|
import { AuthService } from '../auth/auth.service';
|
19
|
import { select, Store } from '@ngrx/store';
|
19
|
import { select, Store } from '@ngrx/store';
|
20
|
import { AppState } from '../core.state';
|
20
|
import { AppState } from '../core.state';
|
21
|
-import { selectAuthUser, selectIsAuthenticated } from '../auth/auth.selectors';
|
21
|
+import {selectAuth, selectAuthUser, selectIsAuthenticated} from '../auth/auth.selectors';
|
22
|
import { take } from 'rxjs/operators';
|
22
|
import { take } from 'rxjs/operators';
|
23
|
import { HomeSection, MenuSection } from '@core/services/menu.models';
|
23
|
import { HomeSection, MenuSection } from '@core/services/menu.models';
|
24
|
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
24
|
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
25
|
import { Authority } from '@shared/models/authority.enum';
|
25
|
import { Authority } from '@shared/models/authority.enum';
|
26
|
import { AuthUser } from '@shared/models/user.model';
|
26
|
import { AuthUser } from '@shared/models/user.model';
|
27
|
import { guid } from '@core/utils';
|
27
|
import { guid } from '@core/utils';
|
|
|
28
|
+import {AuthState} from "@core/auth/auth.models";
|
28
|
|
29
|
|
29
|
@Injectable({
|
30
|
@Injectable({
|
30
|
providedIn: 'root'
|
31
|
providedIn: 'root'
|
|
@@ -45,23 +46,23 @@ export class MenuService { |
|
@@ -45,23 +46,23 @@ export class MenuService { |
45
|
}
|
46
|
}
|
46
|
|
47
|
|
47
|
private buildMenu() {
|
48
|
private buildMenu() {
|
48
|
- this.store.pipe(select(selectAuthUser), take(1)).subscribe(
|
|
|
49
|
- (authUser: AuthUser) => {
|
|
|
50
|
- if (authUser) {
|
49
|
+ this.store.pipe(select(selectAuth), take(1)).subscribe(
|
|
|
50
|
+ (authState: AuthState) => {
|
|
|
51
|
+ if (authState.authUser) {
|
51
|
let menuSections: Array<MenuSection>;
|
52
|
let menuSections: Array<MenuSection>;
|
52
|
let homeSections: Array<HomeSection>;
|
53
|
let homeSections: Array<HomeSection>;
|
53
|
- switch (authUser.authority) {
|
54
|
+ switch (authState.authUser.authority) {
|
54
|
case Authority.SYS_ADMIN:
|
55
|
case Authority.SYS_ADMIN:
|
55
|
- menuSections = this.buildSysAdminMenu(authUser);
|
|
|
56
|
- homeSections = this.buildSysAdminHome(authUser);
|
56
|
+ menuSections = this.buildSysAdminMenu(authState);
|
|
|
57
|
+ homeSections = this.buildSysAdminHome(authState);
|
57
|
break;
|
58
|
break;
|
58
|
case Authority.TENANT_ADMIN:
|
59
|
case Authority.TENANT_ADMIN:
|
59
|
- menuSections = this.buildTenantAdminMenu(authUser);
|
|
|
60
|
- homeSections = this.buildTenantAdminHome(authUser);
|
60
|
+ menuSections = this.buildTenantAdminMenu(authState);
|
|
|
61
|
+ homeSections = this.buildTenantAdminHome(authState);
|
61
|
break;
|
62
|
break;
|
62
|
case Authority.CUSTOMER_USER:
|
63
|
case Authority.CUSTOMER_USER:
|
63
|
- menuSections = this.buildCustomerUserMenu(authUser);
|
|
|
64
|
- homeSections = this.buildCustomerUserHome(authUser);
|
64
|
+ menuSections = this.buildCustomerUserMenu(authState);
|
|
|
65
|
+ homeSections = this.buildCustomerUserHome(authState);
|
65
|
break;
|
66
|
break;
|
66
|
}
|
67
|
}
|
67
|
this.menuSections$.next(menuSections);
|
68
|
this.menuSections$.next(menuSections);
|
|
@@ -71,7 +72,7 @@ export class MenuService { |
|
@@ -71,7 +72,7 @@ export class MenuService { |
71
|
);
|
72
|
);
|
72
|
}
|
73
|
}
|
73
|
|
74
|
|
74
|
- private buildSysAdminMenu(authUser: any): Array<MenuSection> {
|
75
|
+ private buildSysAdminMenu(authState: AuthState): Array<MenuSection> {
|
75
|
const sections: Array<MenuSection> = [];
|
76
|
const sections: Array<MenuSection> = [];
|
76
|
sections.push(
|
77
|
sections.push(
|
77
|
{
|
78
|
{
|
|
@@ -152,7 +153,7 @@ export class MenuService { |
|
@@ -152,7 +153,7 @@ export class MenuService { |
152
|
return sections;
|
153
|
return sections;
|
153
|
}
|
154
|
}
|
154
|
|
155
|
|
155
|
- private buildSysAdminHome(authUser: any): Array<HomeSection> {
|
156
|
+ private buildSysAdminHome(authState: AuthState): Array<HomeSection> {
|
156
|
const homeSections: Array<HomeSection> = [];
|
157
|
const homeSections: Array<HomeSection> = [];
|
157
|
homeSections.push(
|
158
|
homeSections.push(
|
158
|
{
|
159
|
{
|
|
@@ -215,7 +216,7 @@ export class MenuService { |
|
@@ -215,7 +216,7 @@ export class MenuService { |
215
|
return homeSections;
|
216
|
return homeSections;
|
216
|
}
|
217
|
}
|
217
|
|
218
|
|
218
|
- private buildTenantAdminMenu(authUser: any): Array<MenuSection> {
|
219
|
+ private buildTenantAdminMenu(authState: AuthState): Array<MenuSection> {
|
219
|
const sections: Array<MenuSection> = [];
|
220
|
const sections: Array<MenuSection> = [];
|
220
|
sections.push(
|
221
|
sections.push(
|
221
|
{
|
222
|
{
|
|
@@ -267,31 +268,37 @@ export class MenuService { |
|
@@ -267,31 +268,37 @@ export class MenuService { |
267
|
type: 'link',
|
268
|
type: 'link',
|
268
|
path: '/entityViews',
|
269
|
path: '/entityViews',
|
269
|
icon: 'view_quilt'
|
270
|
icon: 'view_quilt'
|
270
|
- },
|
|
|
271
|
- {
|
|
|
272
|
- id: guid(),
|
|
|
273
|
- name: 'edge.management',
|
|
|
274
|
- type: 'toggle',
|
|
|
275
|
- path: '/edges',
|
|
|
276
|
- height: '80px',
|
|
|
277
|
- icon: 'router',
|
|
|
278
|
- pages: [
|
|
|
279
|
- {
|
|
|
280
|
- id: guid(),
|
|
|
281
|
- name: 'edge.edges',
|
|
|
282
|
- type: 'link',
|
|
|
283
|
- path: '/edges',
|
|
|
284
|
- icon: 'router'
|
|
|
285
|
- },
|
|
|
286
|
- {
|
|
|
287
|
- id: guid(),
|
|
|
288
|
- name: 'rulechain.edge-rulechains',
|
|
|
289
|
- type: 'link',
|
|
|
290
|
- path: '/edges/ruleChains',
|
|
|
291
|
- icon: 'settings_ethernet'
|
|
|
292
|
- }
|
|
|
293
|
- ]
|
|
|
294
|
- },
|
271
|
+ }
|
|
|
272
|
+ );
|
|
|
273
|
+ if (authState.edgesSupportEnabled) {
|
|
|
274
|
+ sections.push(
|
|
|
275
|
+ {
|
|
|
276
|
+ id: guid(),
|
|
|
277
|
+ name: 'edge.management',
|
|
|
278
|
+ type: 'toggle',
|
|
|
279
|
+ path: '/edges',
|
|
|
280
|
+ height: '80px',
|
|
|
281
|
+ icon: 'router',
|
|
|
282
|
+ pages: [
|
|
|
283
|
+ {
|
|
|
284
|
+ id: guid(),
|
|
|
285
|
+ name: 'edge.edges',
|
|
|
286
|
+ type: 'link',
|
|
|
287
|
+ path: '/edges',
|
|
|
288
|
+ icon: 'router'
|
|
|
289
|
+ },
|
|
|
290
|
+ {
|
|
|
291
|
+ id: guid(),
|
|
|
292
|
+ name: 'rulechain.edge-rulechains',
|
|
|
293
|
+ type: 'link',
|
|
|
294
|
+ path: '/edges/ruleChains',
|
|
|
295
|
+ icon: 'settings_ethernet'
|
|
|
296
|
+ }
|
|
|
297
|
+ ]
|
|
|
298
|
+ }
|
|
|
299
|
+ );
|
|
|
300
|
+ }
|
|
|
301
|
+ sections.push(
|
295
|
{
|
302
|
{
|
296
|
id: guid(),
|
303
|
id: guid(),
|
297
|
name: 'widget.widget-library',
|
304
|
name: 'widget.widget-library',
|
|
@@ -325,7 +332,7 @@ export class MenuService { |
|
@@ -325,7 +332,7 @@ export class MenuService { |
325
|
return sections;
|
332
|
return sections;
|
326
|
}
|
333
|
}
|
327
|
|
334
|
|
328
|
- private buildTenantAdminHome(authUser: any): Array<HomeSection> {
|
335
|
+ private buildTenantAdminHome(authState: AuthState): Array<HomeSection> {
|
329
|
const homeSections: Array<HomeSection> = [];
|
336
|
const homeSections: Array<HomeSection> = [];
|
330
|
homeSections.push(
|
337
|
homeSections.push(
|
331
|
{
|
338
|
{
|
|
@@ -383,22 +390,28 @@ export class MenuService { |
|
@@ -383,22 +390,28 @@ export class MenuService { |
383
|
path: '/entityViews'
|
390
|
path: '/entityViews'
|
384
|
}
|
391
|
}
|
385
|
]
|
392
|
]
|
386
|
- },
|
|
|
387
|
- {
|
|
|
388
|
- name: 'edge.management',
|
|
|
389
|
- places: [
|
|
|
390
|
- {
|
|
|
391
|
- name: 'edge.edges',
|
|
|
392
|
- icon: 'router',
|
|
|
393
|
- path: '/edges'
|
|
|
394
|
- },
|
|
|
395
|
- {
|
|
|
396
|
- name: 'rulechain.edge-rulechains',
|
|
|
397
|
- icon: 'settings_ethernet',
|
|
|
398
|
- path: '/edges/ruleChains'
|
|
|
399
|
- }
|
|
|
400
|
- ]
|
|
|
401
|
- },
|
393
|
+ }
|
|
|
394
|
+ );
|
|
|
395
|
+ if (authState.edgesSupportEnabled) {
|
|
|
396
|
+ homeSections.push(
|
|
|
397
|
+ {
|
|
|
398
|
+ name: 'edge.management',
|
|
|
399
|
+ places: [
|
|
|
400
|
+ {
|
|
|
401
|
+ name: 'edge.edges',
|
|
|
402
|
+ icon: 'router',
|
|
|
403
|
+ path: '/edges'
|
|
|
404
|
+ },
|
|
|
405
|
+ {
|
|
|
406
|
+ name: 'rulechain.edge-rulechains',
|
|
|
407
|
+ icon: 'settings_ethernet',
|
|
|
408
|
+ path: '/edges/ruleChains'
|
|
|
409
|
+ }
|
|
|
410
|
+ ]
|
|
|
411
|
+ }
|
|
|
412
|
+ );
|
|
|
413
|
+ }
|
|
|
414
|
+ homeSections.push(
|
402
|
{
|
415
|
{
|
403
|
name: 'dashboard.management',
|
416
|
name: 'dashboard.management',
|
404
|
places: [
|
417
|
places: [
|
|
@@ -433,7 +446,7 @@ export class MenuService { |
|
@@ -433,7 +446,7 @@ export class MenuService { |
433
|
return homeSections;
|
446
|
return homeSections;
|
434
|
}
|
447
|
}
|
435
|
|
448
|
|
436
|
- private buildCustomerUserMenu(authUser: any): Array<MenuSection> {
|
449
|
+ private buildCustomerUserMenu(authState: AuthState): Array<MenuSection> {
|
437
|
const sections: Array<MenuSection> = [];
|
450
|
const sections: Array<MenuSection> = [];
|
438
|
sections.push(
|
451
|
sections.push(
|
439
|
{
|
452
|
{
|
|
@@ -475,7 +488,7 @@ export class MenuService { |
|
@@ -475,7 +488,7 @@ export class MenuService { |
475
|
return sections;
|
488
|
return sections;
|
476
|
}
|
489
|
}
|
477
|
|
490
|
|
478
|
- private buildCustomerUserHome(authUser: any): Array<HomeSection> {
|
491
|
+ private buildCustomerUserHome(authState: AuthState): Array<HomeSection> {
|
479
|
const homeSections: Array<HomeSection> = [
|
492
|
const homeSections: Array<HomeSection> = [
|
480
|
{
|
493
|
{
|
481
|
name: 'asset.view-assets',
|
494
|
name: 'asset.view-assets',
|