thingsboard-aplcache
Changes
ui/src/app/entity/entity-select.directive.js 19(+16 -3)
Details
ui/src/app/entity/entity-select.directive.js 19(+16 -3)
diff --git a/ui/src/app/entity/entity-select.directive.js b/ui/src/app/entity/entity-select.directive.js
index 8e4031c..2ac5228 100644
--- a/ui/src/app/entity/entity-select.directive.js
+++ b/ui/src/app/entity/entity-select.directive.js
@@ -22,14 +22,26 @@ import entitySelectTemplate from './entity-select.tpl.html';
/* eslint-enable import/no-unresolved, import/default */
/*@ngInject*/
-export default function EntitySelect($compile, $templateCache) {
+export default function EntitySelect($compile, $templateCache, entityService) {
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.model = {};
+
+ var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes, scope.useAliasEntityTypes);
+
+ if (entityTypes.length === 1) {
+ scope.displayEntityTypeSelect = false;
+ scope.defaultEntityType = entityTypes[0];
+ } else {
+ scope.displayEntityTypeSelect = true;
+ }
+
+ scope.model = {
+ entityType: scope.defaultEntityType
+ };
scope.updateView = function () {
if (!scope.disabled) {
@@ -54,7 +66,7 @@ export default function EntitySelect($compile, $templateCache) {
scope.model.entityType = value.entityType;
scope.model.entityId = value.id;
} else {
- scope.model.entityType = null;
+ scope.model.entityType = scope.defaultEntityType;
scope.model.entityId = null;
}
initWatchers();
@@ -106,6 +118,7 @@ export default function EntitySelect($compile, $templateCache) {
theForm: '=?',
tbRequired: '=?',
disabled:'=ngDisabled',
+ allowedEntityTypes: "=?",
useAliasEntityTypes: "=?"
}
};
diff --git a/ui/src/app/entity/entity-select.tpl.html b/ui/src/app/entity/entity-select.tpl.html
index 9e5e227..d6b6eea 100644
--- a/ui/src/app/entity/entity-select.tpl.html
+++ b/ui/src/app/entity/entity-select.tpl.html
@@ -17,10 +17,12 @@
-->
<div layout='row' class="tb-entity-select">
<tb-entity-type-select style="min-width: 100px;"
+ ng-if="displayEntityTypeSelect"
the-form="theForm"
ng-disabled="disabled"
tb-required="tbRequired"
use-alias-entity-types="useAliasEntityTypes"
+ allowed-entity-types="allowedEntityTypes"
ng-model="model.entityType">
</tb-entity-type-select>
<tb-entity-autocomplete flex ng-if="model.entityType"