UI: Minor updates.

This commit is contained in:
Igor Kulikov 2017-07-04 17:49:05 +03:00
parent 2eef2c0253
commit 2441cc0ee9
2 changed files with 37 additions and 24 deletions

View File

@ -892,10 +892,10 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
}
}
function getRelatedEntities(rootEntityId, entityType, entitySubTypes, maxLevel, keys, typeTranslatePrefix, relationType) {
function getRelatedEntities(rootEntityId, entityType, entitySubTypes, maxLevel, keys, typeTranslatePrefix, relationType, direction) {
var deferred = $q.defer();
var entitySearchQuery = constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType);
var entitySearchQuery = constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType, direction);
if (!entitySearchQuery) {
deferred.reject();
} else {
@ -930,12 +930,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
return deferred.promise;
}
function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation) {
function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation, direction) {
var deferred = $q.defer();
if (!direction) {
direction = types.entitySearchDirection.from;
}
if (relatedEntity.id.id) {
updateRelatedEntity(relatedEntity, keys, deferred, relation);
updateRelatedEntity(relatedEntity, keys, deferred, relation, direction);
} else {
addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation);
addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation, direction);
}
return deferred.promise;
}
@ -1073,7 +1076,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
}
}
function addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation) {
function addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation, direction) {
var entity = {};
entity.id = relatedEntity.id;
entity.name = relatedEntity.name;
@ -1083,13 +1086,18 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
relatedEntity.id = entity.id;
if (!relation) {
relation = {
from: parentEntityId,
to: relatedEntity.id,
type: types.entityRelationType.contains
};
} else {
relation.to = relatedEntity.id;
}
if (direction == types.entitySearchDirection.from) {
relation.from = parentEntityId;
relation.to = relatedEntity.id;
} else {
relation.from = relatedEntity.id;
relation.to = parentEntityId;
}
entityRelationService.saveRelation(relation).then(
function success() {
updateEntity(entity, relatedEntity, keys, deferred, relation);
@ -1105,11 +1113,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
);
}
function updateRelatedEntity(relatedEntity, keys, deferred, relation) {
function updateRelatedEntity(relatedEntity, keys, deferred, relation, direction) {
getEntityPromise(relatedEntity.id.entityType, relatedEntity.id.id, {ignoreLoading: true}).then(
function success(entity) {
if (relation) {
relation.to = relatedEntity.id;
if (direction == types.entitySearchDirection.from) {
relation.to = relatedEntity.id;
} else {
relation.from = relatedEntity.id;
}
entityRelationService.saveRelation(relation).then(
function success() {
updateEntity(entity, relatedEntity, keys, deferred);
@ -1162,16 +1174,19 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
);
}
function constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType) {
function constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType, direction) {
var searchQuery = {
parameters: {
rootId: rootEntityId.id,
rootType: rootEntityId.entityType,
direction: types.entitySearchDirection.from
direction: direction
},
relationType: relationType
};
if (!direction) {
searchQuery.parameters.direction = types.entitySearchDirection.from;
}
if (!relationType) {
searchQuery.relationType = types.entityRelationType.contains;
}

View File

@ -44,16 +44,14 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
if (!scope.allEntities) {
entityService.getRelatedEntities(scope.rootEntityId, scope.entityType, scope.entitySubtypes, -1, []).then(
function success(entities) {
if (scope.excludeEntityId) {
var result = $filter('filter')(entities, {id: {id: scope.excludeEntityId.id} }, true);
result = $filter('filter')(result, {id: {entityType: scope.excludeEntityId.entityType} }, true);
if (result && result.length) {
var excludeEntity = result[0];
var index = entities.indexOf(excludeEntity);
if (index > -1) {
entities.splice(index, 1);
if (scope.excludeEntityIds && scope.excludeEntityIds.length) {
var filteredEntities = [];
entities.forEach(function(entity) {
if (scope.excludeEntityIds.indexOf(entity.id.id) == -1) {
filteredEntities.push(entity);
}
}
});
entities = filteredEntities;
}
scope.allEntities = entities;
filterEntities(searchText, deferred);
@ -116,7 +114,7 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
rootEntityId: '=',
entityType: '=',
entitySubtypes: '=',
excludeEntityId: '=?',
excludeEntityIds: '=?',
theForm: '=?',
tbRequired: '=?',
disabled:'=ngDisabled',