Add original entity field to datasource.

This commit is contained in:
Igor Kulikov 2018-11-23 12:54:16 +02:00
parent d7a23f4048
commit 63f73c9d1e
2 changed files with 42 additions and 12 deletions

View File

@ -143,6 +143,11 @@ export default class AliasController {
for (var i=0;i<resolvedEntities.length;i++) {
var resolvedEntity = resolvedEntities[i];
newDatasource = angular.copy(datasource);
if (resolvedEntity.origEntity) {
newDatasource.entity = angular.copy(resolvedEntity.origEntity);
} else {
newDatasource.entity = {};
}
newDatasource.entityId = resolvedEntity.id;
newDatasource.entityType = resolvedEntity.entityType;
newDatasource.entityName = resolvedEntity.name;
@ -164,6 +169,11 @@ export default class AliasController {
} else {
var entity = aliasInfo.currentEntity;
if (entity) {
if (entity.origEntity) {
datasource.entity = angular.copy(entity.origEntity);
} else {
datasource.entity = {};
}
datasource.entityId = entity.id;
datasource.entityType = entity.entityType;
datasource.entityName = entity.name;

View File

@ -344,17 +344,21 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
}
function entityToEntityInfo(entity) {
return { name: entity.name, entityType: entity.id.entityType, id: entity.id.id, entityDescription: entity.additionalInfo?entity.additionalInfo.description:"" };
return { origEntity: entity, name: entity.name, entityType: entity.id.entityType, id: entity.id.id, entityDescription: entity.additionalInfo?entity.additionalInfo.description:"" };
}
function entityRelationInfoToEntityInfo(entityRelationInfo, direction) {
var deferred = $q.defer();
var entityId = direction == types.entitySearchDirection.from ? entityRelationInfo.to : entityRelationInfo.from;
var name = direction == types.entitySearchDirection.from ? entityRelationInfo.toName : entityRelationInfo.fromName;
return {
name: name,
entityType: entityId.entityType,
id: entityId.id
};
getEntity(entityId.entityType, entityId.id, {ignoreLoading: true}).then(
function success(entity) {
deferred.resolve(entityToEntityInfo(entity));
},
function fail() {
deferred.reject();
}
);
return deferred.promise;
}
function entitiesToEntitiesInfo(entities) {
@ -368,13 +372,22 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
}
function entityRelationInfosToEntitiesInfo(entityRelations, direction) {
var entitiesInfo = [];
var deferred = $q.defer();
var entitiesInfoTaks = [];
if (entityRelations) {
for (var d = 0; d < entityRelations.length; d++) {
entitiesInfo.push(entityRelationInfoToEntityInfo(entityRelations[d], direction));
entitiesInfoTaks.push(entityRelationInfoToEntityInfo(entityRelations[d], direction));
}
}
return entitiesInfo;
$q.all(entitiesInfoTaks).then(
function success(entitiesInfo) {
deferred.resolve(entitiesInfo);
},
function fail() {
deferred.reject();
}
);
return deferred.promise;
}
@ -581,8 +594,15 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
var limit = Math.min(allRelations.length, maxItems);
allRelations.length = limit;
}
result.entities = entityRelationInfosToEntitiesInfo(allRelations, filter.direction);
deferred.resolve(result);
entityRelationInfosToEntitiesInfo(allRelations, filter.direction).then(
function success(entities) {
result.entities = entities;
deferred.resolve(result);
},
function fail() {
deferred.reject();
}
);
} else {
deferred.reject();
}