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,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 var deferred = $q.defer(); 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 if (!entitySearchQuery) { 899 if (!entitySearchQuery) {
900 deferred.reject(); 900 deferred.reject();
901 } else { 901 } else {
@@ -930,12 +930,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -930,12 +930,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
930 return deferred.promise; 930 return deferred.promise;
931 } 931 }
932 932
933 - function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation) { 933 + function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation, direction) {
934 var deferred = $q.defer(); 934 var deferred = $q.defer();
  935 + if (!direction) {
  936 + direction = types.entitySearchDirection.from;
  937 + }
935 if (relatedEntity.id.id) { 938 if (relatedEntity.id.id) {
936 - updateRelatedEntity(relatedEntity, keys, deferred, relation); 939 + updateRelatedEntity(relatedEntity, keys, deferred, relation, direction);
937 } else { 940 } else {
938 - addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation); 941 + addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation, direction);
939 } 942 }
940 return deferred.promise; 943 return deferred.promise;
941 } 944 }
@@ -1073,7 +1076,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -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 var entity = {}; 1080 var entity = {};
1078 entity.id = relatedEntity.id; 1081 entity.id = relatedEntity.id;
1079 entity.name = relatedEntity.name; 1082 entity.name = relatedEntity.name;
@@ -1083,13 +1086,18 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -1083,13 +1086,18 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
1083 relatedEntity.id = entity.id; 1086 relatedEntity.id = entity.id;
1084 if (!relation) { 1087 if (!relation) {
1085 relation = { 1088 relation = {
1086 - from: parentEntityId,  
1087 - to: relatedEntity.id,  
1088 type: types.entityRelationType.contains 1089 type: types.entityRelationType.contains
1089 }; 1090 };
1090 - } else { 1091 + }
  1092 +
  1093 + if (direction == types.entitySearchDirection.from) {
  1094 + relation.from = parentEntityId;
1091 relation.to = relatedEntity.id; 1095 relation.to = relatedEntity.id;
  1096 + } else {
  1097 + relation.from = relatedEntity.id;
  1098 + relation.to = parentEntityId;
1092 } 1099 }
  1100 +
1093 entityRelationService.saveRelation(relation).then( 1101 entityRelationService.saveRelation(relation).then(
1094 function success() { 1102 function success() {
1095 updateEntity(entity, relatedEntity, keys, deferred, relation); 1103 updateEntity(entity, relatedEntity, keys, deferred, relation);
@@ -1105,11 +1113,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -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 getEntityPromise(relatedEntity.id.entityType, relatedEntity.id.id, {ignoreLoading: true}).then( 1117 getEntityPromise(relatedEntity.id.entityType, relatedEntity.id.id, {ignoreLoading: true}).then(
1110 function success(entity) { 1118 function success(entity) {
1111 if (relation) { 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 entityRelationService.saveRelation(relation).then( 1125 entityRelationService.saveRelation(relation).then(
1114 function success() { 1126 function success() {
1115 updateEntity(entity, relatedEntity, keys, deferred); 1127 updateEntity(entity, relatedEntity, keys, deferred);
@@ -1162,16 +1174,19 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -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 var searchQuery = { 1179 var searchQuery = {
1168 parameters: { 1180 parameters: {
1169 rootId: rootEntityId.id, 1181 rootId: rootEntityId.id,
1170 rootType: rootEntityId.entityType, 1182 rootType: rootEntityId.entityType,
1171 - direction: types.entitySearchDirection.from 1183 + direction: direction
1172 }, 1184 },
1173 relationType: relationType 1185 relationType: relationType
1174 }; 1186 };
  1187 + if (!direction) {
  1188 + searchQuery.parameters.direction = types.entitySearchDirection.from;
  1189 + }
1175 if (!relationType) { 1190 if (!relationType) {
1176 searchQuery.relationType = types.entityRelationType.contains; 1191 searchQuery.relationType = types.entityRelationType.contains;
1177 } 1192 }
@@ -44,16 +44,14 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity @@ -44,16 +44,14 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
44 if (!scope.allEntities) { 44 if (!scope.allEntities) {
45 entityService.getRelatedEntities(scope.rootEntityId, scope.entityType, scope.entitySubtypes, -1, []).then( 45 entityService.getRelatedEntities(scope.rootEntityId, scope.entityType, scope.entitySubtypes, -1, []).then(
46 function success(entities) { 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 scope.allEntities = entities; 56 scope.allEntities = entities;
59 filterEntities(searchText, deferred); 57 filterEntities(searchText, deferred);
@@ -116,7 +114,7 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity @@ -116,7 +114,7 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
116 rootEntityId: '=', 114 rootEntityId: '=',
117 entityType: '=', 115 entityType: '=',
118 entitySubtypes: '=', 116 entitySubtypes: '=',
119 - excludeEntityId: '=?', 117 + excludeEntityIds: '=?',
120 theForm: '=?', 118 theForm: '=?',
121 tbRequired: '=?', 119 tbRequired: '=?',
122 disabled:'=ngDisabled', 120 disabled:'=ngDisabled',