2019-09-05 21:15:40 +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.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
import { EntityId } from '@app/shared/models/id/entity-id';
|
2019-09-10 15:12:10 +03:00
|
|
|
import {
|
|
|
|
|
WidgetActionDescriptor,
|
|
|
|
|
widgetType,
|
|
|
|
|
LegendConfig,
|
|
|
|
|
LegendData,
|
|
|
|
|
Datasource,
|
|
|
|
|
DatasourceData, DataSet, DatasourceType, KeyInfo
|
|
|
|
|
} from '@shared/models/widget.models';
|
2019-09-05 21:15:40 +03:00
|
|
|
import { TimeService } from '../services/time.service';
|
|
|
|
|
import { DeviceService } from '../http/device.service';
|
|
|
|
|
import { AlarmService } from '../http/alarm.service';
|
|
|
|
|
import { UtilsService } from '@core/services/utils.service';
|
2019-09-10 15:12:10 +03:00
|
|
|
import { Timewindow } from '@shared/models/time/time.models';
|
|
|
|
|
import { EntityType } from '@shared/models/entity-type.models';
|
|
|
|
|
import { AlarmSearchStatus } from '@shared/models/alarm.models';
|
|
|
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
|
|
|
import { DatasourceService } from '@core/api/datasource.service';
|
2019-09-05 21:15:40 +03:00
|
|
|
|
|
|
|
|
export interface TimewindowFunctions {
|
|
|
|
|
onUpdateTimewindow: (startTimeMs: number, endTimeMs: number, interval: number) => void;
|
|
|
|
|
onResetTimewindow: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface WidgetSubscriptionApi {
|
2019-09-10 15:12:10 +03:00
|
|
|
createSubscription: (options: WidgetSubscriptionOptions, subscribe?: boolean) => Observable<IWidgetSubscription>;
|
2019-09-05 21:15:40 +03:00
|
|
|
createSubscriptionFromInfo: (type: widgetType, subscriptionsInfo: Array<SubscriptionInfo>,
|
|
|
|
|
options: WidgetSubscriptionOptions, useDefaultComponents: boolean, subscribe: boolean)
|
|
|
|
|
=> Observable<IWidgetSubscription>;
|
|
|
|
|
removeSubscription: (id: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RpcApi {
|
|
|
|
|
sendOneWayCommand: (method: string, params?: any, timeout?: number) => Observable<any>;
|
|
|
|
|
sendTwoWayCommand: (method: string, params?: any, timeout?: number) => Observable<any>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IWidgetUtils {
|
|
|
|
|
formatValue: (value: any, dec?: number, units?: string, showZeroDecimals?: boolean) => string | undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface WidgetActionsApi {
|
|
|
|
|
actionDescriptorsBySourceId: {[sourceId: string]: Array<WidgetActionDescriptor>};
|
|
|
|
|
getActionDescriptors: (actionSourceId: string) => Array<WidgetActionDescriptor>;
|
|
|
|
|
handleWidgetAction: ($event: Event, descriptor: WidgetActionDescriptor,
|
|
|
|
|
entityId?: EntityId, entityName?: string, additionalParams?: any) => void;
|
|
|
|
|
elementClick: ($event: Event) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 15:12:10 +03:00
|
|
|
export interface AliasInfo {
|
|
|
|
|
stateEntity?: boolean;
|
|
|
|
|
currentEntity?: {
|
|
|
|
|
id: string;
|
|
|
|
|
entityType: EntityType;
|
|
|
|
|
name?: string;
|
|
|
|
|
};
|
|
|
|
|
[key: string]: any | null;
|
|
|
|
|
// TODO:
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 21:15:40 +03:00
|
|
|
export interface IAliasController {
|
2019-09-10 15:12:10 +03:00
|
|
|
entityAliasesChanged: Observable<Array<string>>;
|
|
|
|
|
getAliasInfo(aliasId): Observable<AliasInfo>;
|
|
|
|
|
resolveDatasources(datasources: Array<Datasource>): Observable<Array<Datasource>>;
|
2019-09-05 21:15:40 +03:00
|
|
|
[key: string]: any | null;
|
|
|
|
|
// TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface StateObject {
|
|
|
|
|
id?: string;
|
|
|
|
|
params?: StateParams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface StateParams {
|
|
|
|
|
entityName?: string;
|
|
|
|
|
targetEntityParamName?: string;
|
|
|
|
|
entityId?: EntityId;
|
|
|
|
|
[key: string]: any | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IStateController {
|
|
|
|
|
getStateParams: () => StateParams;
|
|
|
|
|
openState: (id: string, params?: StateParams, openRightLayout?: boolean) => void;
|
|
|
|
|
updateState: (id?: string, params?: StateParams, openRightLayout?: boolean) => void;
|
|
|
|
|
// TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface EntityInfo {
|
|
|
|
|
entityId: EntityId;
|
|
|
|
|
entityName: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SubscriptionInfo {
|
2019-09-10 15:12:10 +03:00
|
|
|
type: DatasourceType;
|
|
|
|
|
name?: string;
|
|
|
|
|
entityType?: EntityType;
|
|
|
|
|
entityId?: string;
|
|
|
|
|
entityIds?: Array<string>;
|
|
|
|
|
entityName?: string;
|
|
|
|
|
entityNamePrefix?: string;
|
|
|
|
|
timeseries?: Array<KeyInfo>;
|
|
|
|
|
attributes?: Array<KeyInfo>;
|
|
|
|
|
functions?: Array<KeyInfo>;
|
|
|
|
|
alarmFields?: Array<KeyInfo>;
|
2019-09-05 21:15:40 +03:00
|
|
|
[key: string]: any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface WidgetSubscriptionContext {
|
|
|
|
|
timeService: TimeService;
|
|
|
|
|
deviceService: DeviceService;
|
|
|
|
|
alarmService: AlarmService;
|
2019-09-10 15:12:10 +03:00
|
|
|
datasourceService: DatasourceService;
|
2019-09-05 21:15:40 +03:00
|
|
|
utils: UtilsService;
|
|
|
|
|
widgetUtils: IWidgetUtils;
|
|
|
|
|
dashboardTimewindowApi: TimewindowFunctions;
|
2019-09-10 15:12:10 +03:00
|
|
|
getServerTimeDiff: () => Observable<number>;
|
2019-09-05 21:15:40 +03:00
|
|
|
aliasController: IAliasController;
|
|
|
|
|
[key: string]: any;
|
|
|
|
|
// TODO:
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 15:12:10 +03:00
|
|
|
export interface WidgetSubscriptionCallbacks {
|
|
|
|
|
onDataUpdated?: (subscription: IWidgetSubscription) => void;
|
|
|
|
|
onDataUpdateError?: (subscription: IWidgetSubscription, e: any) => void;
|
|
|
|
|
dataLoading?: (subscription: IWidgetSubscription) => void;
|
|
|
|
|
legendDataUpdated?: (subscription: IWidgetSubscription) => void;
|
|
|
|
|
timeWindowUpdated?: (subscription: IWidgetSubscription, timeWindowConfig: Timewindow) => void;
|
|
|
|
|
rpcStateChanged?: (subscription: IWidgetSubscription) => void;
|
|
|
|
|
onRpcSuccess?: (subscription: IWidgetSubscription) => void;
|
|
|
|
|
onRpcFailed?: (subscription: IWidgetSubscription) => void;
|
|
|
|
|
onRpcErrorCleared?: (subscription: IWidgetSubscription) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 21:15:40 +03:00
|
|
|
export interface WidgetSubscriptionOptions {
|
2019-09-10 15:12:10 +03:00
|
|
|
type: widgetType;
|
|
|
|
|
stateData?: boolean;
|
|
|
|
|
alarmSource?: Datasource;
|
|
|
|
|
alarmSearchStatus?: AlarmSearchStatus;
|
|
|
|
|
alarmsPollingInterval?: number;
|
|
|
|
|
datasources?: Array<Datasource>;
|
|
|
|
|
targetDeviceAliasIds?: Array<string>;
|
|
|
|
|
targetDeviceIds?: Array<string>;
|
|
|
|
|
useDashboardTimewindow?: boolean;
|
|
|
|
|
displayTimewindow?: boolean;
|
|
|
|
|
timeWindowConfig?: Timewindow;
|
|
|
|
|
dashboardTimewindow?: Timewindow;
|
|
|
|
|
legendConfig?: LegendConfig;
|
|
|
|
|
decimals?: number;
|
|
|
|
|
units?: string;
|
|
|
|
|
callbacks?: WidgetSubscriptionCallbacks;
|
2019-09-05 21:15:40 +03:00
|
|
|
[key: string]: any;
|
|
|
|
|
// TODO:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IWidgetSubscription {
|
|
|
|
|
|
2019-09-10 15:12:10 +03:00
|
|
|
id: string;
|
|
|
|
|
init$: Observable<IWidgetSubscription>;
|
|
|
|
|
ctx: WidgetSubscriptionContext;
|
|
|
|
|
type: widgetType;
|
|
|
|
|
callbacks: WidgetSubscriptionCallbacks;
|
2019-09-05 21:15:40 +03:00
|
|
|
|
2019-09-10 15:12:10 +03:00
|
|
|
loadingData: boolean;
|
|
|
|
|
useDashboardTimewindow: boolean;
|
|
|
|
|
|
|
|
|
|
legendData: LegendData;
|
|
|
|
|
datasources?: Array<Datasource>;
|
|
|
|
|
data?: Array<DatasourceData>;
|
|
|
|
|
hiddenData?: Array<{data: DataSet}>;
|
|
|
|
|
timeWindow?: Timewindow;
|
|
|
|
|
|
|
|
|
|
alarmSource?: Datasource;
|
|
|
|
|
alarmSearchStatus?: AlarmSearchStatus;
|
|
|
|
|
alarmsPollingInterval?: number;
|
|
|
|
|
|
|
|
|
|
targetDeviceAliasIds?: Array<string>;
|
|
|
|
|
targetDeviceIds?: Array<string>;
|
|
|
|
|
|
|
|
|
|
rpcEnabled?: boolean;
|
|
|
|
|
executingRpcRequest?: boolean;
|
|
|
|
|
rpcErrorText?: string;
|
|
|
|
|
rpcRejection?: HttpErrorResponse;
|
|
|
|
|
|
|
|
|
|
getFirstEntityInfo(): EntityInfo;
|
|
|
|
|
|
|
|
|
|
onAliasesChanged(aliasIds: Array<string>): boolean;
|
|
|
|
|
|
|
|
|
|
onUpdateTimewindow(startTimeMs: number, endTimeMs: number, interval: number): void;
|
|
|
|
|
onResetTimewindow(): void;
|
|
|
|
|
updateTimewindowConfig(newTimewindow: Timewindow): void;
|
2019-09-05 21:15:40 +03:00
|
|
|
|
2019-09-10 15:12:10 +03:00
|
|
|
sendOneWayCommand(method: string, params?: any, timeout?: number): Observable<any>;
|
|
|
|
|
sendTwoWayCommand(method: string, params?: any, timeout?: number): Observable<any>;
|
|
|
|
|
clearRpcError(): void;
|
2019-09-05 21:15:40 +03:00
|
|
|
|
2019-09-10 15:12:10 +03:00
|
|
|
subscribe(): void;
|
2019-09-05 21:15:40 +03:00
|
|
|
|
|
|
|
|
destroy(): void;
|
|
|
|
|
|
|
|
|
|
[key: string]: any;
|
|
|
|
|
// TODO:
|
|
|
|
|
}
|