Commit d236f62653ffa87ac5d1244d104529cd8b1dd29f

Authored by Igor Kulikov
1 parent 71eda9ed

TB-70: Improve dashboard configuration. Add new alias type 'Single entity'.

@@ -425,6 +425,17 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -425,6 +425,17 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
425 } 425 }
426 var stateEntityId = getStateEntityId(filter, stateParams); 426 var stateEntityId = getStateEntityId(filter, stateParams);
427 switch (filter.type) { 427 switch (filter.type) {
  428 + case types.aliasFilterType.singleEntity.value:
  429 + getEntity(filter.singleEntity.entityType, filter.singleEntity.id).then(
  430 + function success(entity) {
  431 + result.entities = entitiesToEntitiesInfo([entity]);
  432 + deferred.resolve(result);
  433 + },
  434 + function fail() {
  435 + deferred.reject();
  436 + }
  437 + );
  438 + break;
428 case types.aliasFilterType.entityList.value: 439 case types.aliasFilterType.entityList.value:
429 getEntities(filter.entityType, filter.entityList).then( 440 getEntities(filter.entityType, filter.entityList).then(
430 function success(entities) { 441 function success(entities) {
@@ -600,6 +611,8 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -600,6 +611,8 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
600 var filter = entityAlias.filter; 611 var filter = entityAlias.filter;
601 if (filterAliasFilterTypeByEntityTypes(filter.type, entityTypes)) { 612 if (filterAliasFilterTypeByEntityTypes(filter.type, entityTypes)) {
602 switch (filter.type) { 613 switch (filter.type) {
  614 + case types.aliasFilterType.singleEntity.value:
  615 + return entityTypes.indexOf(filter.singleEntity.entityType) > -1 ? true : false;
603 case types.aliasFilterType.entityList.value: 616 case types.aliasFilterType.entityList.value:
604 return entityTypes.indexOf(filter.entityType) > -1 ? true : false; 617 return entityTypes.indexOf(filter.entityType) > -1 ? true : false;
605 case types.aliasFilterType.entityName.value: 618 case types.aliasFilterType.entityName.value:
@@ -642,6 +655,8 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -642,6 +655,8 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
642 655
643 function filterAliasFilterTypeByEntityType(aliasFilterType, entityType) { 656 function filterAliasFilterTypeByEntityType(aliasFilterType, entityType) {
644 switch (aliasFilterType) { 657 switch (aliasFilterType) {
  658 + case types.aliasFilterType.singleEntity.value:
  659 + return true;
645 case types.aliasFilterType.entityList.value: 660 case types.aliasFilterType.entityList.value:
646 return true; 661 return true;
647 case types.aliasFilterType.entityName.value: 662 case types.aliasFilterType.entityName.value:
@@ -203,7 +203,7 @@ function DashboardUtils(types, utils, timeService) { @@ -203,7 +203,7 @@ function DashboardUtils(types, utils, timeService) {
203 } 203 }
204 if (angular.isUndefined(dashboard.configuration.states)) { 204 if (angular.isUndefined(dashboard.configuration.states)) {
205 dashboard.configuration.states = { 205 dashboard.configuration.states = {
206 - 'default': createDefaultState('Default', true) 206 + 'default': createDefaultState(dashboard.title, true)
207 }; 207 };
208 208
209 var mainLayout = dashboard.configuration.states['default'].layouts['main']; 209 var mainLayout = dashboard.configuration.states['default'].layouts['main'];
@@ -272,16 +272,16 @@ function DashboardUtils(types, utils, timeService) { @@ -272,16 +272,16 @@ function DashboardUtils(types, utils, timeService) {
272 } 272 }
273 if (angular.isUndefined(dashboard.configuration.settings)) { 273 if (angular.isUndefined(dashboard.configuration.settings)) {
274 dashboard.configuration.settings = {}; 274 dashboard.configuration.settings = {};
275 - dashboard.configuration.settings.stateControllerId = 'default';  
276 - dashboard.configuration.settings.showTitle = true; 275 + dashboard.configuration.settings.stateControllerId = 'entity';
  276 + dashboard.configuration.settings.showTitle = false;
277 dashboard.configuration.settings.showDashboardsSelect = true; 277 dashboard.configuration.settings.showDashboardsSelect = true;
278 dashboard.configuration.settings.showEntitiesSelect = true; 278 dashboard.configuration.settings.showEntitiesSelect = true;
279 dashboard.configuration.settings.showDashboardTimewindow = true; 279 dashboard.configuration.settings.showDashboardTimewindow = true;
280 dashboard.configuration.settings.showDashboardExport = true; 280 dashboard.configuration.settings.showDashboardExport = true;
281 - dashboard.configuration.settings.toolbarAlwaysOpen = false; 281 + dashboard.configuration.settings.toolbarAlwaysOpen = true;
282 } else { 282 } else {
283 if (angular.isUndefined(dashboard.configuration.settings.stateControllerId)) { 283 if (angular.isUndefined(dashboard.configuration.settings.stateControllerId)) {
284 - dashboard.configuration.settings.stateControllerId = 'default'; 284 + dashboard.configuration.settings.stateControllerId = 'entity';
285 } 285 }
286 } 286 }
287 if (angular.isDefined(dashboard.configuration.gridSettings)) { 287 if (angular.isDefined(dashboard.configuration.gridSettings)) {
@@ -344,9 +344,8 @@ function DashboardUtils(types, utils, timeService) { @@ -344,9 +344,8 @@ function DashboardUtils(types, utils, timeService) {
344 344
345 function createSingleEntityFilter(entityType, entityId) { 345 function createSingleEntityFilter(entityType, entityId) {
346 return { 346 return {
347 - type: types.aliasFilterType.entityList.value,  
348 - entityList: [entityId],  
349 - entityType: entityType, 347 + type: types.aliasFilterType.singleEntity.value,
  348 + singleEntity: { entityType: entityType, id: entityId },
350 resolveMultiple: false 349 resolveMultiple: false
351 }; 350 };
352 } 351 }
@@ -157,6 +157,10 @@ export default angular.module('thingsboard.types', []) @@ -157,6 +157,10 @@ export default angular.module('thingsboard.types', [])
157 } 157 }
158 }, 158 },
159 aliasFilterType: { 159 aliasFilterType: {
  160 + singleEntity: {
  161 + value: 'singleEntity',
  162 + name: 'alias.filter-type-single-entity'
  163 + },
160 entityList: { 164 entityList: {
161 value: 'entityList', 165 value: 'entityList',
162 name: 'alias.filter-type-entity-list' 166 name: 'alias.filter-type-entity-list'
@@ -33,11 +33,11 @@ export default function DashboardSettingsController($scope, $mdDialog, statesCon @@ -33,11 +33,11 @@ export default function DashboardSettingsController($scope, $mdDialog, statesCon
33 33
34 if (vm.settings) { 34 if (vm.settings) {
35 if (angular.isUndefined(vm.settings.stateControllerId)) { 35 if (angular.isUndefined(vm.settings.stateControllerId)) {
36 - vm.settings.stateControllerId = 'default'; 36 + vm.settings.stateControllerId = 'entity';
37 } 37 }
38 38
39 if (angular.isUndefined(vm.settings.showTitle)) { 39 if (angular.isUndefined(vm.settings.showTitle)) {
40 - vm.settings.showTitle = true; 40 + vm.settings.showTitle = false;
41 } 41 }
42 42
43 if (angular.isUndefined(vm.settings.titleColor)) { 43 if (angular.isUndefined(vm.settings.titleColor)) {
@@ -61,7 +61,7 @@ export default function DashboardSettingsController($scope, $mdDialog, statesCon @@ -61,7 +61,7 @@ export default function DashboardSettingsController($scope, $mdDialog, statesCon
61 } 61 }
62 62
63 if (angular.isUndefined(vm.settings.toolbarAlwaysOpen)) { 63 if (angular.isUndefined(vm.settings.toolbarAlwaysOpen)) {
64 - vm.settings.toolbarAlwaysOpen = false; 64 + vm.settings.toolbarAlwaysOpen = true;
65 } 65 }
66 } 66 }
67 67
@@ -51,10 +51,17 @@ function DashboardToolbarController($scope, $element, $timeout, mdFabToolbarAnim @@ -51,10 +51,17 @@ function DashboardToolbarController($scope, $element, $timeout, mdFabToolbarAnim
51 51
52 vm.mdFabToolbarElement = angular.element($element[0].querySelector('md-fab-toolbar')); 52 vm.mdFabToolbarElement = angular.element($element[0].querySelector('md-fab-toolbar'));
53 53
54 - $timeout(function() {  
55 - vm.mdFabBackgroundElement = angular.element(vm.mdFabToolbarElement[0].querySelector('.md-fab-toolbar-background'));  
56 - vm.mdFabTriggerElement = angular.element(vm.mdFabToolbarElement[0].querySelector('md-fab-trigger button'));  
57 - }); 54 + function initElements() {
  55 + $timeout(function() {
  56 + vm.mdFabBackgroundElement = angular.element(vm.mdFabToolbarElement[0].querySelector('.md-fab-toolbar-background'));
  57 + vm.mdFabTriggerElement = angular.element(vm.mdFabToolbarElement[0].querySelector('md-fab-trigger button'));
  58 + if (!vm.mdFabBackgroundElement || !vm.mdFabBackgroundElement[0]) {
  59 + initElements();
  60 + } else {
  61 + triggerFabResize();
  62 + }
  63 + });
  64 + }
58 65
59 addResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef 66 addResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef
60 67
@@ -62,7 +69,12 @@ function DashboardToolbarController($scope, $element, $timeout, mdFabToolbarAnim @@ -62,7 +69,12 @@ function DashboardToolbarController($scope, $element, $timeout, mdFabToolbarAnim
62 removeResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef 69 removeResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef
63 }); 70 });
64 71
  72 + initElements();
  73 +
65 function triggerFabResize() { 74 function triggerFabResize() {
  75 + if (!vm.mdFabBackgroundElement || !vm.mdFabBackgroundElement[0]) {
  76 + return;
  77 + }
66 var ctrl = vm.mdFabToolbarElement.controller('mdFabToolbar'); 78 var ctrl = vm.mdFabToolbarElement.controller('mdFabToolbar');
67 if (ctrl.isOpen) { 79 if (ctrl.isOpen) {
68 if (!vm.mdFabBackgroundElement[0].offsetWidth) { 80 if (!vm.mdFabBackgroundElement[0].offsetWidth) {
@@ -757,7 +757,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget @@ -757,7 +757,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget
757 angular.isDefined(vm.dashboard.configuration.settings.toolbarAlwaysOpen)) { 757 angular.isDefined(vm.dashboard.configuration.settings.toolbarAlwaysOpen)) {
758 return vm.dashboard.configuration.settings.toolbarAlwaysOpen; 758 return vm.dashboard.configuration.settings.toolbarAlwaysOpen;
759 } else { 759 } else {
760 - return false; 760 + return true;
761 } 761 }
762 } 762 }
763 763
@@ -766,7 +766,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget @@ -766,7 +766,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget
766 angular.isDefined(vm.dashboard.configuration.settings.showTitle)) { 766 angular.isDefined(vm.dashboard.configuration.settings.showTitle)) {
767 return vm.dashboard.configuration.settings.showTitle; 767 return vm.dashboard.configuration.settings.showTitle;
768 } else { 768 } else {
769 - return true; 769 + return false;
770 } 770 }
771 } 771 }
772 772
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 16
17 --> 17 -->
18 <md-content flex tb-expand-fullscreen="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-button-id="dashboard-expand-button" 18 <md-content flex tb-expand-fullscreen="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-button-id="dashboard-expand-button"
19 - hide-expand-button="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-tooltip-direction="bottom"> 19 + hide-expand-button="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-tooltip-direction="bottom" ng-if="vm.dashboard">
20 <section class="tb-dashboard-toolbar" ng-show="vm.showDashboardToolbar()" 20 <section class="tb-dashboard-toolbar" ng-show="vm.showDashboardToolbar()"
21 ng-class="{ 'tb-dashboard-toolbar-opened': vm.toolbarOpened, 'tb-dashboard-toolbar-closed': !vm.toolbarOpened }"> 21 ng-class="{ 'tb-dashboard-toolbar-opened': vm.toolbarOpened, 'tb-dashboard-toolbar-closed': !vm.toolbarOpened }">
22 <tb-dashboard-toolbar ng-show="!vm.widgetEditMode" force-fullscreen="forceFullscreen" 22 <tb-dashboard-toolbar ng-show="!vm.widgetEditMode" force-fullscreen="forceFullscreen"
@@ -43,6 +43,10 @@ export default function EntityFilterViewDirective($compile, $templateCache, $q, @@ -43,6 +43,10 @@ export default function EntityFilterViewDirective($compile, $templateCache, $q,
43 var entityType; 43 var entityType;
44 var prefix; 44 var prefix;
45 switch (scope.filter.type) { 45 switch (scope.filter.type) {
  46 + case types.aliasFilterType.singleEntity.value:
  47 + entityType = scope.filter.singleEntity.entityType;
  48 + scope.filterDisplayValue = $translate.instant(types.entityTypeTranslations[entityType].list, {count: 1}, 'messageformat');
  49 + break;
46 case types.aliasFilterType.entityList.value: 50 case types.aliasFilterType.entityList.value:
47 entityType = scope.filter.entityType; 51 entityType = scope.filter.entityType;
48 var count = scope.filter.entityList.length; 52 var count = scope.filter.entityList.length;
@@ -43,8 +43,12 @@ export default function EntityFilterDirective($compile, $templateCache, $q, $doc @@ -43,8 +43,12 @@ export default function EntityFilterDirective($compile, $templateCache, $q, $doc
43 function updateFilter() { 43 function updateFilter() {
44 var filter = {}; 44 var filter = {};
45 filter.type = scope.filter.type; 45 filter.type = scope.filter.type;
46 - filter.resolveMultiple = scope.filter.resolveMultiple; 46 + filter.resolveMultiple = true;
47 switch (filter.type) { 47 switch (filter.type) {
  48 + case types.aliasFilterType.singleEntity.value:
  49 + filter.singleEntity = null;
  50 + filter.resolveMultiple = false;
  51 + break;
48 case types.aliasFilterType.entityList.value: 52 case types.aliasFilterType.entityList.value:
49 filter.entityType = null; 53 filter.entityType = null;
50 filter.entityList = []; 54 filter.entityList = [];
@@ -56,6 +60,7 @@ export default function EntityFilterDirective($compile, $templateCache, $q, $doc @@ -56,6 +60,7 @@ export default function EntityFilterDirective($compile, $templateCache, $q, $doc
56 case types.aliasFilterType.stateEntity.value: 60 case types.aliasFilterType.stateEntity.value:
57 filter.stateEntityParamName = null; 61 filter.stateEntityParamName = null;
58 filter.defaultStateEntity = null; 62 filter.defaultStateEntity = null;
  63 + filter.resolveMultiple = false;
59 break; 64 break;
60 case types.aliasFilterType.assetType.value: 65 case types.aliasFilterType.assetType.value:
61 filter.assetType = null; 66 filter.assetType = null;
@@ -28,6 +28,13 @@ @@ -28,6 +28,13 @@
28 <div ng-message="required" translate>alias.filter-type-required</div> 28 <div ng-message="required" translate>alias.filter-type-required</div>
29 </div> 29 </div>
30 </md-input-container> 30 </md-input-container>
  31 + <section layout="column" ng-if="filter.type == types.aliasFilterType.singleEntity.value" id="singleEntityFilter">
  32 + <tb-entity-select flex
  33 + the-form="theForm"
  34 + tb-required="true"
  35 + ng-model="filter.singleEntity">
  36 + </tb-entity-select>
  37 + </section>
31 <section layout="column" ng-if="filter.type == types.aliasFilterType.entityList.value" id="entityListFilter"> 38 <section layout="column" ng-if="filter.type == types.aliasFilterType.entityList.value" id="entityListFilter">
32 <tb-entity-type-select 39 <tb-entity-type-select
33 ng-model="filter.entityType" 40 ng-model="filter.entityType"
@@ -163,6 +163,7 @@ export default angular.module('thingsboard.locale', []) @@ -163,6 +163,7 @@ export default angular.module('thingsboard.locale', [])
163 "name": "Alias name", 163 "name": "Alias name",
164 "name-required": "Alias name is required", 164 "name-required": "Alias name is required",
165 "duplicate-alias": "Alias with same name is already exists.", 165 "duplicate-alias": "Alias with same name is already exists.",
  166 + "filter-type-single-entity": "Single entity",
166 "filter-type-entity-list": "Entity list", 167 "filter-type-entity-list": "Entity list",
167 "filter-type-entity-name": "Entity name", 168 "filter-type-entity-name": "Entity name",
168 "filter-type-state-entity": "Entity from dashboard state", 169 "filter-type-state-entity": "Entity from dashboard state",