2019-08-20 20:42:48 +03:00
|
|
|
///
|
2020-02-20 10:26:43 +02:00
|
|
|
/// Copyright © 2016-2020 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.
|
|
|
|
|
///
|
|
|
|
|
|
2019-09-03 19:31:16 +03:00
|
|
|
import { Injectable, NgModule } from '@angular/core';
|
|
|
|
|
import { ActivatedRouteSnapshot, Resolve, RouterModule, Routes } from '@angular/router';
|
2019-08-20 20:42:48 +03:00
|
|
|
|
2019-09-19 20:10:52 +03:00
|
|
|
import { EntitiesTableComponent } from '../../components/entity/entities-table.component';
|
|
|
|
|
import { Authority } from '@shared/models/authority.enum';
|
|
|
|
|
import { WidgetsBundlesTableConfigResolver } from '@modules/home/pages/widget/widgets-bundles-table-config.resolver';
|
2019-09-03 19:31:16 +03:00
|
|
|
import { WidgetLibraryComponent } from '@home/pages/widget/widget-library.component';
|
2019-09-05 21:15:40 +03:00
|
|
|
import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb';
|
2019-09-03 19:31:16 +03:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
import { WidgetsBundle } from '@shared/models/widgets-bundle.model';
|
|
|
|
|
import { WidgetService } from '@core/http/widget.service';
|
2019-09-19 20:10:52 +03:00
|
|
|
import { WidgetEditorComponent } from '@home/pages/widget/widget-editor.component';
|
2019-09-20 20:30:43 +03:00
|
|
|
import { map, share } from 'rxjs/operators';
|
2019-09-19 20:10:52 +03:00
|
|
|
import { toWidgetInfo, WidgetInfo } from '@home/models/widget-component.models';
|
2019-09-20 20:30:43 +03:00
|
|
|
import { Widget, widgetType, WidgetType } from '@app/shared/models/widget.models';
|
2019-09-19 20:10:52 +03:00
|
|
|
import { ConfirmOnExitGuard } from '@core/guards/confirm-on-exit.guard';
|
2019-09-20 20:30:43 +03:00
|
|
|
import { WidgetsData } from '@home/models/dashboard-component.models';
|
|
|
|
|
import { NULL_UUID } from '@shared/models/id/has-uuid';
|
2019-09-19 20:10:52 +03:00
|
|
|
|
|
|
|
|
export interface WidgetEditorData {
|
|
|
|
|
widgetType: WidgetType;
|
|
|
|
|
widget: WidgetInfo;
|
|
|
|
|
}
|
2019-09-03 19:31:16 +03:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class WidgetsBundleResolver implements Resolve<WidgetsBundle> {
|
|
|
|
|
|
|
|
|
|
constructor(private widgetsService: WidgetService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<WidgetsBundle> {
|
2019-09-19 20:10:52 +03:00
|
|
|
let widgetsBundleId = route.params.widgetsBundleId;
|
|
|
|
|
if (!widgetsBundleId) {
|
|
|
|
|
widgetsBundleId = route.parent.params.widgetsBundleId;
|
|
|
|
|
}
|
2019-09-03 19:31:16 +03:00
|
|
|
return this.widgetsService.getWidgetsBundle(widgetsBundleId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-20 20:42:48 +03:00
|
|
|
|
2019-09-20 20:30:43 +03:00
|
|
|
@Injectable()
|
|
|
|
|
export class WidgetsTypesDataResolver implements Resolve<WidgetsData> {
|
|
|
|
|
|
|
|
|
|
constructor(private widgetsService: WidgetService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<WidgetsData> {
|
|
|
|
|
const widgetsBundle: WidgetsBundle = route.parent.data.widgetsBundle;
|
|
|
|
|
const bundleAlias = widgetsBundle.alias;
|
|
|
|
|
const isSystem = widgetsBundle.tenantId.id === NULL_UUID;
|
2019-11-08 17:42:31 +02:00
|
|
|
return this.widgetsService.loadBundleLibraryWidgets(bundleAlias,
|
2019-09-20 20:30:43 +03:00
|
|
|
isSystem).pipe(
|
2019-11-08 17:42:31 +02:00
|
|
|
map((widgets) => {
|
|
|
|
|
return { widgets };
|
2019-09-20 20:30:43 +03:00
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 20:10:52 +03:00
|
|
|
@Injectable()
|
|
|
|
|
export class WidgetEditorDataResolver implements Resolve<WidgetEditorData> {
|
|
|
|
|
|
|
|
|
|
constructor(private widgetsService: WidgetService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<WidgetEditorData> {
|
|
|
|
|
const widgetTypeId = route.params.widgetTypeId;
|
|
|
|
|
return this.widgetsService.getWidgetTypeById(widgetTypeId).pipe(
|
|
|
|
|
map((result) => {
|
|
|
|
|
return {
|
|
|
|
|
widgetType: result,
|
|
|
|
|
widget: toWidgetInfo(result)
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class WidgetEditorAddDataResolver implements Resolve<WidgetEditorData> {
|
|
|
|
|
|
|
|
|
|
constructor(private widgetsService: WidgetService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<WidgetEditorData> {
|
|
|
|
|
let widgetTypeParam = route.params.widgetType as widgetType;
|
|
|
|
|
if (!widgetTypeParam) {
|
|
|
|
|
widgetTypeParam = widgetType.timeseries;
|
|
|
|
|
}
|
|
|
|
|
return this.widgetsService.getWidgetTemplate(widgetTypeParam).pipe(
|
|
|
|
|
map((widget) => {
|
|
|
|
|
widget.widgetName = null;
|
|
|
|
|
return {
|
|
|
|
|
widgetType: null,
|
|
|
|
|
widget
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 21:15:40 +03:00
|
|
|
export const widgetTypesBreadcumbLabelFunction: BreadCrumbLabelFunction = ((route, translate) => route.data.widgetsBundle.title);
|
|
|
|
|
|
2019-09-19 20:10:52 +03:00
|
|
|
export const widgetEditorBreadcumbLabelFunction: BreadCrumbLabelFunction =
|
|
|
|
|
((route, translate, component) => component ? (component as WidgetEditorComponent).widget.widgetName : '');
|
|
|
|
|
|
2019-09-05 21:15:40 +03:00
|
|
|
export const routes: Routes = [
|
2019-08-20 20:42:48 +03:00
|
|
|
{
|
|
|
|
|
path: 'widgets-bundles',
|
|
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
label: 'widgets-bundle.widgets-bundles',
|
|
|
|
|
icon: 'now_widgets'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
|
|
|
|
component: EntitiesTableComponent,
|
|
|
|
|
data: {
|
|
|
|
|
auth: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'widgets-bundle.widgets-bundles'
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
entitiesTableConfig: WidgetsBundlesTableConfigResolver
|
|
|
|
|
}
|
2019-09-03 19:31:16 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: ':widgetsBundleId/widgetTypes',
|
|
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
2019-09-05 21:15:40 +03:00
|
|
|
labelFunction: widgetTypesBreadcumbLabelFunction,
|
2019-09-03 19:31:16 +03:00
|
|
|
icon: 'now_widgets'
|
|
|
|
|
} as BreadCrumbConfig
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
widgetsBundle: WidgetsBundleResolver
|
2019-09-19 20:10:52 +03:00
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
|
|
|
|
component: WidgetLibraryComponent,
|
|
|
|
|
data: {
|
|
|
|
|
auth: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'widget.widget-library'
|
2019-09-20 20:30:43 +03:00
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
widgetsData: WidgetsTypesDataResolver
|
2019-09-19 20:10:52 +03:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: ':widgetTypeId',
|
|
|
|
|
component: WidgetEditorComponent,
|
|
|
|
|
canDeactivate: [ConfirmOnExitGuard],
|
|
|
|
|
data: {
|
|
|
|
|
auth: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'widget.editor',
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
labelFunction: widgetEditorBreadcumbLabelFunction,
|
|
|
|
|
icon: 'insert_chart'
|
|
|
|
|
} as BreadCrumbConfig
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
widgetEditorData: WidgetEditorDataResolver
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'add/:widgetType',
|
|
|
|
|
component: WidgetEditorComponent,
|
|
|
|
|
canDeactivate: [ConfirmOnExitGuard],
|
|
|
|
|
data: {
|
|
|
|
|
auth: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'widget.editor',
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
labelFunction: widgetEditorBreadcumbLabelFunction,
|
|
|
|
|
icon: 'insert_chart'
|
|
|
|
|
} as BreadCrumbConfig
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
widgetEditorData: WidgetEditorAddDataResolver
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2019-12-23 14:36:44 +02:00
|
|
|
// @dynamic
|
2019-08-20 20:42:48 +03:00
|
|
|
@NgModule({
|
|
|
|
|
imports: [RouterModule.forChild(routes)],
|
|
|
|
|
exports: [RouterModule],
|
|
|
|
|
providers: [
|
2019-09-03 19:31:16 +03:00
|
|
|
WidgetsBundlesTableConfigResolver,
|
2019-09-19 20:10:52 +03:00
|
|
|
WidgetsBundleResolver,
|
2019-09-20 20:30:43 +03:00
|
|
|
WidgetsTypesDataResolver,
|
2019-09-19 20:10:52 +03:00
|
|
|
WidgetEditorDataResolver,
|
|
|
|
|
WidgetEditorAddDataResolver
|
2019-08-20 20:42:48 +03:00
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
export class WidgetLibraryRoutingModule { }
|