Browse Source

UI: Load home dashboards from asset resources

pull/8946/head
Igor Kulikov 3 years ago
parent
commit
a9b8a6459e
  1. 43
      ui-ngx/src/app/modules/home/pages/home-links/home-links-routing.module.ts
  2. 0
      ui-ngx/src/assets/dashboard/customer_user_home_page.json
  3. 0
      ui-ngx/src/assets/dashboard/sys_admin_home_page.json
  4. 0
      ui-ngx/src/assets/dashboard/tenant_admin_home_page.json

43
ui-ngx/src/app/modules/home/pages/home-links/home-links-routing.module.ts

@ -25,20 +25,19 @@ import { DashboardService } from '@core/http/dashboard.service';
import { select, Store } from '@ngrx/store'; import { select, Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { import { getCurrentAuthUser, selectPersistDeviceStateToTelemetry } from '@core/auth/auth.selectors';
getCurrentAuthUser,
selectHasRepository,
selectPersistDeviceStateToTelemetry
} from '@core/auth/auth.selectors';
import sysAdminHomePageDashboardJson from '!raw-loader!./sys_admin_home_page.raw';
import tenantAdminHomePageDashboardJson from '!raw-loader!./tenant_admin_home_page.raw';
import customerUserHomePageDashboardJson from '!raw-loader!./customer_user_home_page.raw';
import { EntityKeyType } from '@shared/models/query/query.models'; import { EntityKeyType } from '@shared/models/query/query.models';
import { ResourcesService } from '@core/services/resources.service';
const sysAdminHomePageJson = '/assets/dashboard/sys_admin_home_page.json';
const tenantAdminHomePageJson = '/assets/dashboard/tenant_admin_home_page.json';
const customerUserHomePageJson = '/assets/dashboard/customer_user_home_page.json';
@Injectable() @Injectable()
export class HomeDashboardResolver implements Resolve<HomeDashboard> { export class HomeDashboardResolver implements Resolve<HomeDashboard> {
constructor(private dashboardService: DashboardService, constructor(private dashboardService: DashboardService,
private resourcesService: ResourcesService,
private store: Store<AppState>) { private store: Store<AppState>) {
} }
@ -50,13 +49,13 @@ export class HomeDashboardResolver implements Resolve<HomeDashboard> {
const authority = getCurrentAuthUser(this.store).authority; const authority = getCurrentAuthUser(this.store).authority;
switch (authority) { switch (authority) {
case Authority.SYS_ADMIN: case Authority.SYS_ADMIN:
dashboard$ = of(JSON.parse(sysAdminHomePageDashboardJson)); dashboard$ = this.resourcesService.loadJsonResource(sysAdminHomePageJson);
break; break;
case Authority.TENANT_ADMIN: case Authority.TENANT_ADMIN:
dashboard$ = this.updateDeviceActivityKeyFilterIfNeeded(JSON.parse(tenantAdminHomePageDashboardJson)); dashboard$ = this.updateDeviceActivityKeyFilterIfNeeded(this.resourcesService.loadJsonResource(tenantAdminHomePageJson));
break; break;
case Authority.CUSTOMER_USER: case Authority.CUSTOMER_USER:
dashboard$ = this.updateDeviceActivityKeyFilterIfNeeded(JSON.parse(customerUserHomePageDashboardJson)); dashboard$ = this.updateDeviceActivityKeyFilterIfNeeded(this.resourcesService.loadJsonResource(customerUserHomePageJson));
break; break;
} }
if (dashboard$) { if (dashboard$) {
@ -73,18 +72,20 @@ export class HomeDashboardResolver implements Resolve<HomeDashboard> {
); );
} }
private updateDeviceActivityKeyFilterIfNeeded(dashboard: HomeDashboard): Observable<HomeDashboard> { private updateDeviceActivityKeyFilterIfNeeded(dashboard$: Observable<HomeDashboard>): Observable<HomeDashboard> {
return this.store.pipe(select(selectPersistDeviceStateToTelemetry)).pipe( return this.store.pipe(select(selectPersistDeviceStateToTelemetry)).pipe(
map((persistToTelemetry) => { mergeMap((persistToTelemetry) => dashboard$.pipe(
if (persistToTelemetry) { map((dashboard) => {
for (const filterId of Object.keys(dashboard.configuration.filters)) { if (persistToTelemetry) {
if (['Active Devices', 'Inactive Devices'].includes(dashboard.configuration.filters[filterId].filter)) { for (const filterId of Object.keys(dashboard.configuration.filters)) {
dashboard.configuration.filters[filterId].keyFilters[0].key.type = EntityKeyType.TIME_SERIES; if (['Active Devices', 'Inactive Devices'].includes(dashboard.configuration.filters[filterId].filter)) {
dashboard.configuration.filters[filterId].keyFilters[0].key.type = EntityKeyType.TIME_SERIES;
}
}
} }
} return dashboard;
} })
return dashboard; ))
})
); );
} }
} }

0
ui-ngx/src/app/modules/home/pages/home-links/customer_user_home_page.raw → ui-ngx/src/assets/dashboard/customer_user_home_page.json

0
ui-ngx/src/app/modules/home/pages/home-links/sys_admin_home_page.raw → ui-ngx/src/assets/dashboard/sys_admin_home_page.json

0
ui-ngx/src/app/modules/home/pages/home-links/tenant_admin_home_page.raw → ui-ngx/src/assets/dashboard/tenant_admin_home_page.json

Loading…
Cancel
Save