Move filenames collection to temporary editor state container
This commit is contained in:
@@ -30,10 +30,10 @@ namespace Archetype.Models
|
||||
|
||||
public string SerializeForPersistence()
|
||||
{
|
||||
// clear the contents of the property files collections before serializing (it's temporary state data)
|
||||
foreach(var property in Fieldsets.SelectMany(f => f.Properties.Where(p => p.FileNames != null)).ToList())
|
||||
// clear the editor state before serializing (it's temporary state data)
|
||||
foreach(var property in Fieldsets.SelectMany(f => f.Properties.Where(p => p.EditorState != null)).ToList())
|
||||
{
|
||||
property.FileNames = null;
|
||||
property.EditorState = null;
|
||||
}
|
||||
|
||||
var json = JObject.Parse(JsonConvert.SerializeObject(this, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
|
||||
|
||||
@@ -26,9 +26,9 @@ namespace Archetype.Models
|
||||
[JsonProperty("dataTypeGuid")]
|
||||
internal string DataTypeGuid { get; set; }
|
||||
|
||||
// container for the names of any files selected for this property in the Umbraco backend
|
||||
[JsonProperty("fileNames")]
|
||||
internal IEnumerable<string> FileNames;
|
||||
// container for temporary editor state from the Umbraco backend
|
||||
[JsonProperty("editorState")]
|
||||
internal UmbracoEditorState EditorState { get; set; }
|
||||
|
||||
[JsonProperty("hostContentType")]
|
||||
internal PublishedContentType HostContentType { get; set; }
|
||||
@@ -92,5 +92,12 @@ namespace Archetype.Models
|
||||
|
||||
return Attempt<T>.Fail();
|
||||
}
|
||||
|
||||
internal class UmbracoEditorState
|
||||
{
|
||||
// container for the names of any files selected for a property in the Umbraco backend
|
||||
[JsonProperty("fileNames")]
|
||||
public IEnumerable<string> FileNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ namespace Archetype.PropertyEditors
|
||||
{
|
||||
if(property.Value == null || property.Value.ToString() == "")
|
||||
return string.Empty;
|
||||
;
|
||||
|
||||
var archetype = ArchetypeHelper.Instance.DeserializeJsonToArchetype(property.Value.ToString(), propertyType.DataTypeDefinitionId);
|
||||
|
||||
@@ -152,10 +151,10 @@ namespace Archetype.PropertyEditors
|
||||
// it's a nested Archetype - just pass all uploaded files to the value editor
|
||||
additionalData["files"] = uploadedFiles.ToList();
|
||||
}
|
||||
else if(propDef.FileNames != null && propDef.FileNames.Any())
|
||||
else if (propDef.EditorState != null && propDef.EditorState.FileNames != null && propDef.EditorState.FileNames.Any())
|
||||
{
|
||||
// pass the uploaded files that belongs to this property (if any) to the value editor
|
||||
var propertyFiles = propDef.FileNames.Select(f => uploadedFiles.FirstOrDefault(u => u.FileName == f)).Where(f => f != null).ToList();
|
||||
var propertyFiles = propDef.EditorState.FileNames.Select(f => uploadedFiles.FirstOrDefault(u => u.FileName == f)).Where(f => f != null).ToList();
|
||||
if(propertyFiles.Any())
|
||||
{
|
||||
additionalData["files"] = propertyFiles;
|
||||
|
||||
@@ -262,7 +262,6 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
|
||||
|
||||
// issue 114: handler for file selection
|
||||
function setFiles(files) {
|
||||
console.log("set files", files)
|
||||
// get all currently selected files from file manager
|
||||
var currentFiles = fileManager.getFiles();
|
||||
|
||||
|
||||
@@ -123,6 +123,9 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
scope.renderModel = {};
|
||||
scope.model.value = archetypeService.getFieldsetProperty(scope).value;
|
||||
|
||||
//init the property editor state
|
||||
archetypeService.getFieldsetProperty(scope).editorState = {};
|
||||
|
||||
//set the config from the prevalues
|
||||
scope.model.config = config;
|
||||
|
||||
@@ -170,11 +173,11 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
|
||||
// issue 114: handle file selection on property editors
|
||||
scope.$on("filesSelected", function (event, args) {
|
||||
// populate the fileNames collection on the property
|
||||
// populate the fileNames collection on the property editor state
|
||||
var property = archetypeService.getFieldsetProperty(scope);
|
||||
property.fileNames = [];
|
||||
property.editorState.fileNames = [];
|
||||
_.each(args.files, function (item) {
|
||||
property.fileNames.push(item.name);
|
||||
property.editorState.fileNames.push(item.name);
|
||||
});
|
||||
|
||||
// remove the files set for this property
|
||||
|
||||
Reference in New Issue
Block a user