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

This commit is contained in:
Igor Kulikov 2017-08-04 18:54:28 +03:00
parent 71eda9ed0a
commit d236f62653
11 changed files with 66 additions and 19 deletions

View File

@ -425,6 +425,17 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
} }
var stateEntityId = getStateEntityId(filter, stateParams); var stateEntityId = getStateEntityId(filter, stateParams);
switch (filter.type) { switch (filter.type) {
case types.aliasFilterType.singleEntity.value:
getEntity(filter.singleEntity.entityType, filter.singleEntity.id).then(
function success(entity) {
result.entities = entitiesToEntitiesInfo([entity]);
deferred.resolve(result);
},
function fail() {
deferred.reject();
}
);
break;
case types.aliasFilterType.entityList.value: case types.aliasFilterType.entityList.value:
getEntities(filter.entityType, filter.entityList).then( getEntities(filter.entityType, filter.entityList).then(
function success(entities) { function success(entities) {
@ -600,6 +611,8 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
var filter = entityAlias.filter; var filter = entityAlias.filter;
if (filterAliasFilterTypeByEntityTypes(filter.type, entityTypes)) { if (filterAliasFilterTypeByEntityTypes(filter.type, entityTypes)) {
switch (filter.type) { switch (filter.type) {
case types.aliasFilterType.singleEntity.value:
return entityTypes.indexOf(filter.singleEntity.entityType) > -1 ? true : false;
case types.aliasFilterType.entityList.value: case types.aliasFilterType.entityList.value:
return entityTypes.indexOf(filter.entityType) > -1 ? true : false; return entityTypes.indexOf(filter.entityType) > -1 ? true : false;
case types.aliasFilterType.entityName.value: case types.aliasFilterType.entityName.value:
@ -642,6 +655,8 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
function filterAliasFilterTypeByEntityType(aliasFilterType, entityType) { function filterAliasFilterTypeByEntityType(aliasFilterType, entityType) {
switch (aliasFilterType) { switch (aliasFilterType) {
case types.aliasFilterType.singleEntity.value:
return true;
case types.aliasFilterType.entityList.value: case types.aliasFilterType.entityList.value:
return true; return true;
case types.aliasFilterType.entityName.value: case types.aliasFilterType.entityName.value:

View File

@ -203,7 +203,7 @@ function DashboardUtils(types, utils, timeService) {
} }
if (angular.isUndefined(dashboard.configuration.states)) { if (angular.isUndefined(dashboard.configuration.states)) {
dashboard.configuration.states = { dashboard.configuration.states = {
'default': createDefaultState('Default', true) 'default': createDefaultState(dashboard.title, true)
}; };
var mainLayout = dashboard.configuration.states['default'].layouts['main']; var mainLayout = dashboard.configuration.states['default'].layouts['main'];
@ -272,16 +272,16 @@ function DashboardUtils(types, utils, timeService) {
} }
if (angular.isUndefined(dashboard.configuration.settings)) { if (angular.isUndefined(dashboard.configuration.settings)) {
dashboard.configuration.settings = {}; dashboard.configuration.settings = {};
dashboard.configuration.settings.stateControllerId = 'default'; dashboard.configuration.settings.stateControllerId = 'entity';
dashboard.configuration.settings.showTitle = true; dashboard.configuration.settings.showTitle = false;
dashboard.configuration.settings.showDashboardsSelect = true; dashboard.configuration.settings.showDashboardsSelect = true;
dashboard.configuration.settings.showEntitiesSelect = true; dashboard.configuration.settings.showEntitiesSelect = true;
dashboard.configuration.settings.showDashboardTimewindow = true; dashboard.configuration.settings.showDashboardTimewindow = true;
dashboard.configuration.settings.showDashboardExport = true; dashboard.configuration.settings.showDashboardExport = true;
dashboard.configuration.settings.toolbarAlwaysOpen = false; dashboard.configuration.settings.toolbarAlwaysOpen = true;
} else { } else {
if (angular.isUndefined(dashboard.configuration.settings.stateControllerId)) { if (angular.isUndefined(dashboard.configuration.settings.stateControllerId)) {
dashboard.configuration.settings.stateControllerId = 'default'; dashboard.configuration.settings.stateControllerId = 'entity';
} }
} }
if (angular.isDefined(dashboard.configuration.gridSettings)) { if (angular.isDefined(dashboard.configuration.gridSettings)) {
@ -344,9 +344,8 @@ function DashboardUtils(types, utils, timeService) {
function createSingleEntityFilter(entityType, entityId) { function createSingleEntityFilter(entityType, entityId) {
return { return {
type: types.aliasFilterType.entityList.value, type: types.aliasFilterType.singleEntity.value,
entityList: [entityId], singleEntity: { entityType: entityType, id: entityId },
entityType: entityType,
resolveMultiple: false resolveMultiple: false
}; };
} }

View File

@ -157,6 +157,10 @@ export default angular.module('thingsboard.types', [])
} }
}, },
aliasFilterType: { aliasFilterType: {
singleEntity: {
value: 'singleEntity',
name: 'alias.filter-type-single-entity'
},
entityList: { entityList: {
value: 'entityList', value: 'entityList',
name: 'alias.filter-type-entity-list' name: 'alias.filter-type-entity-list'

View File

@ -33,11 +33,11 @@ export default function DashboardSettingsController($scope, $mdDialog, statesCon
if (vm.settings) { if (vm.settings) {
if (angular.isUndefined(vm.settings.stateControllerId)) { if (angular.isUndefined(vm.settings.stateControllerId)) {
vm.settings.stateControllerId = 'default'; vm.settings.stateControllerId = 'entity';
} }
if (angular.isUndefined(vm.settings.showTitle)) { if (angular.isUndefined(vm.settings.showTitle)) {
vm.settings.showTitle = true; vm.settings.showTitle = false;
} }
if (angular.isUndefined(vm.settings.titleColor)) { if (angular.isUndefined(vm.settings.titleColor)) {
@ -61,7 +61,7 @@ export default function DashboardSettingsController($scope, $mdDialog, statesCon
} }
if (angular.isUndefined(vm.settings.toolbarAlwaysOpen)) { if (angular.isUndefined(vm.settings.toolbarAlwaysOpen)) {
vm.settings.toolbarAlwaysOpen = false; vm.settings.toolbarAlwaysOpen = true;
} }
} }

View File

@ -51,10 +51,17 @@ function DashboardToolbarController($scope, $element, $timeout, mdFabToolbarAnim
vm.mdFabToolbarElement = angular.element($element[0].querySelector('md-fab-toolbar')); vm.mdFabToolbarElement = angular.element($element[0].querySelector('md-fab-toolbar'));
$timeout(function() { function initElements() {
vm.mdFabBackgroundElement = angular.element(vm.mdFabToolbarElement[0].querySelector('.md-fab-toolbar-background')); $timeout(function() {
vm.mdFabTriggerElement = angular.element(vm.mdFabToolbarElement[0].querySelector('md-fab-trigger button')); vm.mdFabBackgroundElement = angular.element(vm.mdFabToolbarElement[0].querySelector('.md-fab-toolbar-background'));
}); vm.mdFabTriggerElement = angular.element(vm.mdFabToolbarElement[0].querySelector('md-fab-trigger button'));
if (!vm.mdFabBackgroundElement || !vm.mdFabBackgroundElement[0]) {
initElements();
} else {
triggerFabResize();
}
});
}
addResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef addResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef
@ -62,7 +69,12 @@ function DashboardToolbarController($scope, $element, $timeout, mdFabToolbarAnim
removeResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef removeResizeListener(vm.mdFabToolbarElement[0], triggerFabResize); // eslint-disable-line no-undef
}); });
initElements();
function triggerFabResize() { function triggerFabResize() {
if (!vm.mdFabBackgroundElement || !vm.mdFabBackgroundElement[0]) {
return;
}
var ctrl = vm.mdFabToolbarElement.controller('mdFabToolbar'); var ctrl = vm.mdFabToolbarElement.controller('mdFabToolbar');
if (ctrl.isOpen) { if (ctrl.isOpen) {
if (!vm.mdFabBackgroundElement[0].offsetWidth) { if (!vm.mdFabBackgroundElement[0].offsetWidth) {

View File

@ -757,7 +757,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget
angular.isDefined(vm.dashboard.configuration.settings.toolbarAlwaysOpen)) { angular.isDefined(vm.dashboard.configuration.settings.toolbarAlwaysOpen)) {
return vm.dashboard.configuration.settings.toolbarAlwaysOpen; return vm.dashboard.configuration.settings.toolbarAlwaysOpen;
} else { } else {
return false; return true;
} }
} }
@ -766,7 +766,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget
angular.isDefined(vm.dashboard.configuration.settings.showTitle)) { angular.isDefined(vm.dashboard.configuration.settings.showTitle)) {
return vm.dashboard.configuration.settings.showTitle; return vm.dashboard.configuration.settings.showTitle;
} else { } else {
return true; return false;
} }
} }

View File

@ -16,7 +16,7 @@
--> -->
<md-content flex tb-expand-fullscreen="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-button-id="dashboard-expand-button" <md-content flex tb-expand-fullscreen="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-button-id="dashboard-expand-button"
hide-expand-button="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-tooltip-direction="bottom"> hide-expand-button="vm.widgetEditMode || vm.iframeMode || forceFullscreen" expand-tooltip-direction="bottom" ng-if="vm.dashboard">
<section class="tb-dashboard-toolbar" ng-show="vm.showDashboardToolbar()" <section class="tb-dashboard-toolbar" ng-show="vm.showDashboardToolbar()"
ng-class="{ 'tb-dashboard-toolbar-opened': vm.toolbarOpened, 'tb-dashboard-toolbar-closed': !vm.toolbarOpened }"> ng-class="{ 'tb-dashboard-toolbar-opened': vm.toolbarOpened, 'tb-dashboard-toolbar-closed': !vm.toolbarOpened }">
<tb-dashboard-toolbar ng-show="!vm.widgetEditMode" force-fullscreen="forceFullscreen" <tb-dashboard-toolbar ng-show="!vm.widgetEditMode" force-fullscreen="forceFullscreen"

View File

@ -43,6 +43,10 @@ export default function EntityFilterViewDirective($compile, $templateCache, $q,
var entityType; var entityType;
var prefix; var prefix;
switch (scope.filter.type) { switch (scope.filter.type) {
case types.aliasFilterType.singleEntity.value:
entityType = scope.filter.singleEntity.entityType;
scope.filterDisplayValue = $translate.instant(types.entityTypeTranslations[entityType].list, {count: 1}, 'messageformat');
break;
case types.aliasFilterType.entityList.value: case types.aliasFilterType.entityList.value:
entityType = scope.filter.entityType; entityType = scope.filter.entityType;
var count = scope.filter.entityList.length; var count = scope.filter.entityList.length;

View File

@ -43,8 +43,12 @@ export default function EntityFilterDirective($compile, $templateCache, $q, $doc
function updateFilter() { function updateFilter() {
var filter = {}; var filter = {};
filter.type = scope.filter.type; filter.type = scope.filter.type;
filter.resolveMultiple = scope.filter.resolveMultiple; filter.resolveMultiple = true;
switch (filter.type) { switch (filter.type) {
case types.aliasFilterType.singleEntity.value:
filter.singleEntity = null;
filter.resolveMultiple = false;
break;
case types.aliasFilterType.entityList.value: case types.aliasFilterType.entityList.value:
filter.entityType = null; filter.entityType = null;
filter.entityList = []; filter.entityList = [];
@ -56,6 +60,7 @@ export default function EntityFilterDirective($compile, $templateCache, $q, $doc
case types.aliasFilterType.stateEntity.value: case types.aliasFilterType.stateEntity.value:
filter.stateEntityParamName = null; filter.stateEntityParamName = null;
filter.defaultStateEntity = null; filter.defaultStateEntity = null;
filter.resolveMultiple = false;
break; break;
case types.aliasFilterType.assetType.value: case types.aliasFilterType.assetType.value:
filter.assetType = null; filter.assetType = null;

View File

@ -28,6 +28,13 @@
<div ng-message="required" translate>alias.filter-type-required</div> <div ng-message="required" translate>alias.filter-type-required</div>
</div> </div>
</md-input-container> </md-input-container>
<section layout="column" ng-if="filter.type == types.aliasFilterType.singleEntity.value" id="singleEntityFilter">
<tb-entity-select flex
the-form="theForm"
tb-required="true"
ng-model="filter.singleEntity">
</tb-entity-select>
</section>
<section layout="column" ng-if="filter.type == types.aliasFilterType.entityList.value" id="entityListFilter"> <section layout="column" ng-if="filter.type == types.aliasFilterType.entityList.value" id="entityListFilter">
<tb-entity-type-select <tb-entity-type-select
ng-model="filter.entityType" ng-model="filter.entityType"

View File

@ -163,6 +163,7 @@ export default angular.module('thingsboard.locale', [])
"name": "Alias name", "name": "Alias name",
"name-required": "Alias name is required", "name-required": "Alias name is required",
"duplicate-alias": "Alias with same name is already exists.", "duplicate-alias": "Alias with same name is already exists.",
"filter-type-single-entity": "Single entity",
"filter-type-entity-list": "Entity list", "filter-type-entity-list": "Entity list",
"filter-type-entity-name": "Entity name", "filter-type-entity-name": "Entity name",
"filter-type-state-entity": "Entity from dashboard state", "filter-type-state-entity": "Entity from dashboard state",