2019-08-14 19:55:24 +03:00
|
|
|
///
|
2021-01-11 13:42:16 +02:00
|
|
|
/// Copyright © 2016-2021 The Thingsboard Authors
|
2019-08-14 19:55:24 +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-05 21:15:40 +03:00
|
|
|
import { IDashboardComponent } from '@home/models/dashboard-component.models';
|
2019-09-06 20:17:45 +03:00
|
|
|
import {
|
2019-09-10 15:12:10 +03:00
|
|
|
DataSet,
|
2020-04-27 09:27:14 +03:00
|
|
|
Datasource,
|
|
|
|
|
DatasourceData,
|
|
|
|
|
JsonSettingsSchema,
|
|
|
|
|
Widget,
|
2019-09-06 20:17:45 +03:00
|
|
|
WidgetActionDescriptor,
|
|
|
|
|
WidgetActionSource,
|
|
|
|
|
WidgetConfig,
|
|
|
|
|
WidgetControllerDescriptor,
|
|
|
|
|
WidgetType,
|
|
|
|
|
widgetType,
|
2021-05-27 18:07:06 +03:00
|
|
|
WidgetTypeDescriptor,
|
|
|
|
|
WidgetTypeDetails,
|
2020-04-27 09:27:14 +03:00
|
|
|
WidgetTypeParameters
|
2019-09-06 20:17:45 +03:00
|
|
|
} from '@shared/models/widget.models';
|
2019-09-12 19:58:42 +03:00
|
|
|
import { Timewindow, WidgetTimewindow } from '@shared/models/time/time.models';
|
2019-09-05 21:15:40 +03:00
|
|
|
import {
|
|
|
|
|
IAliasController,
|
2019-09-06 20:17:45 +03:00
|
|
|
IStateController,
|
|
|
|
|
IWidgetSubscription,
|
|
|
|
|
IWidgetUtils,
|
2020-04-27 09:27:14 +03:00
|
|
|
RpcApi,
|
|
|
|
|
SubscriptionEntityInfo,
|
2019-09-06 20:17:45 +03:00
|
|
|
TimewindowFunctions,
|
2019-09-05 21:15:40 +03:00
|
|
|
WidgetActionsApi,
|
2020-04-27 09:27:14 +03:00
|
|
|
WidgetSubscriptionApi
|
2019-09-05 21:15:40 +03:00
|
|
|
} from '@core/api/widget-api.models';
|
2020-01-22 20:05:30 +02:00
|
|
|
import { ChangeDetectorRef, ComponentFactory, Injector, NgZone, Type } from '@angular/core';
|
2020-05-20 19:42:58 +03:00
|
|
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
2019-09-12 19:58:42 +03:00
|
|
|
import { RafService } from '@core/services/raf.service';
|
2019-09-23 20:35:31 +03:00
|
|
|
import { WidgetTypeId } from '@shared/models/id/widget-type-id';
|
|
|
|
|
import { TenantId } from '@shared/models/id/tenant-id';
|
2019-09-25 19:37:29 +03:00
|
|
|
import { WidgetLayout } from '@shared/models/dashboard.models';
|
2020-04-27 09:27:14 +03:00
|
|
|
import { formatValue, isDefined } from '@core/utils';
|
|
|
|
|
import { forkJoin, of } from 'rxjs';
|
2020-02-28 19:49:14 +02:00
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
|
|
|
|
import {
|
|
|
|
|
NotificationHorizontalPosition,
|
|
|
|
|
NotificationType,
|
|
|
|
|
NotificationVerticalPosition
|
|
|
|
|
} from '@core/notification/notification.models';
|
2020-06-26 17:02:41 +03:00
|
|
|
import { ActionNotificationHide, ActionNotificationShow } from '@core/notification/notification.actions';
|
2020-04-28 14:58:21 +03:00
|
|
|
import { AuthUser } from '@shared/models/user.model';
|
|
|
|
|
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
|
2020-05-20 19:42:58 +03:00
|
|
|
import { DeviceService } from '@core/http/device.service';
|
|
|
|
|
import { AssetService } from '@core/http/asset.service';
|
|
|
|
|
import { EntityViewService } from '@core/http/entity-view.service';
|
|
|
|
|
import { CustomerService } from '@core/http/customer.service';
|
|
|
|
|
import { DashboardService } from '@core/http/dashboard.service';
|
|
|
|
|
import { UserService } from '@core/http/user.service';
|
|
|
|
|
import { AttributeService } from '@core/http/attribute.service';
|
|
|
|
|
import { EntityRelationService } from '@core/http/entity-relation.service';
|
|
|
|
|
import { EntityService } from '@core/http/entity.service';
|
|
|
|
|
import { DialogService } from '@core/services/dialog.service';
|
|
|
|
|
import { CustomDialogService } from '@home/components/widget/dialog/custom-dialog.service';
|
|
|
|
|
import { DatePipe } from '@angular/common';
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2020-06-05 15:36:28 +03:00
|
|
|
import { PageLink } from '@shared/models/page/page-link';
|
|
|
|
|
import { SortOrder } from '@shared/models/page/sort-order';
|
2020-08-06 19:05:46 +03:00
|
|
|
import { DomSanitizer } from '@angular/platform-browser';
|
2020-08-31 16:39:54 +03:00
|
|
|
import { Router } from '@angular/router';
|
2021-05-04 19:44:15 +03:00
|
|
|
import { map, mergeMap } from 'rxjs/operators';
|
2019-09-05 21:15:40 +03:00
|
|
|
|
2019-09-03 19:31:16 +03:00
|
|
|
export interface IWidgetAction {
|
2019-09-05 21:15:40 +03:00
|
|
|
name: string;
|
2019-09-03 19:31:16 +03:00
|
|
|
icon: string;
|
|
|
|
|
onAction: ($event: Event) => void;
|
|
|
|
|
}
|
2019-08-14 19:55:24 +03:00
|
|
|
|
2019-09-03 19:31:16 +03:00
|
|
|
export interface WidgetHeaderAction extends IWidgetAction {
|
|
|
|
|
displayName: string;
|
2019-09-05 21:15:40 +03:00
|
|
|
descriptor: WidgetActionDescriptor;
|
2019-08-14 19:55:24 +03:00
|
|
|
}
|
|
|
|
|
|
2019-09-03 19:31:16 +03:00
|
|
|
export interface WidgetAction extends IWidgetAction {
|
|
|
|
|
show: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 20:05:30 +02:00
|
|
|
export interface IDashboardWidget {
|
|
|
|
|
updateWidgetParams();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-04 15:47:36 +02:00
|
|
|
export class WidgetContext {
|
|
|
|
|
|
|
|
|
|
constructor(public dashboard: IDashboardComponent,
|
2020-01-22 20:05:30 +02:00
|
|
|
private dashboardWidget: IDashboardWidget,
|
2019-11-04 15:47:36 +02:00
|
|
|
private widget: Widget) {}
|
|
|
|
|
|
|
|
|
|
get stateController(): IStateController {
|
|
|
|
|
return this.dashboard.stateController;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get aliasController(): IAliasController {
|
|
|
|
|
return this.dashboard.aliasController;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get dashboardTimewindow(): Timewindow {
|
|
|
|
|
return this.dashboard.dashboardTimewindow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get widgetConfig(): WidgetConfig {
|
|
|
|
|
return this.widget.config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get settings(): any {
|
|
|
|
|
return this.widget.config.settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get units(): string {
|
|
|
|
|
return this.widget.config.units || '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get decimals(): number {
|
|
|
|
|
return isDefined(this.widget.config.decimals) ? this.widget.config.decimals : 2;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 20:05:30 +02:00
|
|
|
set changeDetector(cd: ChangeDetectorRef) {
|
2020-02-04 15:14:17 +02:00
|
|
|
this.changeDetectorValue = cd;
|
2020-01-22 20:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-26 13:49:30 +03:00
|
|
|
set containerChangeDetector(cd: ChangeDetectorRef) {
|
|
|
|
|
this.containerChangeDetectorValue = cd;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 14:58:21 +03:00
|
|
|
get currentUser(): AuthUser {
|
|
|
|
|
if (this.store) {
|
|
|
|
|
return getCurrentAuthUser(this.store);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 19:42:58 +03:00
|
|
|
deviceService: DeviceService;
|
|
|
|
|
assetService: AssetService;
|
|
|
|
|
entityViewService: EntityViewService;
|
|
|
|
|
customerService: CustomerService;
|
|
|
|
|
dashboardService: DashboardService;
|
|
|
|
|
userService: UserService;
|
|
|
|
|
attributeService: AttributeService;
|
|
|
|
|
entityRelationService: EntityRelationService;
|
|
|
|
|
entityService: EntityService;
|
|
|
|
|
dialogs: DialogService;
|
|
|
|
|
customDialog: CustomDialogService;
|
|
|
|
|
date: DatePipe;
|
|
|
|
|
translate: TranslateService;
|
|
|
|
|
http: HttpClient;
|
2020-08-06 19:05:46 +03:00
|
|
|
sanitizer: DomSanitizer;
|
2020-08-31 16:39:54 +03:00
|
|
|
router: Router;
|
2020-05-20 19:42:58 +03:00
|
|
|
|
2020-02-04 15:14:17 +02:00
|
|
|
private changeDetectorValue: ChangeDetectorRef;
|
2021-05-26 13:49:30 +03:00
|
|
|
private containerChangeDetectorValue: ChangeDetectorRef;
|
2020-02-03 19:38:28 +02:00
|
|
|
|
2019-11-04 15:47:36 +02:00
|
|
|
inited = false;
|
2020-01-24 19:05:41 +02:00
|
|
|
destroyed = false;
|
2019-11-04 15:47:36 +02:00
|
|
|
|
|
|
|
|
subscriptions: {[id: string]: IWidgetSubscription} = {};
|
|
|
|
|
defaultSubscription: IWidgetSubscription = null;
|
|
|
|
|
|
|
|
|
|
timewindowFunctions: TimewindowFunctions = {
|
|
|
|
|
onUpdateTimewindow: (startTimeMs, endTimeMs, interval) => {
|
|
|
|
|
if (this.defaultSubscription) {
|
|
|
|
|
this.defaultSubscription.onUpdateTimewindow(startTimeMs, endTimeMs, interval);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onResetTimewindow: () => {
|
|
|
|
|
if (this.defaultSubscription) {
|
|
|
|
|
this.defaultSubscription.onResetTimewindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
controlApi: RpcApi = {
|
2021-07-09 19:27:50 +03:00
|
|
|
sendOneWayCommand: (method, params, timeout, persistent, requestUUID) => {
|
2019-11-04 15:47:36 +02:00
|
|
|
if (this.defaultSubscription) {
|
2021-07-09 19:27:50 +03:00
|
|
|
return this.defaultSubscription.sendOneWayCommand(method, params, timeout, persistent, requestUUID);
|
2019-11-04 15:47:36 +02:00
|
|
|
} else {
|
|
|
|
|
return of(null);
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-09 19:27:50 +03:00
|
|
|
sendTwoWayCommand: (method, params, timeout, persistent, requestUUID) => {
|
2019-11-04 15:47:36 +02:00
|
|
|
if (this.defaultSubscription) {
|
2021-07-09 19:27:50 +03:00
|
|
|
return this.defaultSubscription.sendTwoWayCommand(method, params, timeout, persistent, requestUUID);
|
2019-11-04 15:47:36 +02:00
|
|
|
} else {
|
|
|
|
|
return of(null);
|
|
|
|
|
}
|
2021-08-05 19:13:16 +03:00
|
|
|
},
|
|
|
|
|
completedCommand: () => {
|
|
|
|
|
if (this.defaultSubscription) {
|
|
|
|
|
return this.defaultSubscription.completedCommand();
|
|
|
|
|
} else {
|
|
|
|
|
return of(null);
|
|
|
|
|
}
|
2019-11-04 15:47:36 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
utils: IWidgetUtils = {
|
|
|
|
|
formatValue
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-28 19:49:14 +02:00
|
|
|
$container: JQuery<HTMLElement>;
|
|
|
|
|
$containerParent: JQuery<HTMLElement>;
|
2019-11-04 15:47:36 +02:00
|
|
|
width: number;
|
|
|
|
|
height: number;
|
|
|
|
|
$scope: IDynamicWidgetComponent;
|
|
|
|
|
isEdit: boolean;
|
|
|
|
|
isMobile: boolean;
|
|
|
|
|
|
2020-02-10 13:04:56 +02:00
|
|
|
widgetNamespace?: string;
|
2019-09-05 21:15:40 +03:00
|
|
|
subscriptionApi?: WidgetSubscriptionApi;
|
2019-11-04 15:47:36 +02:00
|
|
|
|
2019-09-05 21:15:40 +03:00
|
|
|
actionsApi?: WidgetActionsApi;
|
2019-09-19 20:10:52 +03:00
|
|
|
activeEntityInfo?: SubscriptionEntityInfo;
|
2019-09-10 15:12:10 +03:00
|
|
|
|
|
|
|
|
datasources?: Array<Datasource>;
|
|
|
|
|
data?: Array<DatasourceData>;
|
|
|
|
|
hiddenData?: Array<{data: DataSet}>;
|
2019-09-12 19:58:42 +03:00
|
|
|
timeWindow?: WidgetTimewindow;
|
2019-10-24 19:52:19 +03:00
|
|
|
|
2019-11-04 15:47:36 +02:00
|
|
|
hideTitlePanel = false;
|
|
|
|
|
|
2019-10-24 19:52:19 +03:00
|
|
|
widgetTitle?: string;
|
2020-02-25 19:11:25 +02:00
|
|
|
widgetTitleTooltip?: string;
|
2019-10-24 19:52:19 +03:00
|
|
|
customHeaderActions?: Array<WidgetHeaderAction>;
|
|
|
|
|
widgetActions?: Array<WidgetAction>;
|
|
|
|
|
|
2019-10-25 17:50:12 +03:00
|
|
|
servicesMap?: Map<string, Type<any>>;
|
2020-01-22 20:05:30 +02:00
|
|
|
|
|
|
|
|
$injector?: Injector;
|
2020-02-03 17:29:01 +02:00
|
|
|
|
|
|
|
|
ngZone?: NgZone;
|
2020-02-04 15:14:17 +02:00
|
|
|
|
2020-02-28 19:49:14 +02:00
|
|
|
store?: Store<AppState>;
|
|
|
|
|
|
2020-02-27 17:06:32 +02:00
|
|
|
rxjs = {
|
|
|
|
|
forkJoin,
|
2021-05-04 19:44:15 +03:00
|
|
|
of,
|
|
|
|
|
map,
|
|
|
|
|
mergeMap
|
2020-02-27 17:06:32 +02:00
|
|
|
};
|
|
|
|
|
|
2020-02-28 19:49:14 +02:00
|
|
|
showSuccessToast(message: string, duration: number = 1000,
|
|
|
|
|
verticalPosition: NotificationVerticalPosition = 'bottom',
|
|
|
|
|
horizontalPosition: NotificationHorizontalPosition = 'left',
|
|
|
|
|
target?: string) {
|
|
|
|
|
this.showToast('success', message, duration, verticalPosition, horizontalPosition, target);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 17:02:41 +03:00
|
|
|
showInfoToast(message: string,
|
2020-08-14 13:08:17 +03:00
|
|
|
verticalPosition: NotificationVerticalPosition = 'bottom',
|
|
|
|
|
horizontalPosition: NotificationHorizontalPosition = 'left',
|
|
|
|
|
target?: string) {
|
2020-06-26 17:02:41 +03:00
|
|
|
this.showToast('info', message, undefined, verticalPosition, horizontalPosition, target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showWarnToast(message: string,
|
|
|
|
|
verticalPosition: NotificationVerticalPosition = 'bottom',
|
|
|
|
|
horizontalPosition: NotificationHorizontalPosition = 'left',
|
|
|
|
|
target?: string) {
|
|
|
|
|
this.showToast('warn', message, undefined, verticalPosition, horizontalPosition, target);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 19:49:14 +02:00
|
|
|
showErrorToast(message: string,
|
|
|
|
|
verticalPosition: NotificationVerticalPosition = 'bottom',
|
|
|
|
|
horizontalPosition: NotificationHorizontalPosition = 'left',
|
|
|
|
|
target?: string) {
|
|
|
|
|
this.showToast('error', message, undefined, verticalPosition, horizontalPosition, target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showToast(type: NotificationType, message: string, duration: number,
|
|
|
|
|
verticalPosition: NotificationVerticalPosition = 'bottom',
|
|
|
|
|
horizontalPosition: NotificationHorizontalPosition = 'left',
|
|
|
|
|
target?: string) {
|
|
|
|
|
this.store.dispatch(new ActionNotificationShow(
|
|
|
|
|
{
|
|
|
|
|
message,
|
|
|
|
|
type,
|
|
|
|
|
duration,
|
|
|
|
|
verticalPosition,
|
|
|
|
|
horizontalPosition,
|
|
|
|
|
target,
|
|
|
|
|
panelClass: this.widgetNamespace,
|
|
|
|
|
forceDismiss: true
|
|
|
|
|
}));
|
|
|
|
|
}
|
2020-06-26 17:02:41 +03:00
|
|
|
|
|
|
|
|
hideToast(target?: string) {
|
|
|
|
|
this.store.dispatch(new ActionNotificationHide(
|
|
|
|
|
{
|
|
|
|
|
target,
|
|
|
|
|
}));
|
|
|
|
|
}
|
2020-02-28 19:49:14 +02:00
|
|
|
|
2020-02-04 15:14:17 +02:00
|
|
|
detectChanges(updateWidgetParams: boolean = false) {
|
|
|
|
|
if (!this.destroyed) {
|
|
|
|
|
if (updateWidgetParams) {
|
|
|
|
|
this.dashboardWidget.updateWidgetParams();
|
|
|
|
|
}
|
2020-02-14 16:46:02 +02:00
|
|
|
try {
|
|
|
|
|
this.changeDetectorValue.detectChanges();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e);
|
|
|
|
|
}
|
2020-02-04 15:14:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-26 13:49:30 +03:00
|
|
|
detectContainerChanges() {
|
|
|
|
|
if (!this.destroyed) {
|
|
|
|
|
try {
|
|
|
|
|
this.containerChangeDetectorValue.detectChanges();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 15:14:17 +02:00
|
|
|
updateWidgetParams() {
|
|
|
|
|
if (!this.destroyed) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.dashboardWidget.updateWidgetParams();
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-27 17:06:32 +02:00
|
|
|
updateAliases(aliasIds?: Array<string>) {
|
|
|
|
|
this.aliasController.updateAliases(aliasIds);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 15:14:17 +02:00
|
|
|
reset() {
|
|
|
|
|
this.destroyed = false;
|
|
|
|
|
this.hideTitlePanel = false;
|
|
|
|
|
this.widgetTitle = undefined;
|
|
|
|
|
this.widgetActions = undefined;
|
|
|
|
|
}
|
2020-06-05 15:36:28 +03:00
|
|
|
|
|
|
|
|
pageLink(pageSize: number, page: number = 0, textSearch: string = null, sortOrder: SortOrder = null): PageLink {
|
|
|
|
|
return new PageLink(pageSize, page, textSearch, sortOrder);
|
2020-08-14 13:08:17 +03:00
|
|
|
}
|
2019-08-14 19:55:24 +03:00
|
|
|
}
|
2019-09-06 20:17:45 +03:00
|
|
|
|
|
|
|
|
export interface IDynamicWidgetComponent {
|
2020-01-22 20:05:30 +02:00
|
|
|
readonly ctx: WidgetContext;
|
|
|
|
|
readonly errorMessages: string[];
|
2020-02-13 18:38:11 +02:00
|
|
|
readonly $injector: Injector;
|
2019-09-10 15:12:10 +03:00
|
|
|
executingRpcRequest: boolean;
|
|
|
|
|
rpcEnabled: boolean;
|
|
|
|
|
rpcErrorText: string;
|
|
|
|
|
rpcRejection: HttpErrorResponse;
|
2019-09-12 19:58:42 +03:00
|
|
|
raf: RafService;
|
2019-09-06 20:17:45 +03:00
|
|
|
[key: string]: any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface WidgetInfo extends WidgetTypeDescriptor, WidgetControllerDescriptor {
|
|
|
|
|
widgetName: string;
|
|
|
|
|
alias: string;
|
2019-09-25 19:37:29 +03:00
|
|
|
typeSettingsSchema?: string | any;
|
|
|
|
|
typeDataKeySettingsSchema?: string | any;
|
2021-03-05 17:08:46 +02:00
|
|
|
image?: string;
|
|
|
|
|
description?: string;
|
2019-09-06 20:17:45 +03:00
|
|
|
componentFactory?: ComponentFactory<IDynamicWidgetComponent>;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
export interface WidgetConfigComponentData {
|
|
|
|
|
config: WidgetConfig;
|
|
|
|
|
layout: WidgetLayout;
|
2019-10-10 13:00:29 +03:00
|
|
|
widgetType: widgetType;
|
2019-10-21 19:57:18 +03:00
|
|
|
typeParameters: WidgetTypeParameters;
|
2019-10-24 19:52:19 +03:00
|
|
|
actionSources: {[actionSourceId: string]: WidgetActionSource};
|
2019-10-21 19:57:18 +03:00
|
|
|
isDataEnabled: boolean;
|
2020-02-24 17:16:02 +02:00
|
|
|
settingsSchema: JsonSettingsSchema;
|
|
|
|
|
dataKeySettingsSchema: JsonSettingsSchema;
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
|
2019-09-06 20:17:45 +03:00
|
|
|
export const MissingWidgetType: WidgetInfo = {
|
|
|
|
|
type: widgetType.latest,
|
|
|
|
|
widgetName: 'Widget type not found',
|
|
|
|
|
alias: 'undefined',
|
|
|
|
|
sizeX: 8,
|
|
|
|
|
sizeY: 6,
|
|
|
|
|
resources: [],
|
|
|
|
|
templateHtml: '<div class="tb-widget-error-container">' +
|
2019-09-20 20:30:43 +03:00
|
|
|
'<div class="tb-widget-error-msg" innerHTML="{{\'widget.widget-type-not-found\' | translate }}"></div>' +
|
2019-09-06 20:17:45 +03:00
|
|
|
'</div>',
|
|
|
|
|
templateCss: '',
|
|
|
|
|
controllerScript: 'self.onInit = function() {}',
|
|
|
|
|
settingsSchema: '{}\n',
|
|
|
|
|
dataKeySettingsSchema: '{}\n',
|
2021-02-04 19:00:28 +02:00
|
|
|
image: null,
|
|
|
|
|
description: null,
|
2019-09-06 20:17:45 +03:00
|
|
|
defaultConfig: '{\n' +
|
|
|
|
|
'"title": "Widget type not found",\n' +
|
|
|
|
|
'"datasources": [],\n' +
|
|
|
|
|
'"settings": {}\n' +
|
2019-09-10 15:12:10 +03:00
|
|
|
'}\n',
|
|
|
|
|
typeParameters: {}
|
2019-09-06 20:17:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const ErrorWidgetType: WidgetInfo = {
|
|
|
|
|
type: widgetType.latest,
|
|
|
|
|
widgetName: 'Error loading widget',
|
|
|
|
|
alias: 'error',
|
|
|
|
|
sizeX: 8,
|
|
|
|
|
sizeY: 6,
|
|
|
|
|
resources: [],
|
|
|
|
|
templateHtml: '<div class="tb-widget-error-container">' +
|
|
|
|
|
'<div translate class="tb-widget-error-msg">widget.widget-type-load-error</div>' +
|
|
|
|
|
'<div *ngFor="let error of errorMessages" class="tb-widget-error-msg">{{ error }}</div>' +
|
|
|
|
|
'</div>',
|
|
|
|
|
templateCss: '',
|
|
|
|
|
controllerScript: 'self.onInit = function() {}',
|
|
|
|
|
settingsSchema: '{}\n',
|
|
|
|
|
dataKeySettingsSchema: '{}\n',
|
2021-02-04 19:00:28 +02:00
|
|
|
image: null,
|
|
|
|
|
description: null,
|
2019-09-06 20:17:45 +03:00
|
|
|
defaultConfig: '{\n' +
|
|
|
|
|
'"title": "Widget failed to load",\n' +
|
|
|
|
|
'"datasources": [],\n' +
|
|
|
|
|
'"settings": {}\n' +
|
2019-09-10 15:12:10 +03:00
|
|
|
'}\n',
|
|
|
|
|
typeParameters: {}
|
2019-09-06 20:17:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export interface WidgetTypeInstance {
|
|
|
|
|
getSettingsSchema?: () => string;
|
|
|
|
|
getDataKeySettingsSchema?: () => string;
|
|
|
|
|
typeParameters?: () => WidgetTypeParameters;
|
|
|
|
|
useCustomDatasources?: () => boolean;
|
2019-10-24 19:52:19 +03:00
|
|
|
actionSources?: () => {[actionSourceId: string]: WidgetActionSource};
|
2019-09-06 20:17:45 +03:00
|
|
|
|
|
|
|
|
onInit?: () => void;
|
|
|
|
|
onDataUpdated?: () => void;
|
|
|
|
|
onResize?: () => void;
|
|
|
|
|
onEditModeChanged?: () => void;
|
|
|
|
|
onMobileModeChanged?: () => void;
|
|
|
|
|
onDestroy?: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 17:08:46 +02:00
|
|
|
export function detailsToWidgetInfo(widgetTypeDetailsEntity: WidgetTypeDetails): WidgetInfo {
|
|
|
|
|
const widgetInfo = toWidgetInfo(widgetTypeDetailsEntity);
|
|
|
|
|
widgetInfo.image = widgetTypeDetailsEntity.image;
|
|
|
|
|
widgetInfo.description = widgetTypeDetailsEntity.description;
|
|
|
|
|
return widgetInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 20:17:45 +03:00
|
|
|
export function toWidgetInfo(widgetTypeEntity: WidgetType): WidgetInfo {
|
|
|
|
|
return {
|
|
|
|
|
widgetName: widgetTypeEntity.name,
|
|
|
|
|
alias: widgetTypeEntity.alias,
|
|
|
|
|
type: widgetTypeEntity.descriptor.type,
|
|
|
|
|
sizeX: widgetTypeEntity.descriptor.sizeX,
|
|
|
|
|
sizeY: widgetTypeEntity.descriptor.sizeY,
|
|
|
|
|
resources: widgetTypeEntity.descriptor.resources,
|
|
|
|
|
templateHtml: widgetTypeEntity.descriptor.templateHtml,
|
|
|
|
|
templateCss: widgetTypeEntity.descriptor.templateCss,
|
|
|
|
|
controllerScript: widgetTypeEntity.descriptor.controllerScript,
|
|
|
|
|
settingsSchema: widgetTypeEntity.descriptor.settingsSchema,
|
|
|
|
|
dataKeySettingsSchema: widgetTypeEntity.descriptor.dataKeySettingsSchema,
|
|
|
|
|
defaultConfig: widgetTypeEntity.descriptor.defaultConfig
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 17:08:46 +02:00
|
|
|
export function toWidgetTypeDetails(widgetInfo: WidgetInfo, id: WidgetTypeId, tenantId: TenantId,
|
|
|
|
|
bundleAlias: string, createdTime: number): WidgetTypeDetails {
|
|
|
|
|
const widgetTypeEntity = toWidgetType(widgetInfo, id, tenantId, bundleAlias, createdTime);
|
|
|
|
|
const widgetTypeDetails: WidgetTypeDetails = {...widgetTypeEntity,
|
|
|
|
|
description: widgetInfo.description,
|
|
|
|
|
image: widgetInfo.image
|
|
|
|
|
};
|
|
|
|
|
return widgetTypeDetails;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 15:38:16 +02:00
|
|
|
export function toWidgetType(widgetInfo: WidgetInfo, id: WidgetTypeId, tenantId: TenantId,
|
|
|
|
|
bundleAlias: string, createdTime: number): WidgetType {
|
2019-09-23 20:35:31 +03:00
|
|
|
const descriptor: WidgetTypeDescriptor = {
|
|
|
|
|
type: widgetInfo.type,
|
|
|
|
|
sizeX: widgetInfo.sizeX,
|
|
|
|
|
sizeY: widgetInfo.sizeY,
|
|
|
|
|
resources: widgetInfo.resources,
|
|
|
|
|
templateHtml: widgetInfo.templateHtml,
|
|
|
|
|
templateCss: widgetInfo.templateCss,
|
|
|
|
|
controllerScript: widgetInfo.controllerScript,
|
|
|
|
|
settingsSchema: widgetInfo.settingsSchema,
|
|
|
|
|
dataKeySettingsSchema: widgetInfo.dataKeySettingsSchema,
|
|
|
|
|
defaultConfig: widgetInfo.defaultConfig
|
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
id,
|
|
|
|
|
tenantId,
|
2021-02-25 15:38:16 +02:00
|
|
|
createdTime,
|
2019-09-23 20:35:31 +03:00
|
|
|
bundleAlias,
|
|
|
|
|
alias: widgetInfo.alias,
|
|
|
|
|
name: widgetInfo.widgetName,
|
|
|
|
|
descriptor
|
|
|
|
|
};
|
|
|
|
|
}
|