2016-12-01 11:40:28 +02:00
|
|
|
/*
|
2017-01-09 23:11:09 +02:00
|
|
|
* Copyright © 2016-2017 The Thingsboard Authors
|
2016-12-01 11:40:28 +02: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.
|
|
|
|
|
*/
|
|
|
|
|
import jsonSchemaDefaults from 'json-schema-defaults';
|
|
|
|
|
import thingsboardTypes from '../common/types.constant';
|
|
|
|
|
import thingsboardUtils from '../common/utils.service';
|
2017-05-24 10:39:33 +03:00
|
|
|
import thingsboardEntityAliasSelect from './entity-alias-select.directive';
|
2016-12-01 11:40:28 +02:00
|
|
|
import thingsboardDatasource from './datasource.directive';
|
|
|
|
|
import thingsboardTimewindow from './timewindow.directive';
|
2017-03-03 18:09:14 +02:00
|
|
|
import thingsboardLegendConfig from './legend-config.directive';
|
2016-12-01 11:40:28 +02:00
|
|
|
import thingsboardJsonForm from "./json-form.directive";
|
2017-02-13 21:22:15 +02:00
|
|
|
import 'angular-ui-ace';
|
2016-12-01 11:40:28 +02:00
|
|
|
|
|
|
|
|
/* eslint-disable import/no-unresolved, import/default */
|
|
|
|
|
|
|
|
|
|
import widgetConfigTemplate from './widget-config.tpl.html';
|
|
|
|
|
|
|
|
|
|
/* eslint-enable import/no-unresolved, import/default */
|
|
|
|
|
|
|
|
|
|
/* eslint-disable angular/angularelement */
|
|
|
|
|
|
|
|
|
|
export default angular.module('thingsboard.directives.widgetConfig', [thingsboardTypes,
|
|
|
|
|
thingsboardUtils,
|
|
|
|
|
thingsboardJsonForm,
|
2017-05-24 10:39:33 +03:00
|
|
|
thingsboardEntityAliasSelect,
|
2016-12-01 11:40:28 +02:00
|
|
|
thingsboardDatasource,
|
2017-02-13 21:22:15 +02:00
|
|
|
thingsboardTimewindow,
|
2017-03-03 18:09:14 +02:00
|
|
|
thingsboardLegendConfig,
|
2017-02-13 21:22:15 +02:00
|
|
|
'ui.ace'])
|
2016-12-01 11:40:28 +02:00
|
|
|
.directive('tbWidgetConfig', WidgetConfig)
|
|
|
|
|
.name;
|
|
|
|
|
|
|
|
|
|
/*@ngInject*/
|
2017-06-14 13:43:18 +03:00
|
|
|
function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout, types, utils) {
|
2016-12-01 11:40:28 +02:00
|
|
|
|
|
|
|
|
var linker = function (scope, element, attrs, ngModelCtrl) {
|
|
|
|
|
|
|
|
|
|
var template = $templateCache.get(widgetConfigTemplate);
|
|
|
|
|
|
|
|
|
|
element.html(template);
|
|
|
|
|
|
|
|
|
|
scope.types = types;
|
|
|
|
|
scope.widgetEditMode = $rootScope.widgetEditMode;
|
|
|
|
|
|
|
|
|
|
scope.emptySettingsSchema = {
|
|
|
|
|
type: "object",
|
|
|
|
|
properties: {}
|
|
|
|
|
};
|
|
|
|
|
scope.defaultSettingsForm = [
|
|
|
|
|
'*'
|
|
|
|
|
];
|
|
|
|
|
|
2017-02-13 21:22:15 +02:00
|
|
|
scope.titleStyleEditorOptions = {
|
|
|
|
|
useWrapMode: true,
|
|
|
|
|
mode: 'json',
|
|
|
|
|
advanced: {
|
|
|
|
|
enableSnippets: true,
|
|
|
|
|
enableBasicAutocompletion: true,
|
|
|
|
|
enableLiveAutocompletion: true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
if (angular.isUndefined(scope.forceExpandDatasources)) {
|
|
|
|
|
scope.forceExpandDatasources = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 18:04:55 +03:00
|
|
|
if (angular.isUndefined(scope.isDataEnabled)) {
|
|
|
|
|
scope.isDataEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
scope.currentSettingsSchema = {};
|
|
|
|
|
scope.currentSettings = angular.copy(scope.emptySettingsSchema);
|
|
|
|
|
|
|
|
|
|
scope.targetDeviceAlias = {
|
|
|
|
|
value: null
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 13:43:18 +03:00
|
|
|
scope.alarmSource = {
|
|
|
|
|
value: null
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
ngModelCtrl.$render = function () {
|
|
|
|
|
if (ngModelCtrl.$viewValue) {
|
2017-05-24 10:39:33 +03:00
|
|
|
var config = ngModelCtrl.$viewValue.config;
|
|
|
|
|
var layout = ngModelCtrl.$viewValue.layout;
|
|
|
|
|
if (config) {
|
|
|
|
|
scope.selectedTab = 0;
|
|
|
|
|
scope.title = config.title;
|
|
|
|
|
scope.showTitle = config.showTitle;
|
|
|
|
|
scope.dropShadow = angular.isDefined(config.dropShadow) ? config.dropShadow : true;
|
|
|
|
|
scope.enableFullscreen = angular.isDefined(config.enableFullscreen) ? config.enableFullscreen : true;
|
|
|
|
|
scope.backgroundColor = config.backgroundColor;
|
|
|
|
|
scope.color = config.color;
|
|
|
|
|
scope.padding = config.padding;
|
|
|
|
|
scope.titleStyle =
|
|
|
|
|
angular.toJson(angular.isDefined(config.titleStyle) ? config.titleStyle : {
|
|
|
|
|
fontSize: '16px',
|
|
|
|
|
fontWeight: 400
|
|
|
|
|
}, true);
|
|
|
|
|
scope.units = config.units;
|
|
|
|
|
scope.decimals = config.decimals;
|
|
|
|
|
scope.useDashboardTimewindow = angular.isDefined(config.useDashboardTimewindow) ?
|
|
|
|
|
config.useDashboardTimewindow : true;
|
|
|
|
|
scope.timewindow = config.timewindow;
|
|
|
|
|
scope.showLegend = angular.isDefined(config.showLegend) ?
|
|
|
|
|
config.showLegend : scope.widgetType === types.widgetType.timeseries.value;
|
|
|
|
|
scope.legendConfig = config.legendConfig;
|
2017-06-14 13:43:18 +03:00
|
|
|
if (scope.widgetType !== types.widgetType.rpc.value &&
|
|
|
|
|
scope.widgetType !== types.widgetType.alarm.value &&
|
|
|
|
|
scope.widgetType !== types.widgetType.static.value
|
2017-05-24 10:39:33 +03:00
|
|
|
&& scope.isDataEnabled) {
|
|
|
|
|
if (scope.datasources) {
|
|
|
|
|
scope.datasources.splice(0, scope.datasources.length);
|
|
|
|
|
} else {
|
|
|
|
|
scope.datasources = [];
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
2017-05-24 10:39:33 +03:00
|
|
|
if (config.datasources) {
|
|
|
|
|
for (var i in config.datasources) {
|
|
|
|
|
scope.datasources.push({value: config.datasources[i]});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (scope.widgetType === types.widgetType.rpc.value && scope.isDataEnabled) {
|
|
|
|
|
if (config.targetDeviceAliasIds && config.targetDeviceAliasIds.length > 0) {
|
|
|
|
|
var aliasId = config.targetDeviceAliasIds[0];
|
2017-06-07 17:09:04 +03:00
|
|
|
var entityAliases = scope.aliasController.getEntityAliases();
|
|
|
|
|
if (entityAliases[aliasId]) {
|
|
|
|
|
scope.targetDeviceAlias.value = entityAliases[aliasId];
|
2017-05-24 10:39:33 +03:00
|
|
|
} else {
|
|
|
|
|
scope.targetDeviceAlias.value = null;
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
} else {
|
|
|
|
|
scope.targetDeviceAlias.value = null;
|
|
|
|
|
}
|
2017-06-14 13:43:18 +03:00
|
|
|
} else if (scope.widgetType === types.widgetType.alarm.value && scope.isDataEnabled) {
|
2017-06-14 20:23:13 +03:00
|
|
|
scope.alarmSearchStatus = angular.isDefined(config.alarmSearchStatus) ?
|
|
|
|
|
config.alarmSearchStatus : types.alarmSearchStatus.any;
|
|
|
|
|
scope.alarmsPollingInterval = angular.isDefined(config.alarmsPollingInterval) ?
|
|
|
|
|
config.alarmsPollingInterval : 5;
|
2017-06-14 13:43:18 +03:00
|
|
|
if (config.alarmSource) {
|
|
|
|
|
scope.alarmSource.value = config.alarmSource;
|
|
|
|
|
} else {
|
|
|
|
|
scope.alarmSource.value = null;
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-24 10:39:33 +03:00
|
|
|
scope.settings = config.settings;
|
2016-12-01 11:40:28 +02:00
|
|
|
|
2017-05-24 10:39:33 +03:00
|
|
|
scope.updateSchemaForm();
|
|
|
|
|
}
|
|
|
|
|
if (layout) {
|
|
|
|
|
scope.mobileOrder = layout.mobileOrder;
|
|
|
|
|
scope.mobileHeight = layout.mobileHeight;
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
scope.displayAdvanced = function() {
|
|
|
|
|
return scope.widgetSettingsSchema && scope.widgetSettingsSchema.schema;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scope.updateSchemaForm = function() {
|
|
|
|
|
if (scope.widgetSettingsSchema && scope.widgetSettingsSchema.schema) {
|
|
|
|
|
scope.currentSettingsSchema = scope.widgetSettingsSchema.schema;
|
|
|
|
|
scope.currentSettingsForm = scope.widgetSettingsSchema.form || angular.copy(scope.defaultSettingsForm);
|
|
|
|
|
scope.currentSettings = scope.settings;
|
|
|
|
|
} else {
|
|
|
|
|
scope.currentSettingsForm = angular.copy(scope.defaultSettingsForm);
|
|
|
|
|
scope.currentSettingsSchema = angular.copy(scope.emptySettingsSchema);
|
|
|
|
|
scope.currentSettings = {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scope.updateValidity = function () {
|
|
|
|
|
if (ngModelCtrl.$viewValue) {
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-05-24 10:39:33 +03:00
|
|
|
var config = value.config;
|
|
|
|
|
if (config) {
|
|
|
|
|
var valid;
|
|
|
|
|
if (scope.widgetType === types.widgetType.rpc.value && scope.isDataEnabled) {
|
|
|
|
|
valid = config && config.targetDeviceAliasIds && config.targetDeviceAliasIds.length > 0;
|
|
|
|
|
ngModelCtrl.$setValidity('targetDeviceAliasIds', valid);
|
2017-06-14 13:43:18 +03:00
|
|
|
} else if (scope.widgetType === types.widgetType.alarm.value && scope.isDataEnabled) {
|
|
|
|
|
valid = config && config.alarmSource;
|
|
|
|
|
ngModelCtrl.$setValidity('alarmSource', valid);
|
2017-05-24 10:39:33 +03:00
|
|
|
} else if (scope.widgetType !== types.widgetType.static.value && scope.isDataEnabled) {
|
|
|
|
|
valid = config && config.datasources && config.datasources.length > 0;
|
|
|
|
|
ngModelCtrl.$setValidity('datasources', valid);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
angular.fromJson(scope.titleStyle);
|
|
|
|
|
ngModelCtrl.$setValidity('titleStyle', true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
ngModelCtrl.$setValidity('titleStyle', false);
|
|
|
|
|
}
|
2017-02-13 21:22:15 +02:00
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-01 20:02:01 +02:00
|
|
|
scope.$watch('title + showTitle + dropShadow + enableFullscreen + backgroundColor + color + ' +
|
2017-06-14 20:23:13 +03:00
|
|
|
'padding + titleStyle + mobileOrder + mobileHeight + units + decimals + useDashboardTimewindow + ' +
|
|
|
|
|
'alarmSearchStatus + alarmsPollingInterval + showLegend', function () {
|
2016-12-01 11:40:28 +02:00
|
|
|
if (ngModelCtrl.$viewValue) {
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-05-24 10:39:33 +03:00
|
|
|
if (value.config) {
|
|
|
|
|
var config = value.config;
|
|
|
|
|
config.title = scope.title;
|
|
|
|
|
config.showTitle = scope.showTitle;
|
|
|
|
|
config.dropShadow = scope.dropShadow;
|
|
|
|
|
config.enableFullscreen = scope.enableFullscreen;
|
|
|
|
|
config.backgroundColor = scope.backgroundColor;
|
|
|
|
|
config.color = scope.color;
|
|
|
|
|
config.padding = scope.padding;
|
|
|
|
|
try {
|
|
|
|
|
config.titleStyle = angular.fromJson(scope.titleStyle);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
config.titleStyle = {};
|
|
|
|
|
}
|
|
|
|
|
config.units = scope.units;
|
|
|
|
|
config.decimals = scope.decimals;
|
|
|
|
|
config.useDashboardTimewindow = scope.useDashboardTimewindow;
|
2017-06-14 20:23:13 +03:00
|
|
|
config.alarmSearchStatus = scope.alarmSearchStatus;
|
|
|
|
|
config.alarmsPollingInterval = scope.alarmsPollingInterval;
|
2017-05-24 10:39:33 +03:00
|
|
|
config.showLegend = scope.showLegend;
|
|
|
|
|
}
|
|
|
|
|
if (value.layout) {
|
|
|
|
|
var layout = value.layout;
|
|
|
|
|
layout.mobileOrder = angular.isNumber(scope.mobileOrder) ? scope.mobileOrder : undefined;
|
|
|
|
|
layout.mobileHeight = scope.mobileHeight;
|
2017-02-13 21:22:15 +02:00
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
ngModelCtrl.$setViewValue(value);
|
2017-02-13 21:22:15 +02:00
|
|
|
scope.updateValidity();
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
scope.$watch('currentSettings', function () {
|
|
|
|
|
if (ngModelCtrl.$viewValue) {
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-05-24 10:39:33 +03:00
|
|
|
if (value.config) {
|
|
|
|
|
value.config.settings = scope.currentSettings;
|
|
|
|
|
ngModelCtrl.$setViewValue(value);
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
scope.$watch('timewindow', function () {
|
|
|
|
|
if (ngModelCtrl.$viewValue) {
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-05-24 10:39:33 +03:00
|
|
|
if (value.config) {
|
|
|
|
|
value.config.timewindow = scope.timewindow;
|
|
|
|
|
ngModelCtrl.$setViewValue(value);
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
|
2017-03-03 18:09:14 +02:00
|
|
|
scope.$watch('legendConfig', function () {
|
|
|
|
|
if (ngModelCtrl.$viewValue) {
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-05-24 10:39:33 +03:00
|
|
|
if (value.config) {
|
|
|
|
|
value.config.legendConfig = scope.legendConfig;
|
|
|
|
|
ngModelCtrl.$setViewValue(value);
|
|
|
|
|
}
|
2017-03-03 18:09:14 +02:00
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
scope.$watch('datasources', function () {
|
2017-06-14 13:43:18 +03:00
|
|
|
if (ngModelCtrl.$viewValue && ngModelCtrl.$viewValue.config
|
|
|
|
|
&& scope.widgetType !== types.widgetType.rpc.value
|
|
|
|
|
&& scope.widgetType !== types.widgetType.alarm.value
|
2017-04-23 18:04:55 +03:00
|
|
|
&& scope.widgetType !== types.widgetType.static.value && scope.isDataEnabled) {
|
2016-12-01 11:40:28 +02:00
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-05-24 10:39:33 +03:00
|
|
|
var config = value.config;
|
|
|
|
|
if (config.datasources) {
|
|
|
|
|
config.datasources.splice(0, config.datasources.length);
|
2016-12-01 11:40:28 +02:00
|
|
|
} else {
|
2017-05-24 10:39:33 +03:00
|
|
|
config.datasources = [];
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
if (scope.datasources) {
|
|
|
|
|
for (var i in scope.datasources) {
|
2017-05-24 10:39:33 +03:00
|
|
|
config.datasources.push(scope.datasources[i].value);
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ngModelCtrl.$setViewValue(value);
|
|
|
|
|
scope.updateValidity();
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
scope.$watch('targetDeviceAlias.value', function () {
|
2017-05-24 10:39:33 +03:00
|
|
|
if (ngModelCtrl.$viewValue && ngModelCtrl.$viewValue.config && scope.widgetType === types.widgetType.rpc.value && scope.isDataEnabled) {
|
2016-12-01 11:40:28 +02:00
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-05-24 10:39:33 +03:00
|
|
|
var config = value.config;
|
2016-12-01 11:40:28 +02:00
|
|
|
if (scope.targetDeviceAlias.value) {
|
2017-05-24 10:39:33 +03:00
|
|
|
config.targetDeviceAliasIds = [scope.targetDeviceAlias.value.id];
|
2016-12-01 11:40:28 +02:00
|
|
|
} else {
|
2017-05-24 10:39:33 +03:00
|
|
|
config.targetDeviceAliasIds = [];
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
ngModelCtrl.$setViewValue(value);
|
|
|
|
|
scope.updateValidity();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-14 13:43:18 +03:00
|
|
|
scope.$watch('alarmSource.value', function () {
|
|
|
|
|
if (ngModelCtrl.$viewValue && ngModelCtrl.$viewValue.config && scope.widgetType === types.widgetType.alarm.value && scope.isDataEnabled) {
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
|
|
|
|
var config = value.config;
|
|
|
|
|
if (scope.alarmSource.value) {
|
|
|
|
|
config.alarmSource = scope.alarmSource.value;
|
|
|
|
|
} else {
|
|
|
|
|
config.alarmSource = null;
|
|
|
|
|
}
|
|
|
|
|
ngModelCtrl.$setViewValue(value);
|
|
|
|
|
scope.updateValidity();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
scope.addDatasource = function () {
|
|
|
|
|
var newDatasource;
|
|
|
|
|
if (scope.functionsOnly) {
|
|
|
|
|
newDatasource = angular.copy(utils.getDefaultDatasource(scope.datakeySettingsSchema.schema));
|
|
|
|
|
newDatasource.dataKeys = [scope.generateDataKey('Sin', types.dataKeyType.function)];
|
|
|
|
|
} else {
|
2017-05-24 10:39:33 +03:00
|
|
|
newDatasource = { type: types.datasourceType.entity,
|
2016-12-01 11:40:28 +02:00
|
|
|
dataKeys: []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
var datasource = {value: newDatasource};
|
|
|
|
|
scope.datasources.push(datasource);
|
|
|
|
|
if (scope.theForm) {
|
|
|
|
|
scope.theForm.$setDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scope.removeDatasource = function ($event, datasource) {
|
|
|
|
|
var index = scope.datasources.indexOf(datasource);
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
scope.datasources.splice(index, 1);
|
|
|
|
|
if (scope.theForm) {
|
|
|
|
|
scope.theForm.$setDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
scope.generateDataKey = function (chip, type) {
|
|
|
|
|
|
|
|
|
|
if (angular.isObject(chip)) {
|
|
|
|
|
chip._hash = Math.random();
|
|
|
|
|
return chip;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 13:43:18 +03:00
|
|
|
var label = chip;
|
|
|
|
|
if (type === types.dataKeyType.alarm) {
|
|
|
|
|
var alarmField = types.alarmFields[chip];
|
|
|
|
|
if (alarmField) {
|
|
|
|
|
label = $translate.instant(alarmField.name)+'';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
label = scope.genNextLabel(label);
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
var result = {
|
|
|
|
|
name: chip,
|
|
|
|
|
type: type,
|
2017-06-14 13:43:18 +03:00
|
|
|
label: label,
|
2016-12-01 11:40:28 +02:00
|
|
|
color: scope.genNextColor(),
|
|
|
|
|
settings: {},
|
|
|
|
|
_hash: Math.random()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (type === types.dataKeyType.function) {
|
|
|
|
|
result.name = 'f(x)';
|
|
|
|
|
result.funcBody = utils.getPredefinedFunctionBody(chip);
|
|
|
|
|
if (!result.funcBody) {
|
|
|
|
|
result.funcBody = "return prevValue + 1;";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (angular.isDefined(scope.datakeySettingsSchema.schema)) {
|
|
|
|
|
result.settings = jsonSchemaDefaults(scope.datakeySettingsSchema.schema);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
scope.genNextLabel = function (name) {
|
|
|
|
|
var label = name;
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
|
|
|
|
var i = 1;
|
|
|
|
|
var matches = false;
|
|
|
|
|
do {
|
|
|
|
|
matches = false;
|
2017-06-14 13:43:18 +03:00
|
|
|
var datasources = scope.widgetType == types.widgetType.alarm.value ? [value.config.alarmSource] : value.config.datasources;
|
|
|
|
|
if (datasources) {
|
|
|
|
|
for (var d=0;d<datasources.length;d++) {
|
|
|
|
|
var datasource = datasources[d];
|
|
|
|
|
if (datasource && datasource.dataKeys) {
|
|
|
|
|
for (var k = 0; k < datasource.dataKeys.length; k++) {
|
|
|
|
|
var dataKey = datasource.dataKeys[k];
|
|
|
|
|
if (dataKey.label === label) {
|
|
|
|
|
i++;
|
|
|
|
|
label = name + ' ' + i;
|
|
|
|
|
matches = true;
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (matches);
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scope.genNextColor = function () {
|
|
|
|
|
var i = 0;
|
|
|
|
|
var value = ngModelCtrl.$viewValue;
|
2017-06-14 13:43:18 +03:00
|
|
|
var datasources = scope.widgetType == types.widgetType.alarm.value ? [value.config.alarmSource] : value.config.datasources;
|
|
|
|
|
if (datasources) {
|
|
|
|
|
for (var d=0;d<datasources.length;d++) {
|
|
|
|
|
var datasource = datasources[d];
|
|
|
|
|
if (datasource && datasource.dataKeys) {
|
|
|
|
|
i += datasource.dataKeys.length;
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return utils.getMaterialColor(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$compile(element.contents())(scope);
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
restrict: "E",
|
|
|
|
|
require: "^ngModel",
|
|
|
|
|
scope: {
|
|
|
|
|
forceExpandDatasources: '=?',
|
2017-04-23 18:04:55 +03:00
|
|
|
isDataEnabled: '=?',
|
2016-12-01 11:40:28 +02:00
|
|
|
widgetType: '=',
|
2017-06-19 19:22:48 +03:00
|
|
|
typeParameters: '=',
|
2016-12-01 11:40:28 +02:00
|
|
|
widgetSettingsSchema: '=',
|
|
|
|
|
datakeySettingsSchema: '=',
|
2017-06-07 17:09:04 +03:00
|
|
|
aliasController: '=',
|
2016-12-01 11:40:28 +02:00
|
|
|
functionsOnly: '=',
|
2017-05-24 10:39:33 +03:00
|
|
|
fetchEntityKeys: '&',
|
|
|
|
|
onCreateEntityAlias: '&',
|
2016-12-01 11:40:28 +02:00
|
|
|
theForm: '='
|
|
|
|
|
},
|
|
|
|
|
link: linker
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* eslint-enable angular/angularelement */
|