From c3e773b5985c05d92dd1d212cb82b4f68912ff7d Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 12 Aug 2013 16:45:00 +1000 Subject: [PATCH] Wires up release and expire dates to be persisted, template is wired up but need to get the picker rendering. --- .../src/common/mocks/resources/_utils.js | 4 ++-- .../src/common/services/util.service.js | 19 ++++++++++++++++ .../templatepicker/templatepicker.html | 2 +- src/Umbraco.Web/Editors/ContentController.cs | 22 ++++++++++++++++--- src/Umbraco.Web/Editors/MediaController.cs | 2 +- .../ContentEditing/ContentItemDisplay.cs | 21 ++++++++++++++++-- .../Models/ContentEditing/ContentItemSave.cs | 15 ++++++++++++- .../Models/Mapping/ContentModelMapper.cs | 22 +++++++++---------- 8 files changed, 86 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/mocks/resources/_utils.js b/src/Umbraco.Web.UI.Client/src/common/mocks/resources/_utils.js index f8ecb582ea..1eb4460da8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/mocks/resources/_utils.js +++ b/src/Umbraco.Web.UI.Client/src/common/mocks/resources/_utils.js @@ -104,11 +104,11 @@ description: 'Date/time to un-publish this document', value: new Date().toIsoDateTimeString(), view: "datepicker", - alias: "_umb_removedate" + alias: "_umb_expiredate" }, { label: 'Template', - value: "1234", + value: "{id: 1234, alias: 'myTemplate', name: 'My Template'}", view: "templatepicker", alias: "_umb_template" }, diff --git a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js index e5393069c9..d7297da114 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js @@ -276,6 +276,7 @@ angular.module('umbraco.services').factory('umbImageHelper', umbImageHelper); **/ function umbDataFormatter() { return { + /** formats the display model used to display the content to the model used to save the content */ formatContentPostData: function (displayModel, action) { //NOTE: the display model inherits from the save model so we can in theory just post up the display model but @@ -289,6 +290,7 @@ function umbDataFormatter() { //set the action on the save model action: action }; + _.each(displayModel.tabs, function (tab) { _.each(tab.properties, function (prop) { @@ -301,6 +303,23 @@ function umbDataFormatter() { value: prop.value }); } + else { + //here we need to map some of our internal properties to the content save item + + switch (prop.alias) { + case "_umb_expiredate": + saveModel.expireDate = prop.value; + break; + case "_umb_releasedate": + saveModel.releaseDate = prop.value; + break; + case "_umb_template": + //this will be a json string + var json = angular.toJson(prop.value); + saveModel.templateAlias = json.alias; + break; + } + } }); }); diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/templatepicker/templatepicker.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/templatepicker/templatepicker.html index ebd32d0748..c974776bae 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/templatepicker/templatepicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/templatepicker/templatepicker.html @@ -1,4 +1,4 @@
TODO: Implement this picker
-
+
{{model.value | json}}
\ No newline at end of file diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 9ccb07b99c..c64e035b79 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -192,7 +192,23 @@ namespace Umbraco.Web.Editors //TODO: We need to support 'send to publish' //TODO: We'll need to save the new template, publishat, etc... values here - + contentItem.PersistedContent.ExpireDate = contentItem.ExpireDate; + contentItem.PersistedContent.ReleaseDate = contentItem.ReleaseDate; + //only set the template if it didn't change + if (contentItem.PersistedContent.Template.Alias != contentItem.TemplateAlias) + { + var template = Services.FileService.GetTemplate(contentItem.TemplateAlias); + if (template == null) + { + //ModelState.AddModelError("Template", "No template exists with the specified alias: " + contentItem.TemplateAlias); + LogHelper.Warn("No template exists with the specified alias: " + contentItem.TemplateAlias); + } + else + { + contentItem.PersistedContent.Template = template; + } + } + MapPropertyValues(contentItem); //We need to manually check the validation results here because: @@ -232,12 +248,12 @@ namespace Umbraco.Web.Editors if (contentItem.Action == ContentSaveAction.Save || contentItem.Action == ContentSaveAction.SaveNew) { //save the item - Services.ContentService.Save(contentItem.PersistedContent); + Services.ContentService.Save(contentItem.PersistedContent, (int)Security.CurrentUser.Id); } else { //publish the item and check if it worked, if not we will show a diff msg below - publishStatus = ((ContentService)Services.ContentService).SaveAndPublishInternal(contentItem.PersistedContent); + publishStatus = ((ContentService)Services.ContentService).SaveAndPublishInternal(contentItem.PersistedContent, (int)Security.CurrentUser.Id); } diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index af6e1f8512..7c04ecc434 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -157,7 +157,7 @@ namespace Umbraco.Web.Editors } //save the item - Services.MediaService.Save(contentItem.PersistedContent); + Services.MediaService.Save(contentItem.PersistedContent, (int)Security.CurrentUser.Id); //return the updated model var display = Mapper.Map(contentItem.PersistedContent); diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentItemDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/ContentItemDisplay.cs index 5ca8ed6f6a..57bfcbe006 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentItemDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentItemDisplay.cs @@ -5,6 +5,7 @@ using System.Runtime.Serialization; using System.Web.Http; using System.Web.Http.ModelBinding; using Umbraco.Core.Models; +using Umbraco.Core.Models.Validation; namespace Umbraco.Web.Models.ContentEditing { @@ -22,13 +23,29 @@ namespace Umbraco.Web.Models.ContentEditing public DateTime? ReleaseDate { get; set; } [DataMember(Name = "removeDate")] - public DateTime? RemoveDate { get; set; } + public DateTime? ExpireDate { get; set; } [DataMember(Name = "template")] - public string Template { get; set; } + public TemplateBasic Template { get; set; } [DataMember(Name = "urls")] public string[] Urls { get; set; } } + + [DataContract(Name = "template", Namespace = "")] + public class TemplateBasic + { + [DataMember(Name = "id", IsRequired = true)] + [Required] + public int Id { get; set; } + + [DataMember(Name = "name", IsRequired = true)] + [Required(AllowEmptyStrings = false)] + public string Name { get; set; } + + [DataMember(Name = "alias", IsRequired = true)] + [Required(AllowEmptyStrings = false)] + public string Alias { get; set; } + } } \ No newline at end of file diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentItemSave.cs b/src/Umbraco.Web/Models/ContentEditing/ContentItemSave.cs index b462c75280..9c04a3adcf 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentItemSave.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentItemSave.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Runtime.Serialization; using Newtonsoft.Json; using System.ComponentModel.DataAnnotations; @@ -25,6 +26,18 @@ namespace Umbraco.Web.Models.ContentEditing [Required] public ContentSaveAction Action { get; set; } + /// + /// The template alias to save + /// + [DataMember(Name = "templateAlias")] + public string TemplateAlias { get; set; } + + [DataMember(Name = "releaseDate")] + public DateTime? ReleaseDate { get; set; } + + [DataMember(Name = "expireDate")] + public DateTime? ExpireDate { get; set; } + /// /// The collection of files uploaded /// diff --git a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs index 0c2ed6830b..bdcaa6de7c 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using AutoMapper; +using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.Mapping; @@ -44,13 +45,12 @@ namespace Umbraco.Web.Models.Mapping expression => expression.MapFrom(content => GetPublishedDate(content, applicationContext))) .ForMember( dto => dto.Template, - expression => expression.MapFrom(content => content.Template.Name)) - .ForMember( - dto => dto.ReleaseDate, - expression => expression.MapFrom(content => content.ReleaseDate)) - .ForMember( - dto => dto.RemoveDate, - expression => expression.MapFrom(content => content.ExpireDate)) + expression => expression.MapFrom(content => new TemplateBasic + { + Alias = content.Template.Alias, + Id = content.Template.Id, + Name = content.Template.Name + })) .ForMember( dto => dto.Urls, expression => expression.MapFrom(content => @@ -70,16 +70,16 @@ namespace Umbraco.Web.Models.Mapping }, new ContentPropertyDisplay { - Alias = string.Format("{0}removedate", Constants.PropertyEditors.InternalGenericPropertiesPrefix), + Alias = string.Format("{0}expiredate", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = ui.Text("content", "removeDate"), - Value = display.RemoveDate.HasValue ? display.RemoveDate.Value.ToIsoString() : null, + Value = display.ExpireDate.HasValue ? display.ExpireDate.Value.ToIsoString() : null, View = "datepicker" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor }, new ContentPropertyDisplay { - Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix), + Alias = string.Format("{0}template", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = "Template", //TODO: localize this? - Value = display.Template, + Value = JsonConvert.SerializeObject(display.Template), View = "templatepicker" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor }, new ContentPropertyDisplay