Adds state property to ContentItemBase (Not sure if this will blow things up or if I need to use a diff model for ListView children now)

Adds/copies the same logic from ContentSavedStateResolver.cs
This commit is contained in:
Warren Buckley
2018-09-12 12:08:51 +01:00
parent d39bb96056
commit 551e8120c9
2 changed files with 52 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Validation;
using Umbraco.Web.WebApi;
@@ -44,6 +45,10 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "sortOrder")]
public int SortOrder { get; set; }
[DataMember(Name = "state")]
[JsonConverter(typeof(StringEnumConverter))]
public ContentSavedState State { get; set; }
protected bool Equals(ContentItemBasic other)
{
return Id == other.Id;

View File

@@ -83,7 +83,8 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dest => dest.AdditionalData, opt => opt.Ignore())
.ForMember(dest => dest.UpdateDate, opt => opt.ResolveUsing<CultureUpdateDateResolver>())
.ForMember(dest => dest.Published, opt => opt.ResolveUsing<CulturePublishedResolver>())
.ForMember(dest => dest.Name, opt => opt.ResolveUsing<CultureNameResolver>());
.ForMember(dest => dest.Name, opt => opt.ResolveUsing<CultureNameResolver>())
.ForMember(dest => dest.State, opt => opt.ResolveUsing<CultureStateResolver>());
//FROM IContent TO ContentPropertyCollectionDto
//NOTE: the property mapping for cultures relies on a culture being set in the mapping context
@@ -91,6 +92,51 @@ namespace Umbraco.Web.Models.Mapping
}
}
internal class CultureStateResolver : IValueResolver<IContent, ContentItemBasic<ContentPropertyBasic>, ContentSavedState>
{
//WB: Note this is same logic as ContentSavedStateResolver.cs
//But this is for ContentItemBasic instead of ContentVariantDisplay
public ContentSavedState Resolve(IContent source, ContentItemBasic<ContentPropertyBasic> destination, ContentSavedState destMember, ResolutionContext context)
{
PublishedState publishedState;
bool isEdited;
if (source.ContentType.VariesByCulture())
{
//Get the culture from the context which will be set during the mapping operation for each variant
var culture = context.GetCulture();
//a culture needs to be in the context for a variant content item
if (culture == null)
throw new InvalidOperationException($"No culture found in mapping operation when one is required for a culture variant");
publishedState = source.PublishedState == PublishedState.Unpublished //if the entire document is unpublished, then flag every variant as unpublished
? PublishedState.Unpublished
: source.IsCulturePublished(culture)
? PublishedState.Published
: PublishedState.Unpublished;
isEdited = source.IsCultureEdited(culture);
}
else
{
publishedState = source.PublishedState == PublishedState.Unpublished
? PublishedState.Unpublished
: PublishedState.Published;
isEdited = source.Edited;
}
if (publishedState == PublishedState.Unpublished)
return isEdited && source.Id > 0 ? ContentSavedState.Draft : ContentSavedState.NotCreated;
if (publishedState == PublishedState.Published)
return isEdited ? ContentSavedState.PublishedPendingChanges : ContentSavedState.Published;
throw new NotSupportedException($"PublishedState {publishedState} is not supported.");
}
}
internal class CultureUpdateDateResolver : IValueResolver<IContent, ContentItemBasic<ContentPropertyBasic>, DateTime>
{
public DateTime Resolve(IContent source, ContentItemBasic<ContentPropertyBasic> destination, DateTime destMember, ResolutionContext context)