Compare commits

...

1 Commits

Author SHA1 Message Date
Kevin Giszewski bbab61d416 Attempt at fixing #429 2017-09-13 12:03:21 -04:00
2 changed files with 77 additions and 66 deletions
+6 -3
View File
@@ -65,17 +65,20 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
title.value = null;
archetypeLabelService.getFieldsetTitle($scope, fieldsetConfigModel, fieldsetIndex)
.then(function(value) {
// Finished loading the title.
title.loaded = true;
title.loading = false;
title.value = value;
});
// Still loading a title, so do not return a title.
};
$scope.$on('archetypeEntityCacheUpdated', function(event, entity) {
$scope.fieldsetTitles = _.reject($scope.fieldsetTitles, function(title) {
return title.loaded;
});
});
/**
* Ensure the collection of fieldset titles is large enough to accommodate the number of fieldsets.
+71 -63
View File
@@ -6,101 +6,109 @@ angular.module('umbraco.services').factory('archetypeCacheService', function (ar
var isDatatypeLookupLoading = false;
var datatypeCache = [];
var broadcastEntityCacheUpdated = function(scope, entity) {
scope.$broadcast("archetypeEntityCacheUpdated", entity);
}
return {
getDataTypeFromCache: function(guid) {
return _.find(datatypeCache, function (dt){
return dt.dataTypeGuid == guid;
});
},
getDataTypeFromCache: function(guid) {
return _.find(datatypeCache, function (dt){
return dt.dataTypeGuid == guid;
});
},
addDatatypeToCache: function(datatype, dataTypeGuid) {
addDatatypeToCache: function(datatype, dataTypeGuid) {
var cachedDatatype = this.getDataTypeFromCache(dataTypeGuid);
if(!cachedDatatype) {
datatype.dataTypeGuid = dataTypeGuid;
datatypeCache.push(datatype);
datatype.dataTypeGuid = dataTypeGuid;
datatypeCache.push(datatype);
}
},
},
getDatatypeByGuid: function(guid) {
var cachedDatatype = this.getDataTypeFromCache(guid);
getDatatypeByGuid: function(guid) {
var cachedDatatype = this.getDataTypeFromCache(guid);
if(cachedDatatype) {
return cachedDatatype;
}
if(cachedDatatype) {
return cachedDatatype;
}
//go get it from server, but this should already be pre-populated from the directive, but I suppose I'll leave this in in case used ad-hoc
if (!isDatatypeLookupLoading) {
isDatatypeLookupLoading = true;
//go get it from server, but this should already be pre-populated from the directive, but I suppose I'll leave this in in case used ad-hoc
if (!isDatatypeLookupLoading) {
isDatatypeLookupLoading = true;
archetypePropertyEditorResource.getDataType(guid).then(function(datatype) {
archetypePropertyEditorResource.getDataType(guid).then(function(datatype) {
datatype.dataTypeGuid = guid;
datatype.dataTypeGuid = guid;
datatypeCache.push(datatype);
datatypeCache.push(datatype);
isDatatypeLookupLoading = false;
isDatatypeLookupLoading = false;
return datatype;
});
}
return datatype;
});
}
return null;
return null;
},
getEntityById: function(scope, id, type) {
var cachedEntity = _.find(entityCache, function (e){
return e.id == id;
});
getEntityById: function(scope, id, type) {
var cachedEntity = _.find(entityCache, function (e){
return e.id == id;
});
if(cachedEntity) {
return cachedEntity;
}
if(cachedEntity) {
return cachedEntity;
}
//go get it from server
if (!isEntityLookupLoading) {
isEntityLookupLoading = true;
//go get it from server
if (!isEntityLookupLoading) {
isEntityLookupLoading = true;
scope.resources.entityResource.getById(id, type).then(function(entity) {
scope.resources.entityResource.getById(id, type).then(function(entity) {
entityCache.push(entity);
entityCache.push(entity);
isEntityLookupLoading = false;
isEntityLookupLoading = false;
broadcastEntityCacheUpdated(scope, entity);
return entity;
});
}
return entity;
});
}
return null;
},
return null;
},
getEntityByUmbracoId: function(scope, udi, type) {
var cachedEntity = _.find(entityCache, function (e){
return e.udi == udi;
});
getEntityByUmbracoId: function(scope, udi, type) {
var cachedEntity = _.find(entityCache, function (e){
return e.udi == udi;
});
if(cachedEntity) {
return cachedEntity;
}
if(cachedEntity) {
return cachedEntity;
}
//go get it from server
if (!isEntityLookupLoading) {
isEntityLookupLoading = true;
//go get it from server
if (!isEntityLookupLoading) {
isEntityLookupLoading = true;
scope.resources.entityResource.getByIds([udi], type).then(function (entities) {
// prevent infinite lookups with a default entity
var entity = entities.length > 0 ? entities[0] : { udi: udi, name: "" };
scope.resources.entityResource.getByIds([udi], type).then(function (entities) {
// prevent infinite lookups with a default entity
var entity = entities.length > 0 ? entities[0] : { udi: udi, name: "" };
entityCache.push(entity);
entityCache.push(entity);
isEntityLookupLoading = false;
isEntityLookupLoading = false;
return entity;
});
}
broadcastEntityCacheUpdated(scope, entity);
return null;
}
return entity;
});
}
return null;
}
}
});