From 3881dc8423623e636d5c10b50160373b08a9433a Mon Sep 17 00:00:00 2001 From: Vladyslav Date: Fri, 10 Apr 2020 15:04:24 +0300 Subject: [PATCH] Add new alias Current tenant (#2596) --- ui/src/app/api/entity.service.js | 5 +++++ ui/src/app/common/types.constant.js | 7 ++++++- ui/src/app/entity/entity-select.directive.js | 6 ++++-- ui/src/app/entity/entity-select.tpl.html | 4 ++-- ui/src/app/locale/locale.constant-cs_CZ.json | 1 + ui/src/app/locale/locale.constant-en_US.json | 1 + ui/src/app/locale/locale.constant-ru_RU.json | 1 + ui/src/app/locale/locale.constant-uk_UA.json | 1 + 8 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ui/src/app/api/entity.service.js b/ui/src/app/api/entity.service.js index b795432dee..f692c99051 100644 --- a/ui/src/app/api/entity.service.js +++ b/ui/src/app/api/entity.service.js @@ -435,6 +435,10 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device if (user.authority === 'CUSTOMER_USER') { entityId.id = user.customerId; } + } else if (entityType === types.aliasEntityType.current_tenant){ + let user = userService.getCurrentUser(); + entityId.entityType = types.entityType.tenant; + entityId.id = user.tenantId; } return entityId; } @@ -806,6 +810,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device entityTypes.dashboard = types.entityType.dashboard; if (useAliasEntityTypes) { entityTypes.current_customer = types.aliasEntityType.current_customer; + entityTypes.current_tenant = types.aliasEntityType.current_tenant; } break; case 'CUSTOMER_USER': diff --git a/ui/src/app/common/types.constant.js b/ui/src/app/common/types.constant.js index 86bf952582..aff3821573 100644 --- a/ui/src/app/common/types.constant.js +++ b/ui/src/app/common/types.constant.js @@ -408,7 +408,8 @@ export default angular.module('thingsboard.types', []) } }, aliasEntityType: { - current_customer: "CURRENT_CUSTOMER" + current_customer: "CURRENT_CUSTOMER", + current_tenant: "CURRENT_TENANT" }, entityTypeTranslations: { "DEVICE": { @@ -474,6 +475,10 @@ export default angular.module('thingsboard.types', []) "CURRENT_CUSTOMER": { type: 'entity.type-current-customer', list: 'entity.type-current-customer' + }, + "CURRENT_TENANT": { + type: 'entity.type-current-tenant', + list: 'entity.type-current-tenant' } }, entityField: { diff --git a/ui/src/app/entity/entity-select.directive.js b/ui/src/app/entity/entity-select.directive.js index 9b1c763a60..e93a769eec 100644 --- a/ui/src/app/entity/entity-select.directive.js +++ b/ui/src/app/entity/entity-select.directive.js @@ -22,13 +22,14 @@ import entitySelectTemplate from './entity-select.tpl.html'; /* eslint-enable import/no-unresolved, import/default */ /*@ngInject*/ -export default function EntitySelect($compile, $templateCache, entityService) { +export default function EntitySelect($compile, $templateCache, entityService, types) { var linker = function (scope, element, attrs, ngModelCtrl) { var template = $templateCache.get(entitySelectTemplate); element.html(template); scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false; + scope.entityTypeCurrentTenant = types.aliasEntityType.current_tenant; var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes, scope.useAliasEntityTypes); @@ -48,7 +49,8 @@ export default function EntitySelect($compile, $templateCache, entityService) { scope.updateView = function () { if (!scope.disabled) { var value = ngModelCtrl.$viewValue; - if (scope.model && scope.model.entityType && scope.model.entityId) { + if (scope.model && scope.model.entityType && + (scope.model.entityId || scope.model.entityType === scope.entityTypeCurrentTenant)) { if (!value) { value = {}; } diff --git a/ui/src/app/entity/entity-select.tpl.html b/ui/src/app/entity/entity-select.tpl.html index 59133d541d..8800f9760f 100644 --- a/ui/src/app/entity/entity-select.tpl.html +++ b/ui/src/app/entity/entity-select.tpl.html @@ -25,11 +25,11 @@ allowed-entity-types="allowedEntityTypes" ng-model="model.entityType"> - - \ No newline at end of file + diff --git a/ui/src/app/locale/locale.constant-cs_CZ.json b/ui/src/app/locale/locale.constant-cs_CZ.json index 0006afc74b..2a297cd9bb 100644 --- a/ui/src/app/locale/locale.constant-cs_CZ.json +++ b/ui/src/app/locale/locale.constant-cs_CZ.json @@ -770,6 +770,7 @@ "list-of-rulenodes": "{ count, plural, 1 {Jeden uzel pravidla} other {Seznam # uzlů pravidel} }", "rulenode-name-starts-with": "Uzly pravidel, jejichž název začíná '{{prefix}}'", "type-current-customer": "Stávající zákazník", + "type-current-tenant": "Stávající tenant", "search": "Vyhledat entity", "selected-entities": "{ count, plural, 1 {1 entita} other {# entit} } zvoleno", "entity-name": "Název entity", diff --git a/ui/src/app/locale/locale.constant-en_US.json b/ui/src/app/locale/locale.constant-en_US.json index a0750164ca..d69778a787 100644 --- a/ui/src/app/locale/locale.constant-en_US.json +++ b/ui/src/app/locale/locale.constant-en_US.json @@ -811,6 +811,7 @@ "list-of-rulenodes": "{ count, plural, 1 {One rule node} other {List of # rule nodes} }", "rulenode-name-starts-with": "Rule nodes whose names start with '{{prefix}}'", "type-current-customer": "Current Customer", + "type-current-tenant": "Current Tenant", "search": "Search entities", "selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected", "entity-name": "Entity name", diff --git a/ui/src/app/locale/locale.constant-ru_RU.json b/ui/src/app/locale/locale.constant-ru_RU.json index 47c70da48a..f86eb988ff 100644 --- a/ui/src/app/locale/locale.constant-ru_RU.json +++ b/ui/src/app/locale/locale.constant-ru_RU.json @@ -809,6 +809,7 @@ "list-of-rulenodes": "{ count, plural, 1 {Одно правило} other {Список из # правил} }", "rulenode-name-starts-with": "Правила, чьи названия начинаются с '{{prefix}}'", "type-current-customer": "Текущий клиент", + "type-current-tenant": "Текущий владелец", "search": "Поиск объектов", "selected-entities": "Выбран(ы) { count, plural, 1 {1 объект} few {# объекта} other {# объектов} }", "entity-name": "Название объекта", diff --git a/ui/src/app/locale/locale.constant-uk_UA.json b/ui/src/app/locale/locale.constant-uk_UA.json index 7b882423ed..5a0899014d 100644 --- a/ui/src/app/locale/locale.constant-uk_UA.json +++ b/ui/src/app/locale/locale.constant-uk_UA.json @@ -942,6 +942,7 @@ "list-of-rulenodes": "{ count, plural, 1 {Одне правило} other {Список # правил} }", "rulenode-name-starts-with": "Список правил, імена яких починаються '{{prefix}}'", "type-current-customer": "Поточний клієнт", + "type-current-tenant": "Поточний власник", "search": "Пошук сутностей", "selected-entities": "{ count, plural, 1 {1 сутність} other {# сутності} } вибрано", "entity-name": "Ім'я сутності",