2019-08-20 20:42:48 +03:00
|
|
|
///
|
2022-01-17 14:07:46 +02:00
|
|
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
2019-08-20 20:42:48 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
2020-04-02 11:01:13 +03:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-08-20 20:42:48 +03:00
|
|
|
|
2020-04-02 11:01:13 +03:00
|
|
|
import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router';
|
2019-08-20 20:42:48 +03:00
|
|
|
import {
|
|
|
|
|
CellActionDescriptor,
|
|
|
|
|
checkBoxCell,
|
|
|
|
|
DateEntityTableColumn,
|
|
|
|
|
EntityTableColumn,
|
|
|
|
|
EntityTableConfig,
|
|
|
|
|
GroupActionDescriptor,
|
|
|
|
|
HeaderActionDescriptor
|
2019-08-21 18:18:46 +03:00
|
|
|
} from '@home/models/entity/entities-table-config.models';
|
2020-04-02 11:01:13 +03:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
import { DatePipe } from '@angular/common';
|
|
|
|
|
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
|
|
|
|
|
import { EntityAction } from '@home/models/entity/entity-component.models';
|
|
|
|
|
import { forkJoin, Observable, of } from 'rxjs';
|
|
|
|
|
import { select, Store } from '@ngrx/store';
|
|
|
|
|
import { selectAuthUser } from '@core/auth/auth.selectors';
|
|
|
|
|
import { map, mergeMap, take, tap } from 'rxjs/operators';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
|
|
|
|
import { Authority } from '@app/shared/models/authority.enum';
|
|
|
|
|
import { CustomerService } from '@core/http/customer.service';
|
|
|
|
|
import { Customer } from '@app/shared/models/customer.model';
|
2020-02-10 13:15:29 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2020-04-02 11:01:13 +03:00
|
|
|
import { DialogService } from '@core/services/dialog.service';
|
2019-08-20 20:42:48 +03:00
|
|
|
import {
|
|
|
|
|
AddEntitiesToCustomerDialogComponent,
|
|
|
|
|
AddEntitiesToCustomerDialogData
|
|
|
|
|
} from '../../dialogs/add-entities-to-customer-dialog.component';
|
|
|
|
|
import {
|
|
|
|
|
Dashboard,
|
|
|
|
|
DashboardInfo,
|
|
|
|
|
getDashboardAssignedCustomersText,
|
|
|
|
|
isCurrentPublicDashboardCustomer,
|
|
|
|
|
isPublicDashboard
|
|
|
|
|
} from '@app/shared/models/dashboard.models';
|
2020-04-02 11:01:13 +03:00
|
|
|
import { DashboardService } from '@app/core/http/dashboard.service';
|
|
|
|
|
import { DashboardFormComponent } from '@modules/home/pages/dashboard/dashboard-form.component';
|
2019-08-20 20:42:48 +03:00
|
|
|
import {
|
|
|
|
|
ManageDashboardCustomersActionType,
|
|
|
|
|
ManageDashboardCustomersDialogComponent,
|
|
|
|
|
ManageDashboardCustomersDialogData
|
|
|
|
|
} from './manage-dashboard-customers-dialog.component';
|
2019-08-21 13:36:39 +03:00
|
|
|
import {
|
|
|
|
|
MakeDashboardPublicDialogComponent,
|
|
|
|
|
MakeDashboardPublicDialogData
|
|
|
|
|
} from '@modules/home/pages/dashboard/make-dashboard-public-dialog.component';
|
2019-08-22 13:34:15 +03:00
|
|
|
import { DashboardTabsComponent } from '@home/pages/dashboard/dashboard-tabs.component';
|
2019-11-08 14:17:15 +02:00
|
|
|
import { ImportExportService } from '@home/components/import-export/import-export.service';
|
2021-01-12 22:01:32 +02:00
|
|
|
import { EdgeService } from '@core/http/edge.service';
|
2020-06-22 15:52:01 +03:00
|
|
|
import {
|
|
|
|
|
AddEntitiesToEdgeDialogComponent,
|
|
|
|
|
AddEntitiesToEdgeDialogData
|
2021-01-12 22:01:32 +02:00
|
|
|
} from '@home/dialogs/add-entities-to-edge-dialog.component';
|
2019-08-20 20:42:48 +03:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<DashboardInfo | Dashboard>> {
|
|
|
|
|
|
|
|
|
|
private readonly config: EntityTableConfig<DashboardInfo | Dashboard> = new EntityTableConfig<DashboardInfo | Dashboard>();
|
|
|
|
|
|
|
|
|
|
constructor(private store: Store<AppState>,
|
|
|
|
|
private dashboardService: DashboardService,
|
|
|
|
|
private customerService: CustomerService,
|
2020-06-22 15:52:01 +03:00
|
|
|
private edgeService: EdgeService,
|
2019-08-20 20:42:48 +03:00
|
|
|
private dialogService: DialogService,
|
2019-11-08 14:17:15 +02:00
|
|
|
private importExport: ImportExportService,
|
2019-08-20 20:42:48 +03:00
|
|
|
private translate: TranslateService,
|
|
|
|
|
private datePipe: DatePipe,
|
|
|
|
|
private router: Router,
|
|
|
|
|
private dialog: MatDialog) {
|
|
|
|
|
|
|
|
|
|
this.config.entityType = EntityType.DASHBOARD;
|
|
|
|
|
this.config.entityComponent = DashboardFormComponent;
|
2019-08-22 13:34:15 +03:00
|
|
|
this.config.entityTabsComponent = DashboardTabsComponent;
|
2019-08-20 20:42:48 +03:00
|
|
|
this.config.entityTranslations = entityTypeTranslations.get(EntityType.DASHBOARD);
|
|
|
|
|
this.config.entityResources = entityTypeResources.get(EntityType.DASHBOARD);
|
|
|
|
|
|
|
|
|
|
this.config.deleteEntityTitle = dashboard =>
|
2021-04-15 11:53:45 +03:00
|
|
|
this.translate.instant('dashboard.delete-dashboard-title', {dashboardTitle: dashboard.title});
|
2019-08-20 20:42:48 +03:00
|
|
|
this.config.deleteEntityContent = () => this.translate.instant('dashboard.delete-dashboard-text');
|
|
|
|
|
this.config.deleteEntitiesTitle = count => this.translate.instant('dashboard.delete-dashboards-title', {count});
|
|
|
|
|
this.config.deleteEntitiesContent = () => this.translate.instant('dashboard.delete-dashboards-text');
|
|
|
|
|
|
|
|
|
|
this.config.loadEntity = id => this.dashboardService.getDashboard(id.id);
|
|
|
|
|
this.config.saveEntity = dashboard => {
|
|
|
|
|
return this.dashboardService.saveDashboard(dashboard as Dashboard);
|
|
|
|
|
};
|
|
|
|
|
this.config.onEntityAction = action => this.onDashboardAction(action);
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.detailsReadonly = () => (this.config.componentsData.dashboardScope === 'customer_user' ||
|
|
|
|
|
this.config.componentsData.dashboardScope === 'edge_customer_user');
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<EntityTableConfig<DashboardInfo | Dashboard>> {
|
|
|
|
|
const routeParams = route.params;
|
|
|
|
|
this.config.componentsData = {
|
|
|
|
|
dashboardScope: route.data.dashboardsType,
|
2020-06-24 11:16:46 +03:00
|
|
|
customerId: routeParams.customerId,
|
|
|
|
|
edgeId: routeParams.edgeId
|
2019-08-20 20:42:48 +03:00
|
|
|
};
|
|
|
|
|
return this.store.pipe(select(selectAuthUser), take(1)).pipe(
|
|
|
|
|
tap((authUser) => {
|
|
|
|
|
if (authUser.authority === Authority.CUSTOMER_USER) {
|
2020-12-29 16:55:07 +02:00
|
|
|
if (route.data.dashboardsType === 'edge') {
|
|
|
|
|
this.config.componentsData.dashboardScope = 'edge_customer_user';
|
|
|
|
|
} else {
|
|
|
|
|
this.config.componentsData.dashboardScope = 'customer_user';
|
|
|
|
|
}
|
2019-08-20 20:42:48 +03:00
|
|
|
this.config.componentsData.customerId = authUser.customerId;
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
mergeMap(() =>
|
|
|
|
|
this.config.componentsData.customerId ?
|
|
|
|
|
this.customerService.getCustomer(this.config.componentsData.customerId) : of(null as Customer)
|
|
|
|
|
),
|
|
|
|
|
map((parentCustomer) => {
|
|
|
|
|
if (parentCustomer) {
|
|
|
|
|
if (parentCustomer.additionalInfo && parentCustomer.additionalInfo.isPublic) {
|
|
|
|
|
this.config.tableTitle = this.translate.instant('customer.public-dashboards');
|
|
|
|
|
} else {
|
|
|
|
|
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('dashboard.dashboards');
|
|
|
|
|
}
|
2020-06-22 15:52:01 +03:00
|
|
|
} else if (this.config.componentsData.dashboardScope === 'edge') {
|
2020-11-05 12:18:46 +02:00
|
|
|
this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe(
|
|
|
|
|
edge => this.config.tableTitle = edge.name + ': ' + this.translate.instant('dashboard.dashboards')
|
|
|
|
|
);
|
2019-08-20 20:42:48 +03:00
|
|
|
} else {
|
|
|
|
|
this.config.tableTitle = this.translate.instant('dashboard.dashboards');
|
|
|
|
|
}
|
|
|
|
|
this.config.columns = this.configureColumns(this.config.componentsData.dashboardScope);
|
|
|
|
|
this.configureEntityFunctions(this.config.componentsData.dashboardScope);
|
|
|
|
|
this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.dashboardScope);
|
|
|
|
|
this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.dashboardScope);
|
|
|
|
|
this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.dashboardScope);
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.addEnabled = !(this.config.componentsData.dashboardScope === 'customer_user' ||
|
|
|
|
|
this.config.componentsData.dashboardScope === 'edge_customer_user');
|
2019-08-20 20:42:48 +03:00
|
|
|
this.config.entitiesDeleteEnabled = this.config.componentsData.dashboardScope === 'tenant';
|
|
|
|
|
this.config.deleteEnabled = () => this.config.componentsData.dashboardScope === 'tenant';
|
|
|
|
|
return this.config;
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureColumns(dashboardScope: string): Array<EntityTableColumn<DashboardInfo>> {
|
|
|
|
|
const columns: Array<EntityTableColumn<DashboardInfo>> = [
|
2020-04-02 11:01:13 +03:00
|
|
|
new DateEntityTableColumn<DashboardInfo>('createdTime', 'common.created-time', this.datePipe, '150px'),
|
2020-01-24 19:05:41 +02:00
|
|
|
new EntityTableColumn<DashboardInfo>('title', 'dashboard.title', '50%')
|
2019-08-20 20:42:48 +03:00
|
|
|
];
|
|
|
|
|
if (dashboardScope === 'tenant') {
|
|
|
|
|
columns.push(
|
|
|
|
|
new EntityTableColumn<DashboardInfo>('customersTitle', 'dashboard.assignedToCustomers',
|
2020-01-24 19:05:41 +02:00
|
|
|
'50%', entity => {
|
2019-08-20 20:42:48 +03:00
|
|
|
return getDashboardAssignedCustomersText(entity);
|
|
|
|
|
}, () => ({}), false),
|
|
|
|
|
new EntityTableColumn<DashboardInfo>('dashboardIsPublic', 'dashboard.public', '60px',
|
|
|
|
|
entity => {
|
|
|
|
|
return checkBoxCell(isPublicDashboard(entity));
|
|
|
|
|
}, () => ({}), false),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return columns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureEntityFunctions(dashboardScope: string): void {
|
|
|
|
|
if (dashboardScope === 'tenant') {
|
|
|
|
|
this.config.entitiesFetchFunction = pageLink =>
|
|
|
|
|
this.dashboardService.getTenantDashboards(pageLink);
|
|
|
|
|
this.config.deleteEntity = id => this.dashboardService.deleteDashboard(id.id);
|
2020-12-29 16:55:07 +02:00
|
|
|
} else if (dashboardScope === 'edge' || dashboardScope === 'edge_customer_user') {
|
2020-06-22 15:52:01 +03:00
|
|
|
this.config.entitiesFetchFunction = pageLink =>
|
2020-06-24 11:16:46 +03:00
|
|
|
this.dashboardService.getEdgeDashboards(this.config.componentsData.edgeId, pageLink, this.config.componentsData.dashboardsType);
|
2019-08-20 20:42:48 +03:00
|
|
|
} else {
|
|
|
|
|
this.config.entitiesFetchFunction = pageLink =>
|
|
|
|
|
this.dashboardService.getCustomerDashboards(this.config.componentsData.customerId, pageLink);
|
|
|
|
|
this.config.deleteEntity = id =>
|
|
|
|
|
this.dashboardService.unassignDashboardFromCustomer(this.config.componentsData.customerId, id.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureCellActions(dashboardScope: string): Array<CellActionDescriptor<DashboardInfo>> {
|
|
|
|
|
const actions: Array<CellActionDescriptor<DashboardInfo>> = [];
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.open-dashboard'),
|
|
|
|
|
icon: 'dashboard',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event, entity) => this.openDashboard($event, entity)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
if (dashboardScope === 'tenant') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.export'),
|
|
|
|
|
icon: 'file_download',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event, entity) => this.exportDashboard($event, entity)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.make-public'),
|
|
|
|
|
icon: 'share',
|
|
|
|
|
isEnabled: (entity) => !isPublicDashboard(entity),
|
|
|
|
|
onAction: ($event, entity) => this.makePublic($event, entity)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.make-private'),
|
|
|
|
|
icon: 'reply',
|
|
|
|
|
isEnabled: (entity) => isPublicDashboard(entity),
|
|
|
|
|
onAction: ($event, entity) => this.makePrivate($event, entity)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.manage-assigned-customers'),
|
|
|
|
|
icon: 'assignment_ind',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event, entity) => this.manageAssignedCustomers($event, entity)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (dashboardScope === 'customer') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.export'),
|
|
|
|
|
icon: 'file_download',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event, entity) => this.exportDashboard($event, entity)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.make-private'),
|
|
|
|
|
icon: 'reply',
|
|
|
|
|
isEnabled: (entity) => isCurrentPublicDashboardCustomer(entity, this.config.componentsData.customerId),
|
|
|
|
|
onAction: ($event, entity) => this.makePrivate($event, entity)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.unassign-from-customer'),
|
|
|
|
|
icon: 'assignment_return',
|
|
|
|
|
isEnabled: (entity) => !isCurrentPublicDashboardCustomer(entity, this.config.componentsData.customerId),
|
|
|
|
|
onAction: ($event, entity) => this.unassignFromCustomer($event, entity, this.config.componentsData.customerId)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-22 15:52:01 +03:00
|
|
|
if (dashboardScope === 'edge') {
|
|
|
|
|
actions.push(
|
2020-12-11 11:04:19 +02:00
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.export'),
|
|
|
|
|
icon: 'file_download',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event, entity) => this.exportDashboard($event, entity)
|
|
|
|
|
},
|
2020-06-22 15:52:01 +03:00
|
|
|
{
|
|
|
|
|
name: this.translate.instant('edge.unassign-from-edge'),
|
2020-12-21 19:14:22 +02:00
|
|
|
icon: 'assignment_return',
|
2020-06-22 15:52:01 +03:00
|
|
|
isEnabled: (entity) => true,
|
|
|
|
|
onAction: ($event, entity) => this.unassignFromEdge($event, entity)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-08-20 20:42:48 +03:00
|
|
|
return actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureGroupActions(dashboardScope: string): Array<GroupActionDescriptor<DashboardInfo>> {
|
|
|
|
|
const actions: Array<GroupActionDescriptor<DashboardInfo>> = [];
|
|
|
|
|
if (dashboardScope === 'tenant') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.assign-dashboards'),
|
|
|
|
|
icon: 'assignment_ind',
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
onAction: ($event, entities) => this.assignDashboardsToCustomers($event, entities.map((entity) => entity.id.id))
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.unassign-dashboards'),
|
|
|
|
|
icon: 'assignment_return',
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
onAction: ($event, entities) => this.unassignDashboardsFromCustomers($event, entities.map((entity) => entity.id.id))
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (dashboardScope === 'customer') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.unassign-dashboards'),
|
|
|
|
|
icon: 'assignment_return',
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
onAction: ($event, entities) =>
|
|
|
|
|
this.unassignDashboardsFromCustomer($event, entities.map((entity) => entity.id.id), this.config.componentsData.customerId)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-22 15:52:01 +03:00
|
|
|
if (dashboardScope === 'edge') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
2020-12-21 13:28:53 +02:00
|
|
|
name: this.translate.instant('dashboard.unassign-dashboards'),
|
2020-12-21 19:14:22 +02:00
|
|
|
icon: 'assignment_return',
|
2020-06-22 15:52:01 +03:00
|
|
|
isEnabled: true,
|
|
|
|
|
onAction: ($event, entities) => this.unassignDashboardsFromEdge($event, entities)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-08-20 20:42:48 +03:00
|
|
|
return actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureAddActions(dashboardScope: string): Array<HeaderActionDescriptor> {
|
|
|
|
|
const actions: Array<HeaderActionDescriptor> = [];
|
|
|
|
|
if (dashboardScope === 'tenant') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.create-new-dashboard'),
|
|
|
|
|
icon: 'insert_drive_file',
|
|
|
|
|
isEnabled: () => true,
|
2022-01-19 17:02:18 +02:00
|
|
|
onAction: ($event) => this.config.getTable().addEntity($event)
|
2019-08-20 20:42:48 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.import'),
|
|
|
|
|
icon: 'file_upload',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event) => this.importDashboard($event)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (dashboardScope === 'customer') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.assign-new-dashboard'),
|
|
|
|
|
icon: 'add',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event) => this.addDashboardsToCustomer($event)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-22 15:52:01 +03:00
|
|
|
if (dashboardScope === 'edge') {
|
|
|
|
|
actions.push(
|
|
|
|
|
{
|
|
|
|
|
name: this.translate.instant('dashboard.assign-new-dashboard'),
|
|
|
|
|
icon: 'add',
|
|
|
|
|
isEnabled: () => true,
|
|
|
|
|
onAction: ($event) => this.addDashboardsToEdge($event)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-08-20 20:42:48 +03:00
|
|
|
return actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openDashboard($event: Event, dashboard: DashboardInfo) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
2019-09-19 20:10:52 +03:00
|
|
|
if (this.config.componentsData.dashboardScope === 'customer') {
|
|
|
|
|
this.router.navigateByUrl(`customers/${this.config.componentsData.customerId}/dashboards/${dashboard.id.id}`);
|
2020-12-11 11:31:05 +02:00
|
|
|
} else if (this.config.componentsData.dashboardScope === 'edge') {
|
2021-05-26 21:02:35 +03:00
|
|
|
this.router.navigateByUrl(`edgeInstances/${this.config.componentsData.edgeId}/dashboards/${dashboard.id.id}`);
|
2021-04-15 11:53:45 +03:00
|
|
|
} else {
|
2019-09-19 20:10:52 +03:00
|
|
|
this.router.navigateByUrl(`dashboards/${dashboard.id.id}`);
|
|
|
|
|
}
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
importDashboard($event: Event) {
|
2019-11-08 14:17:15 +02:00
|
|
|
this.importExport.importDashboard().subscribe(
|
|
|
|
|
(dashboard) => {
|
|
|
|
|
if (dashboard) {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2019-11-08 14:17:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exportDashboard($event: Event, dashboard: DashboardInfo) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
2019-11-08 14:17:15 +02:00
|
|
|
this.importExport.exportDashboard(dashboard.id.id);
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addDashboardsToCustomer($event: Event) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialog.open<AddEntitiesToCustomerDialogComponent, AddEntitiesToCustomerDialogData,
|
|
|
|
|
boolean>(AddEntitiesToCustomerDialogComponent, {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
customerId: this.config.componentsData.customerId,
|
|
|
|
|
entityType: EntityType.DASHBOARD
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed()
|
|
|
|
|
.subscribe((res) => {
|
|
|
|
|
if (res) {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makePublic($event: Event, dashboard: DashboardInfo) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dashboardService.makeDashboardPublic(dashboard.id.id).subscribe(
|
|
|
|
|
(publicDashboard) => {
|
2019-08-21 13:36:39 +03:00
|
|
|
this.dialog.open<MakeDashboardPublicDialogComponent, MakeDashboardPublicDialogData>
|
|
|
|
|
(MakeDashboardPublicDialogComponent, {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
dashboard: publicDashboard
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed()
|
|
|
|
|
.subscribe(() => {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2019-08-21 13:36:39 +03:00
|
|
|
});
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makePrivate($event: Event, dashboard: DashboardInfo) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialogService.confirm(
|
|
|
|
|
this.translate.instant('dashboard.make-private-dashboard-title', {dashboardTitle: dashboard.title}),
|
|
|
|
|
this.translate.instant('dashboard.make-private-dashboard-text'),
|
|
|
|
|
this.translate.instant('action.no'),
|
|
|
|
|
this.translate.instant('action.yes'),
|
|
|
|
|
true
|
|
|
|
|
).subscribe((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
this.dashboardService.makeDashboardPrivate(dashboard.id.id).subscribe(
|
|
|
|
|
() => {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
manageAssignedCustomers($event: Event, dashboard: DashboardInfo) {
|
|
|
|
|
const assignedCustomersIds = dashboard.assignedCustomers ?
|
|
|
|
|
dashboard.assignedCustomers.map(customerInfo => customerInfo.customerId.id) : [];
|
|
|
|
|
this.showManageAssignedCustomersDialog($event, [dashboard.id.id], 'manage', assignedCustomersIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assignDashboardsToCustomers($event: Event, dashboardIds: Array<string>) {
|
|
|
|
|
this.showManageAssignedCustomersDialog($event, dashboardIds, 'assign');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unassignDashboardsFromCustomers($event: Event, dashboardIds: Array<string>) {
|
|
|
|
|
this.showManageAssignedCustomersDialog($event, dashboardIds, 'unassign');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showManageAssignedCustomersDialog($event: Event, dashboardIds: Array<string>,
|
|
|
|
|
actionType: ManageDashboardCustomersActionType,
|
|
|
|
|
assignedCustomersIds?: Array<string>) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialog.open<ManageDashboardCustomersDialogComponent, ManageDashboardCustomersDialogData,
|
|
|
|
|
boolean>(ManageDashboardCustomersDialogComponent, {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
dashboardIds,
|
|
|
|
|
actionType,
|
|
|
|
|
assignedCustomersIds
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed()
|
|
|
|
|
.subscribe((res) => {
|
|
|
|
|
if (res) {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unassignFromCustomer($event: Event, dashboard: DashboardInfo, customerId: string) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialogService.confirm(
|
|
|
|
|
this.translate.instant('dashboard.unassign-dashboard-title', {dashboardTitle: dashboard.title}),
|
|
|
|
|
this.translate.instant('dashboard.unassign-dashboard-text'),
|
|
|
|
|
this.translate.instant('action.no'),
|
|
|
|
|
this.translate.instant('action.yes'),
|
|
|
|
|
true
|
|
|
|
|
).subscribe((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
this.dashboardService.unassignDashboardFromCustomer(customerId, dashboard.id.id).subscribe(
|
|
|
|
|
() => {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData(this.config.componentsData.dashboardScope !== 'tenant');
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unassignDashboardsFromCustomer($event: Event, dashboardIds: Array<string>, customerId: string) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialogService.confirm(
|
|
|
|
|
this.translate.instant('dashboard.unassign-dashboards-title', {count: dashboardIds.length}),
|
|
|
|
|
this.translate.instant('dashboard.unassign-dashboards-text'),
|
|
|
|
|
this.translate.instant('action.no'),
|
|
|
|
|
this.translate.instant('action.yes'),
|
|
|
|
|
true
|
|
|
|
|
).subscribe((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
const tasks: Observable<any>[] = [];
|
|
|
|
|
dashboardIds.forEach(
|
|
|
|
|
(dashboardId) => {
|
|
|
|
|
tasks.push(this.dashboardService.unassignDashboardFromCustomer(customerId, dashboardId));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
forkJoin(tasks).subscribe(
|
|
|
|
|
() => {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDashboardAction(action: EntityAction<DashboardInfo>): boolean {
|
|
|
|
|
switch (action.action) {
|
|
|
|
|
case 'open':
|
|
|
|
|
this.openDashboard(action.event, action.entity);
|
|
|
|
|
return true;
|
|
|
|
|
case 'export':
|
|
|
|
|
this.exportDashboard(action.event, action.entity);
|
|
|
|
|
return true;
|
|
|
|
|
case 'makePublic':
|
|
|
|
|
this.makePublic(action.event, action.entity);
|
|
|
|
|
return true;
|
|
|
|
|
case 'makePrivate':
|
|
|
|
|
this.makePrivate(action.event, action.entity);
|
|
|
|
|
return true;
|
|
|
|
|
case 'manageAssignedCustomers':
|
|
|
|
|
this.manageAssignedCustomers(action.event, action.entity);
|
|
|
|
|
return true;
|
|
|
|
|
case 'unassignFromCustomer':
|
|
|
|
|
this.unassignFromCustomer(action.event, action.entity, this.config.componentsData.customerId);
|
|
|
|
|
return true;
|
2020-12-10 16:59:15 +02:00
|
|
|
case 'unassignFromEdge':
|
|
|
|
|
this.unassignFromEdge(action.event, action.entity);
|
|
|
|
|
return true;
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 15:52:01 +03:00
|
|
|
addDashboardsToEdge($event: Event) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData,
|
|
|
|
|
boolean>(AddEntitiesToEdgeDialogComponent, {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
2020-06-24 11:16:46 +03:00
|
|
|
edgeId: this.config.componentsData.edgeId,
|
2020-06-22 15:52:01 +03:00
|
|
|
entityType: EntityType.DASHBOARD
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed()
|
|
|
|
|
.subscribe((res) => {
|
|
|
|
|
if (res) {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2020-06-22 15:52:01 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unassignFromEdge($event: Event, dashboard: DashboardInfo) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialogService.confirm(
|
2020-12-10 16:59:15 +02:00
|
|
|
this.translate.instant('dashboard.unassign-dashboard-title', {dashboardTitle: dashboard.title}),
|
2020-06-22 15:52:01 +03:00
|
|
|
this.translate.instant('dashboard.unassign-dashboard-from-edge-text'),
|
|
|
|
|
this.translate.instant('action.no'),
|
|
|
|
|
this.translate.instant('action.yes'),
|
|
|
|
|
true
|
|
|
|
|
).subscribe((res) => {
|
|
|
|
|
if (res) {
|
2020-06-24 11:16:46 +03:00
|
|
|
this.dashboardService.unassignDashboardFromEdge(this.config.componentsData.edgeId, dashboard.id.id).subscribe(
|
2020-06-22 15:52:01 +03:00
|
|
|
() => {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData(this.config.componentsData.dashboardScope !== 'tenant');
|
2020-06-22 15:52:01 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unassignDashboardsFromEdge($event: Event, dashboards: Array<DashboardInfo>) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
this.dialogService.confirm(
|
|
|
|
|
this.translate.instant('dashboard.unassign-dashboards-from-edge-title', {count: dashboards.length}),
|
|
|
|
|
this.translate.instant('dashboard.unassign-dashboards-from-edge-text'),
|
|
|
|
|
this.translate.instant('action.no'),
|
|
|
|
|
this.translate.instant('action.yes'),
|
|
|
|
|
true
|
|
|
|
|
).subscribe((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
const tasks: Observable<any>[] = [];
|
|
|
|
|
dashboards.forEach(
|
|
|
|
|
(dashboard) => {
|
2020-06-24 11:16:46 +03:00
|
|
|
tasks.push(this.dashboardService.unassignDashboardFromEdge(this.config.componentsData.edgeId, dashboard.id.id));
|
2020-06-22 15:52:01 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
forkJoin(tasks).subscribe(
|
|
|
|
|
() => {
|
2022-01-19 17:02:18 +02:00
|
|
|
this.config.updateData();
|
2020-06-22 15:52:01 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|