Partial fix Edge dashboards page

This commit is contained in:
deaflynx 2020-06-22 15:52:01 +03:00
parent c242446a86
commit f035bbd941
3 changed files with 118 additions and 2 deletions

View File

@ -164,8 +164,8 @@ export class DashboardService {
}
public assignDashboardToEdge(edgeId: string, dashboardId: string, config?: RequestConfig): Observable<Dashboard> {
return this.http.post<Dashboard>(`/api/edge/${edgeId}/dashboard/${dashboardId}`, null,
defaultHttpOptionsFromConfig(config));
return this.http.post<Dashboard>(`/api/edge/${edgeId}/dashboard/${dashboardId}`,
null, defaultHttpOptionsFromConfig(config));
}
public unassignDashboardFromEdge(edgeId: string, dashboardId: string, config?: RequestConfig) {

View File

@ -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<EntityTableConfig<DashboardInfo | Dashboard>> {
private readonly config: EntityTableConfig<DashboardInfo | Dashboard> = new EntityTableConfig<DashboardInfo | Dashboard>();
private edgeId: string;
constructor(private store: Store<AppState>,
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<EntityTableConfig<
dashboardScope: route.data.dashboardsType,
customerId: routeParams.customerId
};
this.edgeId = routeParams.edgeId;
return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) {
@ -124,6 +132,9 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
} else {
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('dashboard.dashboards');
}
} else if (this.config.componentsData.dashboardScope === 'edge') {
this.edgeService.getEdge(this.edgeId).pipe(map(edge =>
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<EntityTableConfig<
this.config.entitiesFetchFunction = pageLink =>
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<EntityTableConfig<
}
);
}
if (dashboardScope === 'edge') {
actions.push(
{
name: this.translate.instant('edge.unassign-from-edge'),
icon: 'portable_wifi_off',
isEnabled: (entity) => true,
onAction: ($event, entity) => this.unassignFromEdge($event, entity)
}
);
}
return actions;
}
@ -267,6 +291,16 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
}
);
}
if (dashboardScope === 'edge') {
actions.push(
{
name: this.translate.instant('dashboard.unassign-dashboards-from-edge'),
icon: 'portable_wifi_off',
isEnabled: true,
onAction: ($event, entities) => this.unassignDashboardsFromEdge($event, entities)
}
);
}
return actions;
}
@ -298,6 +332,16 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
}
);
}
if (dashboardScope === 'edge') {
actions.push(
{
name: this.translate.instant('dashboard.assign-new-dashboard'),
icon: 'add',
isEnabled: () => true,
onAction: ($event) => this.addDashboardsToEdge($event)
}
);
}
return actions;
}
@ -503,4 +547,74 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
return false;
}
addDashboardsToEdge($event: Event) {
if ($event) {
$event.stopPropagation();
}
this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData,
boolean>(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<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) => {
tasks.push(this.dashboardService.unassignDashboardFromEdge(this.edgeId, dashboard.id.id));
}
);
forkJoin(tasks).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
}

View File

@ -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",