Commit 2441cc0ee9c662e3802632b2ec92a5e6a85a7d29

Authored by Igor Kulikov
1 parent 2eef2c02

UI: Minor updates.

... ... @@ -892,10 +892,10 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
892 892 }
893 893 }
894 894
895   - function getRelatedEntities(rootEntityId, entityType, entitySubTypes, maxLevel, keys, typeTranslatePrefix, relationType) {
  895 + function getRelatedEntities(rootEntityId, entityType, entitySubTypes, maxLevel, keys, typeTranslatePrefix, relationType, direction) {
896 896 var deferred = $q.defer();
897 897
898   - var entitySearchQuery = constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType);
  898 + var entitySearchQuery = constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType, direction);
899 899 if (!entitySearchQuery) {
900 900 deferred.reject();
901 901 } else {
... ... @@ -930,12 +930,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
930 930 return deferred.promise;
931 931 }
932 932
933   - function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation) {
  933 + function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation, direction) {
934 934 var deferred = $q.defer();
  935 + if (!direction) {
  936 + direction = types.entitySearchDirection.from;
  937 + }
935 938 if (relatedEntity.id.id) {
936   - updateRelatedEntity(relatedEntity, keys, deferred, relation);
  939 + updateRelatedEntity(relatedEntity, keys, deferred, relation, direction);
937 940 } else {
938   - addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation);
  941 + addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation, direction);
939 942 }
940 943 return deferred.promise;
941 944 }
... ... @@ -1073,7 +1076,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1073 1076 }
1074 1077 }
1075 1078
1076   - function addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation) {
  1079 + function addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation, direction) {
1077 1080 var entity = {};
1078 1081 entity.id = relatedEntity.id;
1079 1082 entity.name = relatedEntity.name;
... ... @@ -1083,13 +1086,18 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1083 1086 relatedEntity.id = entity.id;
1084 1087 if (!relation) {
1085 1088 relation = {
1086   - from: parentEntityId,
1087   - to: relatedEntity.id,
1088 1089 type: types.entityRelationType.contains
1089 1090 };
1090   - } else {
  1091 + }
  1092 +
  1093 + if (direction == types.entitySearchDirection.from) {
  1094 + relation.from = parentEntityId;
1091 1095 relation.to = relatedEntity.id;
  1096 + } else {
  1097 + relation.from = relatedEntity.id;
  1098 + relation.to = parentEntityId;
1092 1099 }
  1100 +
1093 1101 entityRelationService.saveRelation(relation).then(
1094 1102 function success() {
1095 1103 updateEntity(entity, relatedEntity, keys, deferred, relation);
... ... @@ -1105,11 +1113,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1105 1113 );
1106 1114 }
1107 1115
1108   - function updateRelatedEntity(relatedEntity, keys, deferred, relation) {
  1116 + function updateRelatedEntity(relatedEntity, keys, deferred, relation, direction) {
1109 1117 getEntityPromise(relatedEntity.id.entityType, relatedEntity.id.id, {ignoreLoading: true}).then(
1110 1118 function success(entity) {
1111 1119 if (relation) {
1112   - relation.to = relatedEntity.id;
  1120 + if (direction == types.entitySearchDirection.from) {
  1121 + relation.to = relatedEntity.id;
  1122 + } else {
  1123 + relation.from = relatedEntity.id;
  1124 + }
1113 1125 entityRelationService.saveRelation(relation).then(
1114 1126 function success() {
1115 1127 updateEntity(entity, relatedEntity, keys, deferred);
... ... @@ -1162,16 +1174,19 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1162 1174 );
1163 1175 }
1164 1176
1165   - function constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType) {
  1177 + function constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType, direction) {
1166 1178
1167 1179 var searchQuery = {
1168 1180 parameters: {
1169 1181 rootId: rootEntityId.id,
1170 1182 rootType: rootEntityId.entityType,
1171   - direction: types.entitySearchDirection.from
  1183 + direction: direction
1172 1184 },
1173 1185 relationType: relationType
1174 1186 };
  1187 + if (!direction) {
  1188 + searchQuery.parameters.direction = types.entitySearchDirection.from;
  1189 + }
1175 1190 if (!relationType) {
1176 1191 searchQuery.relationType = types.entityRelationType.contains;
1177 1192 }
... ...
... ... @@ -44,16 +44,14 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
44 44 if (!scope.allEntities) {
45 45 entityService.getRelatedEntities(scope.rootEntityId, scope.entityType, scope.entitySubtypes, -1, []).then(
46 46 function success(entities) {
47   - if (scope.excludeEntityId) {
48   - var result = $filter('filter')(entities, {id: {id: scope.excludeEntityId.id} }, true);
49   - result = $filter('filter')(result, {id: {entityType: scope.excludeEntityId.entityType} }, true);
50   - if (result && result.length) {
51   - var excludeEntity = result[0];
52   - var index = entities.indexOf(excludeEntity);
53   - if (index > -1) {
54   - entities.splice(index, 1);
  47 + if (scope.excludeEntityIds && scope.excludeEntityIds.length) {
  48 + var filteredEntities = [];
  49 + entities.forEach(function(entity) {
  50 + if (scope.excludeEntityIds.indexOf(entity.id.id) == -1) {
  51 + filteredEntities.push(entity);
55 52 }
56   - }
  53 + });
  54 + entities = filteredEntities;
57 55 }
58 56 scope.allEntities = entities;
59 57 filterEntities(searchText, deferred);
... ... @@ -116,7 +114,7 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
116 114 rootEntityId: '=',
117 115 entityType: '=',
118 116 entitySubtypes: '=',
119   - excludeEntityId: '=?',
  117 + excludeEntityIds: '=?',
120 118 theForm: '=?',
121 119 tbRequired: '=?',
122 120 disabled:'=ngDisabled',
... ...