From 2fdb372c893c842afdc5884d14a20a6e120b9d13 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 22 Jun 2017 17:40:26 +0300 Subject: [PATCH] TB-64: Implement widget actions. --- ui/src/app/api/subscription.js | 43 ++++++ ui/src/app/api/widget.service.js | 2 +- ui/src/app/common/types.constant.js | 3 +- ui/src/app/common/utils.service.js | 23 +++- .../dashboard-autocomplete.directive.js | 24 +++- ui/src/app/components/dashboard.directive.js | 10 ++ ui/src/app/components/dashboard.tpl.html | 10 ++ .../material-icon-select.directive.js | 2 + .../app/components/material-icon-select.scss | 27 ++++ .../components/material-icon-select.tpl.html | 8 +- .../action/manage-widget-actions.directive.js | 41 ++++-- .../action/widget-action-dialog.controller.js | 127 +++++++++++++++++- .../action/widget-action-dialog.tpl.html | 56 +++++++- .../widget/widget-config.directive.js | 1 + .../components/widget/widget-config.tpl.html | 5 +- .../components/widget/widget.controller.js | 120 ++++++++++++++++- ui/src/app/dashboard/add-widget.controller.js | 21 +++ ui/src/app/dashboard/add-widget.tpl.html | 1 + ui/src/app/dashboard/edit-widget.directive.js | 20 +++ ui/src/app/dashboard/edit-widget.tpl.html | 1 + .../states/default-state-controller.js | 15 +-- .../states/entity-state-controller.js | 16 +-- ...d-widget-to-dashboard-dialog.controller.js | 1 + ui/src/app/locale/locale.constant.js | 14 +- ui/src/app/widget/lib/alarms-table-widget.js | 19 +-- .../app/widget/lib/entities-table-widget.js | 60 ++++++--- .../widget/lib/entities-table-widget.tpl.html | 20 +-- 27 files changed, 595 insertions(+), 95 deletions(-) create mode 100644 ui/src/app/components/material-icon-select.scss diff --git a/ui/src/app/api/subscription.js b/ui/src/app/api/subscription.js index 215da0f5ad..dd93626ed9 100644 --- a/ui/src/app/api/subscription.js +++ b/ui/src/app/api/subscription.js @@ -171,6 +171,48 @@ export default class Subscription { return deferred.promise; } + getFirstEntityInfo() { + var entityId; + var entityName; + if (this.type === this.ctx.types.widgetType.rpc.value) { + if (this.targetDeviceId) { + entityId = { + entityType: this.ctx.entityType.device, + id: this.targetDeviceId + } + entityName = this.targetDeviceName; + } + } else if (this.type == this.ctx.types.widgetType.alarm.value) { + if (this.alarmSource && this.alarmSource.entityType && this.alarmSource.entityId) { + entityId = { + entityType: this.alarmSource.entityType, + id: this.alarmSource.entityId + } + entityName = this.alarmSource.entityName; + } + } else { + for (var i=0;i 0) { scope.dashboard = dashboards[0]; + scope.updateView(); } }, function fail() { }); diff --git a/ui/src/app/components/dashboard.directive.js b/ui/src/app/components/dashboard.directive.js index e61abcc644..1a4cdba4e4 100644 --- a/ui/src/app/components/dashboard.directive.js +++ b/ui/src/app/components/dashboard.directive.js @@ -187,6 +187,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ vm.showWidgetActions = showWidgetActions; vm.widgetTitleStyle = widgetTitleStyle; vm.widgetTitle = widgetTitle; + vm.customWidgetHeaderActions = customWidgetHeaderActions; vm.widgetActions = widgetActions; vm.dropWidgetShadow = dropWidgetShadow; vm.enableWidgetFullscreen = enableWidgetFullscreen; @@ -875,6 +876,15 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ } } + function customWidgetHeaderActions(widget) { + var ctx = widgetContext(widget); + if (ctx && ctx.customHeaderActions && ctx.customHeaderActions.length) { + return ctx.customHeaderActions; + } else { + return []; + } + } + function widgetActions(widget) { var ctx = widgetContext(widget); if (ctx && ctx.widgetActions && ctx.widgetActions.length) { diff --git a/ui/src/app/components/dashboard.tpl.html b/ui/src/app/components/dashboard.tpl.html index aea3dfcf32..5d46fea5ca 100644 --- a/ui/src/app/components/dashboard.tpl.html +++ b/ui/src/app/components/dashboard.tpl.html @@ -52,6 +52,16 @@
+ + + {{action.displayName}} + + + -
+
{{icon}} - - - - + +
\ No newline at end of file diff --git a/ui/src/app/components/widget/action/manage-widget-actions.directive.js b/ui/src/app/components/widget/action/manage-widget-actions.directive.js index b2737296a8..93ca06fdd1 100644 --- a/ui/src/app/components/widget/action/manage-widget-actions.directive.js +++ b/ui/src/app/components/widget/action/manage-widget-actions.directive.js @@ -42,7 +42,8 @@ function ManageWidgetActions() { scope: true, bindToController: { actionSources: '=', - widgetActions: '=' + widgetActions: '=', + fetchDashboardStates: '&', }, controller: ManageWidgetActionsController, controllerAs: 'vm', @@ -55,7 +56,7 @@ function ManageWidgetActions() { /*@ngInject*/ function ManageWidgetActionsController($rootScope, $scope, $document, $mdDialog, $q, $filter, - $translate, $timeout, types) { + $translate, $timeout, utils, types) { let vm = this; @@ -165,12 +166,30 @@ function ManageWidgetActionsController($rootScope, $scope, $document, $mdDialog, if (!isAdd) { prevActionId = action.id; } + var availableActionSources = {}; + for (var id in vm.actionSources) { + var actionSource = vm.actionSources[id]; + if (actionSource.multiple) { + availableActionSources[id] = actionSource; + } else { + if (!isAdd && action.actionSourceId == id) { + availableActionSources[id] = actionSource; + } else { + var result = $filter('filter')(vm.allActions, {actionSourceId: id}); + if (!result || !result.length) { + availableActionSources[id] = actionSource; + } + } + } + } $mdDialog.show({ controller: 'WidgetActionDialogController', controllerAs: 'vm', templateUrl: widgetActionDialogTemplate, parent: angular.element($document[0].body), - locals: {isAdd: isAdd, actionSources: vm.actionSources, action: angular.copy(action)}, + locals: {isAdd: isAdd, fetchDashboardStates: vm.fetchDashboardStates, + actionSources: availableActionSources, widgetActions: vm.widgetActions, + action: angular.copy(action)}, skipHide: true, fullscreen: true, targetEvent: $event @@ -189,7 +208,8 @@ function ManageWidgetActionsController($rootScope, $scope, $document, $mdDialog, } function saveAction(action, prevActionId) { - action.actionSourceName = vm.actionSources[action.actionSourceId].name; + var actionSourceName = vm.actionSources[action.actionSourceId].name; + action.actionSourceName = utils.customTranslation(actionSourceName, actionSourceName); action.typeName = $translate.instant(types.widgetActionTypes[action.type].name); var actionSourceId = action.actionSourceId; var widgetAction = angular.copy(action); @@ -227,15 +247,10 @@ function ManageWidgetActionsController($rootScope, $scope, $document, $mdDialog, var actionSourceActions = vm.widgetActions[actionSourceId]; for (var i=0;i
-
+
- {{actionSource.name}} + {{vm.actionSourceName(actionSource)}}
@@ -48,6 +48,7 @@
widget-config.action-name-required
+
widget-config.action-name-not-unique
@@ -63,6 +64,57 @@
widget-config.action-type-required
+
+
widget-action.target-dashboard
+ + +
+ + +
+ {{item}} +
+
+
+
widget-action.target-dashboard-state-required
+
+
+ {{ 'widget-action.open-right-layout' | translate }} + + {{ 'widget-action.set-entity-from-widget' | translate }} + + +
diff --git a/ui/src/app/components/widget/widget-config.directive.js b/ui/src/app/components/widget/widget-config.directive.js index 3df9263c59..afdaf8d745 100644 --- a/ui/src/app/components/widget/widget-config.directive.js +++ b/ui/src/app/components/widget/widget-config.directive.js @@ -468,6 +468,7 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout aliasController: '=', functionsOnly: '=', fetchEntityKeys: '&', + fetchDashboardStates: '&', onCreateEntityAlias: '&', theForm: '=' }, diff --git a/ui/src/app/components/widget/widget-config.tpl.html b/ui/src/app/components/widget/widget-config.tpl.html index 2cc264c0d7..f2ee0f112d 100644 --- a/ui/src/app/components/widget/widget-config.tpl.html +++ b/ui/src/app/components/widget/widget-config.tpl.html @@ -277,7 +277,10 @@ - + diff --git a/ui/src/app/components/widget/widget.controller.js b/ui/src/app/components/widget/widget.controller.js index b2877f3d38..113399a8cc 100644 --- a/ui/src/app/components/widget/widget.controller.js +++ b/ui/src/app/components/widget/widget.controller.js @@ -20,7 +20,7 @@ import Subscription from '../../api/subscription'; /* eslint-disable angular/angularelement */ /*@ngInject*/ -export default function WidgetController($scope, $timeout, $window, $element, $q, $log, $injector, $filter, $compile, tbRaf, types, utils, timeService, +export default function WidgetController($scope, $state, $timeout, $window, $element, $q, $log, $injector, $filter, $compile, tbRaf, types, utils, timeService, datasourceService, alarmService, entityService, deviceService, visibleRect, isEdit, isMobile, stDiff, dashboardTimewindow, dashboardTimewindowApi, widget, aliasController, stateController, widgetInfo, widgetType) { @@ -44,6 +44,20 @@ export default function WidgetController($scope, $timeout, $window, $element, $q var cafs = {}; + var actionDescriptorsBySourceId = {}; + if (widget.config.actions) { + for (var actionSourceId in widget.config.actions) { + var descriptors = widget.config.actions[actionSourceId]; + var actionDescriptors = []; + descriptors.forEach(function(descriptor) { + var actionDescriptor = angular.copy(descriptor); + actionDescriptor.displayName = utils.customTranslation(descriptor.name, descriptor.name); + actionDescriptors.push(actionDescriptor); + }); + actionDescriptorsBySourceId[actionSourceId] = actionDescriptors; + } + } + var widgetContext = { inited: false, $container: null, @@ -103,9 +117,32 @@ export default function WidgetController($scope, $timeout, $window, $element, $q utils: { formatValue: formatValue }, + actionsApi: { + actionDescriptorsBySourceId: actionDescriptorsBySourceId, + getActionDescriptors: getActionDescriptors, + handleWidgetAction: handleWidgetAction + }, stateController: stateController }; + widgetContext.customHeaderActions = []; + var headerActionsDescriptors = getActionDescriptors(types.widgetActionSources.headerButton.value); + for (var i=0;i 0) { + try { + var customActionFunction = new Function('$event', 'widgetContext', 'entityId', 'entityName', customFunction); + customActionFunction($event, widgetContext, entityId, entityName); + } catch (e) { + // + } + } + break; + } + } + + function getFirstEntityInfo() { + var entityInfo; + for (var id in widgetContext.subscriptions) { + var subscription = widgetContext.subscriptions[id]; + entityInfo = subscription.getFirstEntityInfo(); + if (entityInfo) { + break; + } + } + return entityInfo; + } + function configureWidgetElement() { $scope.displayLegend = angular.isDefined(widget.config.showLegend) ? diff --git a/ui/src/app/dashboard/add-widget.controller.js b/ui/src/app/dashboard/add-widget.controller.js index fd2ada7b4a..c15492dbd9 100644 --- a/ui/src/app/dashboard/add-widget.controller.js +++ b/ui/src/app/dashboard/add-widget.controller.js @@ -36,6 +36,7 @@ export default function AddWidgetController($scope, widgetService, entityService vm.add = add; vm.cancel = cancel; vm.fetchEntityKeys = fetchEntityKeys; + vm.fetchDashboardStates = fetchDashboardStates; vm.createEntityAlias = createEntityAlias; vm.widgetConfig = { @@ -128,6 +129,26 @@ export default function AddWidgetController($scope, widgetService, entityService return deferred.promise; } + function fetchDashboardStates (query) { + var deferred = $q.defer(); + var stateIds = Object.keys(vm.dashboard.configuration.states); + var result = query ? stateIds.filter( + createFilterForDashboardState(query)) : stateIds; + if (result && result.length) { + deferred.resolve(result); + } else { + deferred.resolve([query]); + } + return deferred.promise; + } + + function createFilterForDashboardState (query) { + var lowercaseQuery = angular.lowercase(query); + return function filterFn(stateId) { + return (angular.lowercase(stateId).indexOf(lowercaseQuery) === 0); + }; + } + function createEntityAlias (event, alias, allowedEntityTypes) { var deferred = $q.defer(); diff --git a/ui/src/app/dashboard/add-widget.tpl.html b/ui/src/app/dashboard/add-widget.tpl.html index 3920f91aeb..4ca29f0b01 100644 --- a/ui/src/app/dashboard/add-widget.tpl.html +++ b/ui/src/app/dashboard/add-widget.tpl.html @@ -42,6 +42,7 @@ alias-controller="vm.aliasController" functions-only="vm.functionsOnly" fetch-entity-keys="vm.fetchEntityKeys(entityAliasId, query, type)" + fetch-dashboard-states="vm.fetchDashboardStates(query)" on-create-entity-alias="vm.createEntityAlias(event, alias, allowedEntityTypes)" the-form="theForm"> diff --git a/ui/src/app/dashboard/edit-widget.directive.js b/ui/src/app/dashboard/edit-widget.directive.js index 5d32706f64..9bf1548d4a 100644 --- a/ui/src/app/dashboard/edit-widget.directive.js +++ b/ui/src/app/dashboard/edit-widget.directive.js @@ -94,6 +94,26 @@ export default function EditWidgetDirective($compile, $templateCache, types, wid return deferred.promise; }; + scope.fetchDashboardStates = function(query) { + var deferred = $q.defer(); + var stateIds = Object.keys(scope.dashboard.configuration.states); + var result = query ? stateIds.filter( + createFilterForDashboardState(query)) : stateIds; + if (result && result.length) { + deferred.resolve(result); + } else { + deferred.resolve([query]); + } + return deferred.promise; + } + + function createFilterForDashboardState (query) { + var lowercaseQuery = angular.lowercase(query); + return function filterFn(stateId) { + return (angular.lowercase(stateId).indexOf(lowercaseQuery) === 0); + }; + } + scope.createEntityAlias = function (event, alias, allowedEntityTypes) { var deferred = $q.defer(); diff --git a/ui/src/app/dashboard/edit-widget.tpl.html b/ui/src/app/dashboard/edit-widget.tpl.html index c6bfd5a8c4..1f724a8749 100644 --- a/ui/src/app/dashboard/edit-widget.tpl.html +++ b/ui/src/app/dashboard/edit-widget.tpl.html @@ -26,6 +26,7 @@ alias-controller="aliasController" functions-only="widgetEditMode" fetch-entity-keys="fetchEntityKeys(entityAliasId, query, type)" + fetch-dashboard-states="fetchDashboardStates(query)" on-create-entity-alias="createEntityAlias(event, alias, allowedEntityTypes)" the-form="theForm"> diff --git a/ui/src/app/dashboard/states/default-state-controller.js b/ui/src/app/dashboard/states/default-state-controller.js index 716d333229..d39478f14c 100644 --- a/ui/src/app/dashboard/states/default-state-controller.js +++ b/ui/src/app/dashboard/states/default-state-controller.js @@ -15,7 +15,7 @@ */ /*@ngInject*/ -export default function DefaultStateController($scope, $location, $state, $stateParams, $translate, types, dashboardUtils) { +export default function DefaultStateController($scope, $location, $state, $stateParams, utils, types, dashboardUtils) { var vm = this; @@ -50,6 +50,9 @@ export default function DefaultStateController($scope, $location, $state, $state } function updateState(id, params, openRightLayout) { + if (!id) { + id = getStateId(); + } if (vm.states && vm.states[id]) { if (!params) { params = {}; @@ -110,15 +113,7 @@ export default function DefaultStateController($scope, $location, $state, $state } function getStateName(id, state) { - var result = ''; - var translationId = types.translate.customTranslationsPrefix + state.name; - var translation = $translate.instant(translationId); - if (translation != translationId) { - result = translation + ''; - } else { - result = id; - } - return result; + return utils.customTranslation(state.name, id); } function parseState(stateJson) { diff --git a/ui/src/app/dashboard/states/entity-state-controller.js b/ui/src/app/dashboard/states/entity-state-controller.js index dd295cc89e..4510449e28 100644 --- a/ui/src/app/dashboard/states/entity-state-controller.js +++ b/ui/src/app/dashboard/states/entity-state-controller.js @@ -55,6 +55,9 @@ export default function EntityStateController($scope, $location, $state, $stateP } function updateState(id, params, openRightLayout) { + if (!id) { + id = getStateId(); + } if (vm.states && vm.states[id]) { resolveEntity(params).then( function success(entityName) { @@ -121,17 +124,10 @@ export default function EntityStateController($scope, $location, $state, $stateP var result = ''; if (vm.stateObject[index]) { var stateName = vm.states[vm.stateObject[index].id].name; - var translationId = types.translate.customTranslationsPrefix + stateName; - var translation = $translate.instant(translationId); - if (translation != translationId) { - stateName = translation + ''; - } + stateName = utils.customTranslation(stateName, stateName); var params = vm.stateObject[index].params; - if (params && params.entityName) { - result = utils.insertVariable(stateName, 'entityName', params.entityName); - } else { - result = stateName; - } + var entityName = params && params.entityName ? params.entityName : ''; + result = utils.insertVariable(stateName, 'entityName', entityName); } return result; } diff --git a/ui/src/app/entity/attribute/add-widget-to-dashboard-dialog.controller.js b/ui/src/app/entity/attribute/add-widget-to-dashboard-dialog.controller.js index bcf37dd825..a133829086 100644 --- a/ui/src/app/entity/attribute/add-widget-to-dashboard-dialog.controller.js +++ b/ui/src/app/entity/attribute/add-widget-to-dashboard-dialog.controller.js @@ -102,6 +102,7 @@ export default function AddWidgetToDashboardDialogController($scope, $mdDialog, if (vm.addToDashboardType === 0) { dashboardService.getDashboard(vm.dashboardId).then( function success(dashboard) { + dashboard = dashboardUtils.validateAndUpdateDashboard(dashboard); selectTargetState($event, dashboard).then( function(targetState) { selectTargetLayout($event, dashboard, targetState).then( diff --git a/ui/src/app/locale/locale.constant.js b/ui/src/app/locale/locale.constant.js index 63f20e5410..4d4ebe2600 100644 --- a/ui/src/app/locale/locale.constant.js +++ b/ui/src/app/locale/locale.constant.js @@ -1104,11 +1104,16 @@ export default angular.module('thingsboard.locale', []) "export": "Export widget" }, "widget-action": { - "header-button": "Header button", + "header-button": "Widget header button", "open-dashboard-state": "Navigate to new dashboard state", "update-dashboard-state": "Update current dashboard state", "open-dashboard": "Navigate to other dashboard", - "custom": "Custom action" + "custom": "Custom action", + "target-dashboard-state": "Target dashboard state", + "target-dashboard-state-required": "Target dashboard state is required", + "set-entity-from-widget": "Set entity from widget", + "target-dashboard": "Target dashboard", + "open-right-layout": "Open right dashboard layout (mobile view)" }, "widgets-bundle": { "current": "Current bundle", @@ -1174,6 +1179,7 @@ export default angular.module('thingsboard.locale', []) "action-source-required": "Action source is required.", "action-name": "Name", "action-name-required": "Action name is required.", + "action-name-not-unique": "Another action with the same name already exists.
Action name should be unique within the same action source.", "action-icon": "Icon", "action-type": "Type", "action-type-required": "Action type is required.", @@ -1205,6 +1211,10 @@ export default angular.module('thingsboard.locale', []) "es_ES": "Spanish" }, "custom": { + "widget-action": { + "action-cell-button": "Action cell button", + "row-click": "On row click" + } } } } diff --git a/ui/src/app/widget/lib/alarms-table-widget.js b/ui/src/app/widget/lib/alarms-table-widget.js index 5a65af20b0..7618e6a829 100644 --- a/ui/src/app/widget/lib/alarms-table-widget.js +++ b/ui/src/app/widget/lib/alarms-table-widget.js @@ -158,13 +158,7 @@ function AlarmsTableWidgetController($element, $scope, $filter, $mdMedia, $mdDia vm.ctx.widgetActions = [ vm.searchAction ]; if (vm.settings.alarmsTitle && vm.settings.alarmsTitle.length) { - var translationId = types.translate.customTranslationsPrefix + vm.settings.alarmsTitle; - var translation = $translate.instant(translationId); - if (translation != translationId) { - vm.alarmsTitle = translation + ''; - } else { - vm.alarmsTitle = vm.settings.alarmsTitle; - } + vm.alarmsTitle = utils.customTranslation(vm.settings.alarmsTitle, vm.settings.alarmsTitle); } else { vm.alarmsTitle = $translate.instant('alarm.alarms'); } @@ -226,6 +220,9 @@ function AlarmsTableWidgetController($element, $scope, $filter, $mdMedia, $mdDia 'table.md-table td.md-cell.md-checkbox-cell md-checkbox:not(.md-checked) .md-icon {\n'+ 'border-color: ' + mdDarkSecondary + ';\n'+ '}\n'+ + 'table.md-table td.md-cell.tb-action-cell button.md-icon-button md-icon {\n'+ + 'color: ' + mdDarkSecondary + ';\n'+ + '}\n'+ 'table.md-table td.md-cell.md-placeholder {\n'+ 'color: ' + mdDarkDisabled + ';\n'+ '}\n'+ @@ -539,13 +536,7 @@ function AlarmsTableWidgetController($element, $scope, $filter, $mdMedia, $mdDia for (var d = 0; d < vm.alarmSource.dataKeys.length; d++ ) { var dataKey = vm.alarmSource.dataKeys[d]; - var translationId = types.translate.customTranslationsPrefix + dataKey.label; - var translation = $translate.instant(translationId); - if (translation != translationId) { - dataKey.title = translation + ''; - } else { - dataKey.title = dataKey.label; - } + dataKey.title = utils.customTranslation(dataKey.label, dataKey.label); var keySettings = dataKey.settings; diff --git a/ui/src/app/widget/lib/entities-table-widget.js b/ui/src/app/widget/lib/entities-table-widget.js index 4b8aa6ec2b..733e7cb592 100644 --- a/ui/src/app/widget/lib/entities-table-widget.js +++ b/ui/src/app/widget/lib/entities-table-widget.js @@ -65,8 +65,9 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra vm.currentEntity = null; vm.displayEntityName = true; + vm.entityNameColumnTitle = ''; vm.displayEntityType = true; - vm.displayActions = false; //TODO: Widget actions + vm.actionCellDescriptors = []; vm.displayPagination = true; vm.defaultPageSize = 10; vm.defaultSortOrder = 'entityName'; @@ -92,6 +93,7 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra vm.onReorder = onReorder; vm.onPaginate = onPaginate; vm.onRowClick = onRowClick; + vm.onActionButtonClick = onActionButtonClick; vm.isCurrent = isCurrent; vm.cellStyle = cellStyle; @@ -141,14 +143,10 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra vm.ctx.widgetActions = [ vm.searchAction ]; + vm.actionCellDescriptors = vm.ctx.actionsApi.getActionDescriptors('actionCellButton'); + if (vm.settings.entitiesTitle && vm.settings.entitiesTitle.length) { - var translationId = types.translate.customTranslationsPrefix + vm.settings.entitiesTitle; - var translation = $translate.instant(translationId); - if (translation != translationId) { - vm.entitiesTitle = translation + ''; - } else { - vm.entitiesTitle = vm.settings.entitiesTitle; - } + vm.entitiesTitle = utils.customTranslation(vm.settings.entitiesTitle, vm.settings.entitiesTitle); } else { vm.entitiesTitle = $translate.instant('entity.entities'); } @@ -157,6 +155,13 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra vm.searchAction.show = angular.isDefined(vm.settings.enableSearch) ? vm.settings.enableSearch : true; vm.displayEntityName = angular.isDefined(vm.settings.displayEntityName) ? vm.settings.displayEntityName : true; + + if (vm.settings.entityNameColumnTitle && vm.settings.entityNameColumnTitle.length) { + vm.entityNameColumnTitle = utils.customTranslation(vm.settings.entityNameColumnTitle, vm.settings.entityNameColumnTitle); + } else { + vm.entityNameColumnTitle = $translate.instant('entity.entity-name'); + } + vm.displayEntityType = angular.isDefined(vm.settings.displayEntityType) ? vm.settings.displayEntityType : true; vm.displayPagination = angular.isDefined(vm.settings.displayPagination) ? vm.settings.displayPagination : true; @@ -185,6 +190,8 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra //var mdDarkIcon = mdDarkSecondary; var mdDarkDivider = defaultColor.setAlpha(0.12).toRgbString(); + //md-icon.md-default-theme, md-icon { + var cssString = 'table.md-table th.md-column {\n'+ 'color: ' + mdDarkSecondary + ';\n'+ '}\n'+ @@ -204,6 +211,9 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra 'table.md-table td.md-cell.md-checkbox-cell md-checkbox:not(.md-checked) .md-icon {\n'+ 'border-color: ' + mdDarkSecondary + ';\n'+ '}\n'+ + 'table.md-table td.md-cell.tb-action-cell button.md-icon-button md-icon {\n'+ + 'color: ' + mdDarkSecondary + ';\n'+ + '}\n'+ 'table.md-table td.md-cell.md-placeholder {\n'+ 'color: ' + mdDarkDisabled + ';\n'+ '}\n'+ @@ -261,11 +271,37 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra } function onRowClick($event, entity) { + if ($event) { + $event.stopPropagation(); + } if (vm.currentEntity != entity) { vm.currentEntity = entity; + var descriptors = vm.ctx.actionsApi.getActionDescriptors('rowClick'); + if (descriptors.length) { + var entityId; + var entityName; + if (vm.currentEntity) { + entityId = vm.currentEntity.id; + entityName = vm.currentEntity.entityName; + } + vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); + } } } + function onActionButtonClick($event, entity, actionDescriptor) { + if ($event) { + $event.stopPropagation(); + } + var entityId; + var entityName; + if (entity) { + entityId = entity.id; + entityName = entity.entityName; + } + vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName); + } + function isCurrent(entity) { return (vm.currentEntity && entity && vm.currentEntity.id && entity.id) && (vm.currentEntity.id.id === entity.id.id); @@ -393,13 +429,7 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $tra } vm.dataKeys.push(dataKey); - var translationId = types.translate.customTranslationsPrefix + dataKey.label; - var translation = $translate.instant(translationId); - if (translation != translationId) { - dataKey.title = translation + ''; - } else { - dataKey.title = dataKey.label; - } + dataKey.title = utils.customTranslation(dataKey.label, dataKey.label); var keySettings = dataKey.settings; diff --git a/ui/src/app/widget/lib/entities-table-widget.tpl.html b/ui/src/app/widget/lib/entities-table-widget.tpl.html index 247d4792e8..162e5f74de 100644 --- a/ui/src/app/widget/lib/entities-table-widget.tpl.html +++ b/ui/src/app/widget/lib/entities-table-widget.tpl.html @@ -41,10 +41,10 @@ - + - + @@ -57,14 +57,18 @@ ng-style="vm.cellStyle(entity, key)" ng-bind-html="vm.cellContent(entity, key)"> -
entity.entity-name{{vm.entityNameColumnTitle}} entity.entity-type {{ key.title }}  
- +