From f035bbd941d1d3d2b26da09e7da94347b17f7c27 Mon Sep 17 00:00:00 2001 From: deaflynx Date: Mon, 22 Jun 2020 15:52:01 +0300 Subject: [PATCH] Partial fix Edge dashboards page --- ui-ngx/src/app/core/http/dashboard.service.ts | 4 +- .../dashboards-table-config.resolver.ts | 114 ++++++++++++++++++ .../assets/locale/locale.constant-en_US.json | 2 + 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/core/http/dashboard.service.ts b/ui-ngx/src/app/core/http/dashboard.service.ts index 111ea9bfe4..7af0639d66 100644 --- a/ui-ngx/src/app/core/http/dashboard.service.ts +++ b/ui-ngx/src/app/core/http/dashboard.service.ts @@ -164,8 +164,8 @@ export class DashboardService { } public assignDashboardToEdge(edgeId: string, dashboardId: string, config?: RequestConfig): Observable { - return this.http.post(`/api/edge/${edgeId}/dashboard/${dashboardId}`, null, - defaultHttpOptionsFromConfig(config)); + return this.http.post(`/api/edge/${edgeId}/dashboard/${dashboardId}`, + null, defaultHttpOptionsFromConfig(config)); } public unassignDashboardFromEdge(edgeId: string, dashboardId: string, config?: RequestConfig) { diff --git a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts index 4d176a765d..379e26dc99 100644 --- a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts @@ -64,15 +64,22 @@ import { } from '@modules/home/pages/dashboard/make-dashboard-public-dialog.component'; import { DashboardTabsComponent } from '@home/pages/dashboard/dashboard-tabs.component'; import { ImportExportService } from '@home/components/import-export/import-export.service'; +import { EdgeService } from "@core/http/edge.service"; +import { + AddEntitiesToEdgeDialogComponent, + AddEntitiesToEdgeDialogData +} from "@home/dialogs/add-entities-to-edge-dialog.component"; @Injectable() export class DashboardsTableConfigResolver implements Resolve> { private readonly config: EntityTableConfig = new EntityTableConfig(); + private edgeId: string; constructor(private store: Store, private dashboardService: DashboardService, private customerService: CustomerService, + private edgeService: EdgeService, private dialogService: DialogService, private importExport: ImportExportService, private translate: TranslateService, @@ -106,6 +113,7 @@ export class DashboardsTableConfigResolver implements Resolve { if (authUser.authority === Authority.CUSTOMER_USER) { @@ -124,6 +132,9 @@ export class DashboardsTableConfigResolver implements Resolve + this.config.tableTitle = edge.name + ': ' + this.translate.instant('dashboard.dashboards'))).subscribe(); } else { this.config.tableTitle = this.translate.instant('dashboard.dashboards'); } @@ -165,6 +176,9 @@ export class DashboardsTableConfigResolver implements Resolve this.dashboardService.getTenantDashboards(pageLink); this.config.deleteEntity = id => this.dashboardService.deleteDashboard(id.id); + } else if (dashboardScope === 'edge') { + this.config.entitiesFetchFunction = pageLink => + this.dashboardService.getEdgeDashboards(this.edgeId, pageLink, this.config.componentsData.dashboardsType); } else { this.config.entitiesFetchFunction = pageLink => this.dashboardService.getCustomerDashboards(this.config.componentsData.customerId, pageLink); @@ -233,6 +247,16 @@ export class DashboardsTableConfigResolver implements Resolve true, + onAction: ($event, entity) => this.unassignFromEdge($event, entity) + } + ); + } return actions; } @@ -267,6 +291,16 @@ export class DashboardsTableConfigResolver implements Resolve this.unassignDashboardsFromEdge($event, entities) + } + ); + } return actions; } @@ -298,6 +332,16 @@ export class DashboardsTableConfigResolver implements Resolve true, + onAction: ($event) => this.addDashboardsToEdge($event) + } + ); + } return actions; } @@ -503,4 +547,74 @@ export class DashboardsTableConfigResolver implements Resolve(AddEntitiesToEdgeDialogComponent, { + disableClose: true, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + edgeId: this.edgeId, + entityType: EntityType.DASHBOARD + } + }).afterClosed() + .subscribe((res) => { + if (res) { + this.config.table.updateData(); + } + }); + } + + unassignFromEdge($event: Event, dashboard: DashboardInfo) { + if ($event) { + $event.stopPropagation(); + } + this.dialogService.confirm( + this.translate.instant('dashboard.unassign-dashboard-from-edge-title', {dashboardName: dashboard.name}), + this.translate.instant('dashboard.unassign-dashboard-from-edge-text'), + this.translate.instant('action.no'), + this.translate.instant('action.yes'), + true + ).subscribe((res) => { + if (res) { + this.dashboardService.unassignDashboardFromEdge(this.edgeId, dashboard.id.id).subscribe( + () => { + this.config.table.updateData(); + } + ); + } + } + ); + } + + unassignDashboardsFromEdge($event: Event, dashboards: Array) { + 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[] = []; + dashboards.forEach( + (dashboard) => { + tasks.push(this.dashboardService.unassignDashboardFromEdge(this.edgeId, dashboard.id.id)); + } + ); + forkJoin(tasks).subscribe( + () => { + this.config.table.updateData(); + } + ); + } + } + ); + } + } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 6e8ea6f85e..89a49372e6 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -468,6 +468,8 @@ "add": "Add Dashboard", "assign-dashboard-to-customer": "Assign Dashboard(s) To Customer", "assign-dashboard-to-customer-text": "Please select the dashboards to assign to the customer", + "assign-dashboard-to-edge-title": "Assign Dashboard(s) To Edge", + "assign-dashboard-to-edge-text": "Please select the dashboards to assign to the edge", "assign-to-customer-text": "Please select the customer to assign the dashboard(s)", "assign-to-customer": "Assign to customer", "unassign-from-customer": "Unassign from customer",