2019-08-14 19:55:24 +03:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2019 The Thingsboard Authors
|
|
|
|
|
///
|
|
|
|
|
/// 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 { ExceptionData } from '@shared/models/error.models';
|
|
|
|
|
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,
|
|
|
|
|
Datasource, DatasourceData,
|
2019-09-06 20:17:45 +03:00
|
|
|
WidgetActionDescriptor,
|
|
|
|
|
WidgetActionSource,
|
|
|
|
|
WidgetConfig,
|
|
|
|
|
WidgetConfigSettings,
|
|
|
|
|
WidgetControllerDescriptor,
|
|
|
|
|
WidgetType,
|
|
|
|
|
widgetType,
|
|
|
|
|
WidgetTypeDescriptor,
|
|
|
|
|
WidgetTypeParameters
|
|
|
|
|
} 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,
|
2019-09-19 20:10:52 +03:00
|
|
|
RpcApi, SubscriptionEntityInfo,
|
2019-09-06 20:17:45 +03:00
|
|
|
TimewindowFunctions,
|
2019-09-05 21:15:40 +03:00
|
|
|
WidgetActionsApi,
|
2019-09-06 20:17:45 +03:00
|
|
|
WidgetSubscriptionApi
|
2019-09-05 21:15:40 +03:00
|
|
|
} from '@core/api/widget-api.models';
|
2019-09-06 20:17:45 +03:00
|
|
|
import { ComponentFactory } from '@angular/core';
|
2019-09-10 15:12:10 +03:00
|
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
2019-09-12 19:58:42 +03:00
|
|
|
import { RafService } from '@core/services/raf.service';
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface WidgetContext {
|
2019-09-05 21:15:40 +03:00
|
|
|
inited?: boolean;
|
2019-09-10 15:17:38 +03:00
|
|
|
$container?: JQuery<any>;
|
|
|
|
|
$containerParent?: JQuery<any>;
|
2019-09-05 21:15:40 +03:00
|
|
|
width?: number;
|
|
|
|
|
height?: number;
|
|
|
|
|
$scope?: IDynamicWidgetComponent;
|
2019-09-03 19:31:16 +03:00
|
|
|
hideTitlePanel?: boolean;
|
2019-09-05 21:15:40 +03:00
|
|
|
isEdit?: boolean;
|
|
|
|
|
isMobile?: boolean;
|
|
|
|
|
dashboard?: IDashboardComponent;
|
|
|
|
|
widgetConfig?: WidgetConfig;
|
|
|
|
|
settings?: WidgetConfigSettings;
|
|
|
|
|
units?: string;
|
|
|
|
|
decimals?: number;
|
|
|
|
|
subscriptions?: {[id: string]: IWidgetSubscription};
|
|
|
|
|
defaultSubscription?: IWidgetSubscription;
|
|
|
|
|
dashboardTimewindow?: Timewindow;
|
|
|
|
|
timewindowFunctions?: TimewindowFunctions;
|
|
|
|
|
subscriptionApi?: WidgetSubscriptionApi;
|
|
|
|
|
controlApi?: RpcApi;
|
|
|
|
|
utils?: IWidgetUtils;
|
|
|
|
|
actionsApi?: WidgetActionsApi;
|
|
|
|
|
stateController?: IStateController;
|
|
|
|
|
aliasController?: IAliasController;
|
2019-09-19 20:10:52 +03:00
|
|
|
activeEntityInfo?: SubscriptionEntityInfo;
|
2019-09-05 21:15:40 +03:00
|
|
|
widgetTitleTemplate?: string;
|
2019-09-03 19:31:16 +03:00
|
|
|
widgetTitle?: string;
|
|
|
|
|
customHeaderActions?: Array<WidgetHeaderAction>;
|
|
|
|
|
widgetActions?: Array<WidgetAction>;
|
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-08-14 19:55:24 +03:00
|
|
|
}
|
2019-09-06 20:17:45 +03:00
|
|
|
|
|
|
|
|
export interface IDynamicWidgetComponent {
|
|
|
|
|
widgetContext: WidgetContext;
|
|
|
|
|
errorMessages: string[];
|
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;
|
|
|
|
|
typeSettingsSchema?: string;
|
|
|
|
|
typeDataKeySettingsSchema?: string;
|
|
|
|
|
componentFactory?: ComponentFactory<IDynamicWidgetComponent>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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',
|
|
|
|
|
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',
|
|
|
|
|
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;
|
|
|
|
|
actionSources?: () => {[key: string]: WidgetActionSource};
|
|
|
|
|
|
|
|
|
|
onInit?: () => void;
|
|
|
|
|
onDataUpdated?: () => void;
|
|
|
|
|
onResize?: () => void;
|
|
|
|
|
onEditModeChanged?: () => void;
|
|
|
|
|
onMobileModeChanged?: () => void;
|
|
|
|
|
onDestroy?: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|