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