Commit b36e8a1b88b04cdbf6a86f40ec32fc1ad0247e2b

Authored by Igor Kulikov
1 parent 10e588aa

Improve entity select component.

@@ -22,14 +22,26 @@ import entitySelectTemplate from './entity-select.tpl.html'; @@ -22,14 +22,26 @@ 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) { 25 +export default function EntitySelect($compile, $templateCache, entityService) {
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.model = {}; 32 +
  33 + var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes, scope.useAliasEntityTypes);
  34 +
  35 + if (entityTypes.length === 1) {
  36 + scope.displayEntityTypeSelect = false;
  37 + scope.defaultEntityType = entityTypes[0];
  38 + } else {
  39 + scope.displayEntityTypeSelect = true;
  40 + }
  41 +
  42 + scope.model = {
  43 + entityType: scope.defaultEntityType
  44 + };
33 45
34 scope.updateView = function () { 46 scope.updateView = function () {
35 if (!scope.disabled) { 47 if (!scope.disabled) {
@@ -54,7 +66,7 @@ export default function EntitySelect($compile, $templateCache) { @@ -54,7 +66,7 @@ export default function EntitySelect($compile, $templateCache) {
54 scope.model.entityType = value.entityType; 66 scope.model.entityType = value.entityType;
55 scope.model.entityId = value.id; 67 scope.model.entityId = value.id;
56 } else { 68 } else {
57 - scope.model.entityType = null; 69 + scope.model.entityType = scope.defaultEntityType;
58 scope.model.entityId = null; 70 scope.model.entityId = null;
59 } 71 }
60 initWatchers(); 72 initWatchers();
@@ -106,6 +118,7 @@ export default function EntitySelect($compile, $templateCache) { @@ -106,6 +118,7 @@ export default function EntitySelect($compile, $templateCache) {
106 theForm: '=?', 118 theForm: '=?',
107 tbRequired: '=?', 119 tbRequired: '=?',
108 disabled:'=ngDisabled', 120 disabled:'=ngDisabled',
  121 + allowedEntityTypes: "=?",
109 useAliasEntityTypes: "=?" 122 useAliasEntityTypes: "=?"
110 } 123 }
111 }; 124 };
@@ -17,10 +17,12 @@ @@ -17,10 +17,12 @@
17 --> 17 -->
18 <div layout='row' class="tb-entity-select"> 18 <div layout='row' class="tb-entity-select">
19 <tb-entity-type-select style="min-width: 100px;" 19 <tb-entity-type-select style="min-width: 100px;"
  20 + ng-if="displayEntityTypeSelect"
20 the-form="theForm" 21 the-form="theForm"
21 ng-disabled="disabled" 22 ng-disabled="disabled"
22 tb-required="tbRequired" 23 tb-required="tbRequired"
23 use-alias-entity-types="useAliasEntityTypes" 24 use-alias-entity-types="useAliasEntityTypes"
  25 + allowed-entity-types="allowedEntityTypes"
24 ng-model="model.entityType"> 26 ng-model="model.entityType">
25 </tb-entity-type-select> 27 </tb-entity-type-select>
26 <tb-entity-autocomplete flex ng-if="model.entityType" 28 <tb-entity-autocomplete flex ng-if="model.entityType"