This commit is contained in:
perploug
2013-08-12 15:26:31 +02:00
39 changed files with 2089 additions and 1771 deletions

View File

@@ -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
{
@@ -17,6 +18,34 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "publishDate")]
public DateTime? PublishDate { get; set; }
[DataMember(Name = "releaseDate")]
public DateTime? ReleaseDate { get; set; }
[DataMember(Name = "removeDate")]
public DateTime? ExpireDate { get; set; }
[DataMember(Name = "template")]
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; }
}
}

View File

@@ -1,33 +1,39 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Models;
namespace Umbraco.Web.Models.ContentEditing
{
public abstract class ContentItemDisplayBase<T, TPersisted> : TabbedContentItem<T, TPersisted>, INotificationModel, IErrorModel
where T : ContentPropertyBasic
where TPersisted : IContentBase
{
protected ContentItemDisplayBase()
{
Notifications = new List<Notification>();
}
/// <summary>
/// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes.
/// </summary>
[DataMember(Name = "notifications")]
public List<Notification> Notifications { get; private set; }
/// <summary>
/// This is used for validation of a content item.
/// </summary>
/// <remarks>
/// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will
/// still save the item but it cannot be published. So we need a way of returning validation errors as well as the
/// updated model.
/// </remarks>
[DataMember(Name = "modelState")]
public IDictionary<string, object> Errors { get; set; }
}
}
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Models;
namespace Umbraco.Web.Models.ContentEditing
{
public abstract class ContentItemDisplayBase<T, TPersisted> : TabbedContentItem<T, TPersisted>, INotificationModel, IErrorModel
where T : ContentPropertyBasic
where TPersisted : IContentBase
{
protected ContentItemDisplayBase()
{
Notifications = new List<Notification>();
}
/// <summary>
/// The name of the content type
/// </summary>
[DataMember(Name = "contentTypeName")]
public string ContentTypeName { get; set; }
/// <summary>
/// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes.
/// </summary>
[DataMember(Name = "notifications")]
public List<Notification> Notifications { get; private set; }
/// <summary>
/// This is used for validation of a content item.
/// </summary>
/// <remarks>
/// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will
/// still save the item but it cannot be published. So we need a way of returning validation errors as well as the
/// updated model.
/// </remarks>
[DataMember(Name = "modelState")]
public IDictionary<string, object> Errors { get; set; }
}
}

View File

@@ -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; }
/// <summary>
/// The template alias to save
/// </summary>
[DataMember(Name = "templateAlias")]
public string TemplateAlias { get; set; }
[DataMember(Name = "releaseDate")]
public DateTime? ReleaseDate { get; set; }
[DataMember(Name = "expireDate")]
public DateTime? ExpireDate { get; set; }
/// <summary>
/// The collection of files uploaded
/// </summary>

View File

@@ -1,13 +1,20 @@
using System;
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;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
using umbraco;
using Umbraco.Web.Routing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Declares how model mappings for content
/// </summary>
@@ -15,6 +22,7 @@ namespace Umbraco.Web.Models.Mapping
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
//FROM IContent TO ContentItemDisplay
config.CreateMap<IContent, ContentItemDisplay>()
.ForMember(
@@ -29,11 +37,58 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(
dto => dto.ContentTypeAlias,
expression => expression.MapFrom(content => content.ContentType.Alias))
.ForMember(
dto => dto.ContentTypeName,
expression => expression.MapFrom(content => content.ContentType.Name))
.ForMember(
dto => dto.PublishDate,
expression => expression.MapFrom(content => GetPublishedDate(content, applicationContext)))
.ForMember(
dto => dto.Template,
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 =>
UmbracoContext.Current == null
? new[] {"Cannot generate urls without a current Umbraco Context"}
: content.GetContentUrls()))
.ForMember(display => display.Properties, expression => expression.Ignore())
.ForMember(display => display.Tabs, expression => expression.ResolveUsing<TabsAndPropertiesResolver>());
.ForMember(display => display.Tabs, expression => expression.ResolveUsing<TabsAndPropertiesResolver>())
.AfterMap((content, display) => TabsAndPropertiesResolver.MapGenericProperties(
content, display,
new ContentPropertyDisplay
{
Alias = string.Format("{0}releasedate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = ui.Text("content", "releaseDate"),
Value = display.ReleaseDate.HasValue ? display.ReleaseDate.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}expiredate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = ui.Text("content", "removeDate"),
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}template", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = "Template", //TODO: localize this?
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
{
Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = ui.Text("content", "urls"),
Value = string.Join(",", display.Urls),
View = "urllist" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
}));
//FROM IContent TO ContentItemBasic<ContentPropertyBasic, IContent>
config.CreateMap<IContent, ContentItemBasic<ContentPropertyBasic, IContent>>()

