2024-01-30 12:30:24 +02:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2024 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 { AttributeScope } from '@shared/models/telemetry/telemetry.models';
|
2024-02-01 19:16:37 +02:00
|
|
|
import { widgetType } from '@shared/models/widget.models';
|
2024-11-21 17:22:07 +02:00
|
|
|
import { AlarmSeverity } from '@shared/models/alarm.models';
|
2024-01-30 12:30:24 +02:00
|
|
|
|
|
|
|
|
export enum GetValueAction {
|
|
|
|
|
DO_NOTHING = 'DO_NOTHING',
|
|
|
|
|
EXECUTE_RPC = 'EXECUTE_RPC',
|
|
|
|
|
GET_ATTRIBUTE = 'GET_ATTRIBUTE',
|
2024-02-29 17:54:52 +02:00
|
|
|
GET_TIME_SERIES = 'GET_TIME_SERIES',
|
2024-11-21 17:22:07 +02:00
|
|
|
GET_ALARM_STATUS = 'GET_ALARM_STATUS',
|
2024-02-29 17:54:52 +02:00
|
|
|
GET_DASHBOARD_STATE = 'GET_DASHBOARD_STATE'
|
2024-01-30 12:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getValueActions = Object.keys(GetValueAction) as GetValueAction[];
|
|
|
|
|
|
2024-02-01 19:16:37 +02:00
|
|
|
export const getValueActionsByWidgetType = (type: widgetType): GetValueAction[] => {
|
|
|
|
|
if (type !== widgetType.rpc) {
|
|
|
|
|
return getValueActions.filter(action => action !== GetValueAction.EXECUTE_RPC);
|
|
|
|
|
} else {
|
|
|
|
|
return getValueActions;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-30 12:30:24 +02:00
|
|
|
export const getValueActionTranslations = new Map<GetValueAction, string>(
|
|
|
|
|
[
|
|
|
|
|
[GetValueAction.DO_NOTHING, 'widgets.value-action.do-nothing'],
|
|
|
|
|
[GetValueAction.EXECUTE_RPC, 'widgets.value-action.execute-rpc'],
|
|
|
|
|
[GetValueAction.GET_ATTRIBUTE, 'widgets.value-action.get-attribute'],
|
2024-02-29 17:54:52 +02:00
|
|
|
[GetValueAction.GET_TIME_SERIES, 'widgets.value-action.get-time-series'],
|
2024-11-21 17:22:07 +02:00
|
|
|
[GetValueAction.GET_ALARM_STATUS, 'widgets.value-action.get-alarm-status'],
|
2024-02-29 17:54:52 +02:00
|
|
|
[GetValueAction.GET_DASHBOARD_STATE, 'widgets.value-action.get-dashboard-state']
|
2024-01-30 12:30:24 +02:00
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export interface RpcSettings {
|
|
|
|
|
method: string;
|
|
|
|
|
requestTimeout: number;
|
|
|
|
|
requestPersistent: boolean;
|
|
|
|
|
persistentPollingInterval: number;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 17:22:07 +02:00
|
|
|
export interface AlarmStatusSettings {
|
|
|
|
|
severityList: Array<AlarmSeverity>;
|
|
|
|
|
typeList: Array<string>;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 12:30:24 +02:00
|
|
|
export interface TelemetryValueSettings {
|
|
|
|
|
key: string;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-02 13:53:41 +02:00
|
|
|
export interface GetAttributeValueSettings extends TelemetryValueSettings {
|
2024-01-30 12:30:24 +02:00
|
|
|
scope: AttributeScope | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SetAttributeValueSettings extends TelemetryValueSettings {
|
|
|
|
|
scope: AttributeScope.SERVER_SCOPE | AttributeScope.SHARED_SCOPE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum DataToValueType {
|
|
|
|
|
NONE = 'NONE',
|
|
|
|
|
FUNCTION = 'FUNCTION'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DataToValueSettings {
|
|
|
|
|
type: DataToValueType;
|
|
|
|
|
dataToValueFunction: string;
|
|
|
|
|
compareToValue?: any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ValueActionSettings {
|
|
|
|
|
actionLabel?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface GetValueSettings<V> extends ValueActionSettings {
|
|
|
|
|
action: GetValueAction;
|
|
|
|
|
defaultValue: V;
|
2024-02-01 19:16:37 +02:00
|
|
|
executeRpc?: RpcSettings;
|
2024-01-30 12:30:24 +02:00
|
|
|
getAttribute: GetAttributeValueSettings;
|
2024-02-02 13:53:41 +02:00
|
|
|
getTimeSeries: TelemetryValueSettings;
|
2024-11-21 17:22:07 +02:00
|
|
|
getAlarmStatus: AlarmStatusSettings;
|
2024-01-30 12:30:24 +02:00
|
|
|
dataToValue: DataToValueSettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum SetValueAction {
|
|
|
|
|
EXECUTE_RPC = 'EXECUTE_RPC',
|
|
|
|
|
SET_ATTRIBUTE = 'SET_ATTRIBUTE',
|
|
|
|
|
ADD_TIME_SERIES = 'ADD_TIME_SERIES'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setValueActions = Object.keys(SetValueAction) as SetValueAction[];
|
|
|
|
|
|
2024-02-01 19:16:37 +02:00
|
|
|
export const setValueActionsByWidgetType = (type: widgetType): SetValueAction[] => {
|
|
|
|
|
if (type !== widgetType.rpc) {
|
|
|
|
|
return setValueActions.filter(action => action !== SetValueAction.EXECUTE_RPC);
|
|
|
|
|
} else {
|
|
|
|
|
return setValueActions;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-30 12:30:24 +02:00
|
|
|
export const setValueActionTranslations = new Map<SetValueAction, string>(
|
|
|
|
|
[
|
|
|
|
|
[SetValueAction.EXECUTE_RPC, 'widgets.value-action.execute-rpc'],
|
|
|
|
|
[SetValueAction.SET_ATTRIBUTE, 'widgets.value-action.set-attribute'],
|
|
|
|
|
[SetValueAction.ADD_TIME_SERIES, 'widgets.value-action.add-time-series']
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export enum ValueToDataType {
|
2024-02-14 18:42:29 +02:00
|
|
|
VALUE = 'VALUE',
|
2024-01-30 12:30:24 +02:00
|
|
|
CONSTANT = 'CONSTANT',
|
|
|
|
|
FUNCTION = 'FUNCTION',
|
|
|
|
|
NONE = 'NONE'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ValueToDataSettings {
|
|
|
|
|
type: ValueToDataType;
|
|
|
|
|
constantValue: any;
|
|
|
|
|
valueToDataFunction: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SetValueSettings extends ValueActionSettings {
|
|
|
|
|
action: SetValueAction;
|
|
|
|
|
executeRpc: RpcSettings;
|
|
|
|
|
setAttribute: SetAttributeValueSettings;
|
|
|
|
|
putTimeSeries: TelemetryValueSettings;
|
|
|
|
|
valueToData: ValueToDataSettings;
|
|
|
|
|
}
|