From 20155b5ca643813629754835b541d6465aa767c9 Mon Sep 17 00:00:00 2001 From: kjac Date: Fri, 26 Jun 2015 11:30:51 +0200 Subject: [PATCH] Move filenames collection to temporary editor state container --- .../Umbraco.Archetype/Models/ArchetypeModel.cs | 6 +++--- .../Models/ArchetypePropertyModel.cs | 13 ++++++++++--- .../PropertyEditors/ArcheTypePropertyEditor.cs | 5 ++--- app/controllers/controller.js | 1 - app/directives/archetypeproperty.js | 9 ++++++--- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs index ea0333d..975015f 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs @@ -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 })); diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs index 023ba38..34bac35 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs @@ -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 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.Fail(); } + + internal class UmbracoEditorState + { + // container for the names of any files selected for a property in the Umbraco backend + [JsonProperty("fileNames")] + public IEnumerable FileNames; + } } } diff --git a/app/Umbraco/Umbraco.Archetype/PropertyEditors/ArcheTypePropertyEditor.cs b/app/Umbraco/Umbraco.Archetype/PropertyEditors/ArcheTypePropertyEditor.cs index 64e1dee..42c5819 100644 --- a/app/Umbraco/Umbraco.Archetype/PropertyEditors/ArcheTypePropertyEditor.cs +++ b/app/Umbraco/Umbraco.Archetype/PropertyEditors/ArcheTypePropertyEditor.cs @@ -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; diff --git a/app/controllers/controller.js b/app/controllers/controller.js index 47304b4..191ba6a 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -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(); diff --git a/app/directives/archetypeproperty.js b/app/directives/archetypeproperty.js index 2f73789..e530591 100644 --- a/app/directives/archetypeproperty.js +++ b/app/directives/archetypeproperty.js @@ -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