View File

@@ -29,9 +29,13 @@ namespace Umbraco.Web.Models.Mapping
expression => expression.MapFrom(content => content.ContentType.Icon))
.ForMember(
dto => dto.ContentTypeAlias,
expression => expression.MapFrom(content => content.ContentType.Alias))
expression => expression.MapFrom(content => content.ContentType.Alias))
.ForMember(
dto => dto.ContentTypeName,
expression => expression.MapFrom(content => content.ContentType.Name))
.ForMember(display => display.Properties, expression => expression.Ignore())
.ForMember(display => display.Tabs, expression => expression.ResolveUsing<TabsAndPropertiesResolver>());
.ForMember(display => display.Tabs, expression => expression.ResolveUsing<TabsAndPropertiesResolver>())
.AfterMap((media, display) => TabsAndPropertiesResolver.MapGenericProperties(media, display));
//FROM IMedia TO ContentItemBasic<ContentPropertyBasic, IMedia>
config.CreateMap<IMedia, ContentItemBasic<ContentPropertyBasic, IMedia>>()

View File

@@ -1,68 +1,149 @@
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates the tabs collection with properties assigned for display models
/// </summary>
internal class TabsAndPropertiesResolver : ValueResolver<IContentBase, IEnumerable<Tab<ContentPropertyDisplay>>>
{
protected override IEnumerable<Tab<ContentPropertyDisplay>> ResolveCore(IContentBase content)
{
var aggregateTabs = new List<Tab<ContentPropertyDisplay>>();
//now we need to aggregate the tabs and properties since we might have duplicate tabs (based on aliases) because
// of how content composition works.
foreach (var propertyGroups in content.PropertyGroups.GroupBy(x => x.Name))
{
var aggregateProperties = new List<ContentPropertyDisplay>();
//there will always be one group with a null parent id (the top-most)
//then we'll iterate over all of the groups and ensure the properties are
//added in order so that when they render they are rendered with highest leve
//parent properties first.
int? currentParentId = null;
for (var i = 0; i < propertyGroups.Count(); i++)
{
var current = propertyGroups.Single(x => x.ParentId == currentParentId);
aggregateProperties.AddRange(
Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(
content.GetPropertiesForGroup(current)));
currentParentId = current.Id;
}
//then we'll just use the root group's data to make the composite tab
var rootGroup = propertyGroups.Single(x => x.ParentId == null);
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = rootGroup.Id,
Alias = rootGroup.Name,
Label = rootGroup.Name,
Properties = aggregateProperties,
IsActive = false
});
}
//now add the generic properties tab for any properties that don't belong to a tab
var orphanProperties = content.GetNonGroupedProperties();
//now add the generic properties tab
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = 0,
Label = "Generic properties",
Alias = "Generic properties",
Properties = Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(orphanProperties)
});
//set the first tab to active
aggregateTabs.First().IsActive = true;
return aggregateTabs;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
using umbraco;
namespace Umbraco.Web.Models.Mapping
{
/// <summary>
/// Creates the tabs collection with properties assigned for display models
/// </summary>
internal class TabsAndPropertiesResolver : ValueResolver<IContentBase, IEnumerable<Tab<ContentPropertyDisplay>>>
{
/// <summary>
/// Maps properties on to the generic properties tab
/// </summary>
/// <param name="content"></param>
/// <param name="display"></param>
/// <param name="customProperties">
/// Any additional custom properties to assign to the generic properties tab.
/// </param>
/// <remarks>
/// The generic properties tab is mapped during AfterMap and is responsible for
/// setting up the properties such as Created date, udpated date, template selected, etc...
/// </remarks>
public static void MapGenericProperties<TPersisted>(
TPersisted content,
ContentItemDisplayBase<ContentPropertyDisplay, TPersisted> display,
params ContentPropertyDisplay[] customProperties)
where TPersisted : IContentBase
{
var genericProps = display.Tabs.Single(x => x.Id == 0);
//store the current props to append to the newly inserted ones
var currProps = genericProps.Properties.ToArray();
var labelEditor = PropertyEditorResolver.Current.GetById(new Guid(Constants.PropertyEditors.NoEdit)).ValueEditor.View;
var contentProps = new List<ContentPropertyDisplay>
{
new ContentPropertyDisplay
{
Alias = string.Format("{0}id", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = "Id",
Value = display.Id.ToInvariantString(),
View = labelEditor
},
new ContentPropertyDisplay
{
Alias = string.Format("{0}creator", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = ui.Text("content", "createBy"),
Description = "Original author", //TODO: Localize this
Value = display.Owner.Name,
View = labelEditor
},
new ContentPropertyDisplay
{
Alias = string.Format("{0}createdate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = ui.Text("content", "createDate"),
Description = "Date/time this document was created", //TODO: Localize this
Value = display.CreateDate.ToIsoString(),
View = labelEditor
},
new ContentPropertyDisplay
{
Alias = string.Format("{0}updatedate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = ui.Text("content", "updateDate"),
Description = "Date/time this document was created", //TODO: Localize this
Value = display.UpdateDate.ToIsoString(),
View = labelEditor
},
new ContentPropertyDisplay
{
Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = ui.Text("content", "documentType"),
Value = display.ContentTypeName,
View = labelEditor
}
};
//add the custom ones
contentProps.AddRange(customProperties);
//now add the user props
contentProps.AddRange(currProps);
//re-assign
genericProps.Properties = contentProps;
}
protected override IEnumerable<Tab<ContentPropertyDisplay>> ResolveCore(IContentBase content)
{
var aggregateTabs = new List<Tab<ContentPropertyDisplay>>();
//now we need to aggregate the tabs and properties since we might have duplicate tabs (based on aliases) because
// of how content composition works.
foreach (var propertyGroups in content.PropertyGroups.GroupBy(x => x.Name))
{
var aggregateProperties = new List<ContentPropertyDisplay>();
//there will always be one group with a null parent id (the top-most)
//then we'll iterate over all of the groups and ensure the properties are
//added in order so that when they render they are rendered with highest leve
//parent properties first.
int? currentParentId = null;
for (var i = 0; i < propertyGroups.Count(); i++)
{
var current = propertyGroups.Single(x => x.ParentId == currentParentId);
aggregateProperties.AddRange(
Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(
content.GetPropertiesForGroup(current)));
currentParentId = current.Id;
}
//then we'll just use the root group's data to make the composite tab
var rootGroup = propertyGroups.Single(x => x.ParentId == null);
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = rootGroup.Id,
Alias = rootGroup.Name,
Label = rootGroup.Name,
Properties = aggregateProperties,
IsActive = false
});
}
//now add the generic properties tab for any properties that don't belong to a tab
var orphanProperties = content.GetNonGroupedProperties();
//now add the generic properties tab
aggregateTabs.Add(new Tab<ContentPropertyDisplay>
{
Id = 0,
Label = "Generic properties",
Alias = "Generic properties",
Properties = Mapper.Map<IEnumerable<Property>, IEnumerable<ContentPropertyDisplay>>(orphanProperties)
});
//set the first tab to active
aggregateTabs.First().IsActive = true;
return aggregateTabs;
}
}
}