Commit 3881dc8423623e636d5c10b50160373b08a9433a

Authored by Vladyslav
Committed by GitHub
1 parent fcf436c6

Add new alias Current tenant (#2596)

@@ -435,6 +435,10 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -435,6 +435,10 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
435 if (user.authority === 'CUSTOMER_USER') { 435 if (user.authority === 'CUSTOMER_USER') {
436 entityId.id = user.customerId; 436 entityId.id = user.customerId;
437 } 437 }
  438 + } else if (entityType === types.aliasEntityType.current_tenant){
  439 + let user = userService.getCurrentUser();
  440 + entityId.entityType = types.entityType.tenant;
  441 + entityId.id = user.tenantId;
438 } 442 }
439 return entityId; 443 return entityId;
440 } 444 }
@@ -806,6 +810,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -806,6 +810,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
806 entityTypes.dashboard = types.entityType.dashboard; 810 entityTypes.dashboard = types.entityType.dashboard;
807 if (useAliasEntityTypes) { 811 if (useAliasEntityTypes) {
808 entityTypes.current_customer = types.aliasEntityType.current_customer; 812 entityTypes.current_customer = types.aliasEntityType.current_customer;
  813 + entityTypes.current_tenant = types.aliasEntityType.current_tenant;
809 } 814 }
810 break; 815 break;
811 case 'CUSTOMER_USER': 816 case 'CUSTOMER_USER':
@@ -408,7 +408,8 @@ export default angular.module('thingsboard.types', []) @@ -408,7 +408,8 @@ export default angular.module('thingsboard.types', [])
408 } 408 }
409 }, 409 },
410 aliasEntityType: { 410 aliasEntityType: {
411 - current_customer: "CURRENT_CUSTOMER" 411 + current_customer: "CURRENT_CUSTOMER",
  412 + current_tenant: "CURRENT_TENANT"
412 }, 413 },
413 entityTypeTranslations: { 414 entityTypeTranslations: {
414 "DEVICE": { 415 "DEVICE": {
@@ -474,6 +475,10 @@ export default angular.module('thingsboard.types', []) @@ -474,6 +475,10 @@ export default angular.module('thingsboard.types', [])
474 "CURRENT_CUSTOMER": { 475 "CURRENT_CUSTOMER": {
475 type: 'entity.type-current-customer', 476 type: 'entity.type-current-customer',
476 list: 'entity.type-current-customer' 477 list: 'entity.type-current-customer'
  478 + },
  479 + "CURRENT_TENANT": {
  480 + type: 'entity.type-current-tenant',
  481 + list: 'entity.type-current-tenant'
477 } 482 }
478 }, 483 },
479 entityField: { 484 entityField: {
@@ -22,13 +22,14 @@ import entitySelectTemplate from './entity-select.tpl.html'; @@ -22,13 +22,14 @@ import entitySelectTemplate from './entity-select.tpl.html';
22 /* eslint-enable import/no-unresolved, import/default */ 22 /* eslint-enable import/no-unresolved, import/default */
23 23
24 /*@ngInject*/ 24 /*@ngInject*/
25 -export default function EntitySelect($compile, $templateCache, entityService) { 25 +export default function EntitySelect($compile, $templateCache, entityService, types) {
26 26
27 var linker = function (scope, element, attrs, ngModelCtrl) { 27 var linker = function (scope, element, attrs, ngModelCtrl) {
28 var template = $templateCache.get(entitySelectTemplate); 28 var template = $templateCache.get(entitySelectTemplate);
29 element.html(template); 29 element.html(template);
30 30
31 scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false; 31 scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false;
  32 + scope.entityTypeCurrentTenant = types.aliasEntityType.current_tenant;
32 33
33 var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes, scope.useAliasEntityTypes); 34 var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes, scope.useAliasEntityTypes);
34 35
@@ -48,7 +49,8 @@ export default function EntitySelect($compile, $templateCache, entityService) { @@ -48,7 +49,8 @@ export default function EntitySelect($compile, $templateCache, entityService) {
48 scope.updateView = function () { 49 scope.updateView = function () {
49 if (!scope.disabled) { 50 if (!scope.disabled) {
50 var value = ngModelCtrl.$viewValue; 51 var value = ngModelCtrl.$viewValue;
51 - if (scope.model && scope.model.entityType && scope.model.entityId) { 52 + if (scope.model && scope.model.entityType &&
  53 + (scope.model.entityId || scope.model.entityType === scope.entityTypeCurrentTenant)) {
52 if (!value) { 54 if (!value) {
53 value = {}; 55 value = {};
54 } 56 }
@@ -25,11 +25,11 @@ @@ -25,11 +25,11 @@
25 allowed-entity-types="allowedEntityTypes" 25 allowed-entity-types="allowedEntityTypes"
26 ng-model="model.entityType"> 26 ng-model="model.entityType">
27 </tb-entity-type-select> 27 </tb-entity-type-select>
28 - <tb-entity-autocomplete flex ng-if="model.entityType" 28 + <tb-entity-autocomplete flex ng-if="model.entityType && model.entityType !== entityTypeCurrentTenant"
29 the-form="theForm" 29 the-form="theForm"
30 ng-disabled="disabled" 30 ng-disabled="disabled"
31 tb-required="tbRequired" 31 tb-required="tbRequired"
32 entity-type="model.entityType" 32 entity-type="model.entityType"
33 ng-model="model.entityId"> 33 ng-model="model.entityId">
34 </tb-entity-autocomplete> 34 </tb-entity-autocomplete>
35 -</div>  
  35 +</div>
@@ -770,6 +770,7 @@ @@ -770,6 +770,7 @@
770 "list-of-rulenodes": "{ count, plural, 1 {Jeden uzel pravidla} other {Seznam # uzlů pravidel} }", 770 "list-of-rulenodes": "{ count, plural, 1 {Jeden uzel pravidla} other {Seznam # uzlů pravidel} }",
771 "rulenode-name-starts-with": "Uzly pravidel, jejichž název začíná '{{prefix}}'", 771 "rulenode-name-starts-with": "Uzly pravidel, jejichž název začíná '{{prefix}}'",
772 "type-current-customer": "Stávající zákazník", 772 "type-current-customer": "Stávající zákazník",
  773 + "type-current-tenant": "Stávající tenant",
773 "search": "Vyhledat entity", 774 "search": "Vyhledat entity",
774 "selected-entities": "{ count, plural, 1 {1 entita} other {# entit} } zvoleno", 775 "selected-entities": "{ count, plural, 1 {1 entita} other {# entit} } zvoleno",
775 "entity-name": "Název entity", 776 "entity-name": "Název entity",
@@ -811,6 +811,7 @@ @@ -811,6 +811,7 @@
811 "list-of-rulenodes": "{ count, plural, 1 {One rule node} other {List of # rule nodes} }", 811 "list-of-rulenodes": "{ count, plural, 1 {One rule node} other {List of # rule nodes} }",
812 "rulenode-name-starts-with": "Rule nodes whose names start with '{{prefix}}'", 812 "rulenode-name-starts-with": "Rule nodes whose names start with '{{prefix}}'",
813 "type-current-customer": "Current Customer", 813 "type-current-customer": "Current Customer",
  814 + "type-current-tenant": "Current Tenant",
814 "search": "Search entities", 815 "search": "Search entities",
815 "selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected", 816 "selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected",
816 "entity-name": "Entity name", 817 "entity-name": "Entity name",
@@ -809,6 +809,7 @@ @@ -809,6 +809,7 @@
809 "list-of-rulenodes": "{ count, plural, 1 {Одно правило} other {Список из # правил} }", 809 "list-of-rulenodes": "{ count, plural, 1 {Одно правило} other {Список из # правил} }",
810 "rulenode-name-starts-with": "Правила, чьи названия начинаются с '{{prefix}}'", 810 "rulenode-name-starts-with": "Правила, чьи названия начинаются с '{{prefix}}'",
811 "type-current-customer": "Текущий клиент", 811 "type-current-customer": "Текущий клиент",
  812 + "type-current-tenant": "Текущий владелец",
812 "search": "Поиск объектов", 813 "search": "Поиск объектов",
813 "selected-entities": "Выбран(ы) { count, plural, 1 {1 объект} few {# объекта} other {# объектов} }", 814 "selected-entities": "Выбран(ы) { count, plural, 1 {1 объект} few {# объекта} other {# объектов} }",
814 "entity-name": "Название объекта", 815 "entity-name": "Название объекта",
@@ -942,6 +942,7 @@ @@ -942,6 +942,7 @@
942 "list-of-rulenodes": "{ count, plural, 1 {Одне правило} other {Список # правил} }", 942 "list-of-rulenodes": "{ count, plural, 1 {Одне правило} other {Список # правил} }",
943 "rulenode-name-starts-with": "Список правил, імена яких починаються '{{prefix}}'", 943 "rulenode-name-starts-with": "Список правил, імена яких починаються '{{prefix}}'",
944 "type-current-customer": "Поточний клієнт", 944 "type-current-customer": "Поточний клієнт",
  945 + "type-current-tenant": "Поточний власник",
945 "search": "Пошук сутностей", 946 "search": "Пошук сутностей",
946 "selected-entities": "{ count, plural, 1 {1 сутність} other {# сутності} } вибрано", 947 "selected-entities": "{ count, plural, 1 {1 сутність} other {# сутності} } вибрано",
947 "entity-name": "Ім'я сутності", 948 "entity-name": "Ім'я сутності",