UI: Minor updates.
This commit is contained in:
parent
2eef2c0253
commit
2441cc0ee9
@ -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 deferred = $q.defer();
|
||||||
|
|
||||||
var entitySearchQuery = constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType);
|
var entitySearchQuery = constructRelatedEntitiesSearchQuery(rootEntityId, entityType, entitySubTypes, maxLevel, relationType, direction);
|
||||||
if (!entitySearchQuery) {
|
if (!entitySearchQuery) {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
} else {
|
} else {
|
||||||
@ -930,12 +930,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation) {
|
function saveRelatedEntity(relatedEntity, parentEntityId, keys, relation, direction) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
if (!direction) {
|
||||||
|
direction = types.entitySearchDirection.from;
|
||||||
|
}
|
||||||
if (relatedEntity.id.id) {
|
if (relatedEntity.id.id) {
|
||||||
updateRelatedEntity(relatedEntity, keys, deferred, relation);
|
updateRelatedEntity(relatedEntity, keys, deferred, relation, direction);
|
||||||
} else {
|
} else {
|
||||||
addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation);
|
addRelatedEntity(relatedEntity, parentEntityId, keys, deferred, relation, direction);
|
||||||
}
|
}
|
||||||
return deferred.promise;
|
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 = {};
|
var entity = {};
|
||||||
entity.id = relatedEntity.id;
|
entity.id = relatedEntity.id;
|
||||||
entity.name = relatedEntity.name;
|
entity.name = relatedEntity.name;
|
||||||
@ -1083,13 +1086,18 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
|
|||||||
relatedEntity.id = entity.id;
|
relatedEntity.id = entity.id;
|
||||||
if (!relation) {
|
if (!relation) {
|
||||||
relation = {
|
relation = {
|
||||||
from: parentEntityId,
|
|
||||||
to: relatedEntity.id,
|
|
||||||
type: types.entityRelationType.contains
|
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(
|
entityRelationService.saveRelation(relation).then(
|
||||||
function success() {
|
function success() {
|
||||||
updateEntity(entity, relatedEntity, keys, deferred, relation);
|
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(
|
getEntityPromise(relatedEntity.id.entityType, relatedEntity.id.id, {ignoreLoading: true}).then(
|
||||||
function success(entity) {
|
function success(entity) {
|
||||||
if (relation) {
|
if (relation) {
|
||||||
|
if (direction == types.entitySearchDirection.from) {
|
||||||
relation.to = relatedEntity.id;
|
relation.to = relatedEntity.id;
|
||||||
|
} else {
|
||||||
|
relation.from = relatedEntity.id;
|
||||||
|
}
|
||||||
entityRelationService.saveRelation(relation).then(
|
entityRelationService.saveRelation(relation).then(
|
||||||
function success() {
|
function success() {
|
||||||
updateEntity(entity, relatedEntity, keys, deferred);
|
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 = {
|
var searchQuery = {
|
||||||
parameters: {
|
parameters: {
|
||||||
rootId: rootEntityId.id,
|
rootId: rootEntityId.id,
|
||||||
rootType: rootEntityId.entityType,
|
rootType: rootEntityId.entityType,
|
||||||
direction: types.entitySearchDirection.from
|
direction: direction
|
||||||
},
|
},
|
||||||
relationType: relationType
|
relationType: relationType
|
||||||
};
|
};
|
||||||
|
if (!direction) {
|
||||||
|
searchQuery.parameters.direction = types.entitySearchDirection.from;
|
||||||
|
}
|
||||||
if (!relationType) {
|
if (!relationType) {
|
||||||
searchQuery.relationType = types.entityRelationType.contains;
|
searchQuery.relationType = types.entityRelationType.contains;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,16 +44,14 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
|
|||||||
if (!scope.allEntities) {
|
if (!scope.allEntities) {
|
||||||
entityService.getRelatedEntities(scope.rootEntityId, scope.entityType, scope.entitySubtypes, -1, []).then(
|
entityService.getRelatedEntities(scope.rootEntityId, scope.entityType, scope.entitySubtypes, -1, []).then(
|
||||||
function success(entities) {
|
function success(entities) {
|
||||||
if (scope.excludeEntityId) {
|
if (scope.excludeEntityIds && scope.excludeEntityIds.length) {
|
||||||
var result = $filter('filter')(entities, {id: {id: scope.excludeEntityId.id} }, true);
|
var filteredEntities = [];
|
||||||
result = $filter('filter')(result, {id: {entityType: scope.excludeEntityId.entityType} }, true);
|
entities.forEach(function(entity) {
|
||||||
if (result && result.length) {
|
if (scope.excludeEntityIds.indexOf(entity.id.id) == -1) {
|
||||||
var excludeEntity = result[0];
|
filteredEntities.push(entity);
|
||||||
var index = entities.indexOf(excludeEntity);
|
|
||||||
if (index > -1) {
|
|
||||||
entities.splice(index, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
entities = filteredEntities;
|
||||||
}
|
}
|
||||||
scope.allEntities = entities;
|
scope.allEntities = entities;
|
||||||
filterEntities(searchText, deferred);
|
filterEntities(searchText, deferred);
|
||||||
@ -116,7 +114,7 @@ function RelatedEntityAutocomplete($compile, $templateCache, $q, $filter, entity
|
|||||||
rootEntityId: '=',
|
rootEntityId: '=',
|
||||||
entityType: '=',
|
entityType: '=',
|
||||||
entitySubtypes: '=',
|
entitySubtypes: '=',
|
||||||
excludeEntityId: '=?',
|
excludeEntityIds: '=?',
|
||||||
theForm: '=?',
|
theForm: '=?',
|
||||||
tbRequired: '=?',
|
tbRequired: '=?',
|
||||||
disabled:'=ngDisabled',
|
disabled:'=ngDisabled',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user