From b1d309aa16f6010887a62d7249d11eadf1a50935 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 4 Apr 2018 10:50:18 +1000 Subject: [PATCH] Some updates based on PR review notes --- .../Services/LocalizationServiceExtensions.cs | 16 ++++++++-------- .../src/common/resources/content.resource.js | 3 ++- src/Umbraco.Web/Editors/ContentController.cs | 4 +++- .../Models/ContentEditing/ContentVariation.cs | 12 ------------ .../Mapping/ContentPropertyMapperProfile.cs | 4 ++-- .../Models/Mapping/VariationResolver.cs | 7 ++----- 6 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/Umbraco.Core/Services/LocalizationServiceExtensions.cs b/src/Umbraco.Core/Services/LocalizationServiceExtensions.cs index b317b91cd5..a597b64f3b 100644 --- a/src/Umbraco.Core/Services/LocalizationServiceExtensions.cs +++ b/src/Umbraco.Core/Services/LocalizationServiceExtensions.cs @@ -14,6 +14,8 @@ namespace Umbraco.Core.Services { var langs = service.GetAllLanguages().OrderBy(x => x.Id).ToList(); + if (langs.Count == 0) return null; + //if there's only one language, by default it is the default if (langs.Count == 1) { @@ -22,15 +24,13 @@ namespace Umbraco.Core.Services return langs[0]; } - if (langs.All(x => !x.IsDefaultVariantLanguage)) - { - //if no language has the default flag, then the defaul language is the one with the lowest id - langs[0].IsDefaultVariantLanguage = true; - langs[0].Mandatory = true; - return langs[0]; - } + var foundDefault = langs.FirstOrDefault(x => x.IsDefaultVariantLanguage); + if (foundDefault != null) return foundDefault; - return langs.First(x => x.IsDefaultVariantLanguage); + //if no language has the default flag, then the defaul language is the one with the lowest id + langs[0].IsDefaultVariantLanguage = true; + langs[0].Mandatory = true; + return langs[0]; } } } diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js index 7d569f7622..fe3a86e930 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js @@ -313,7 +313,8 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { * }); * * - * @param {Int} id id of content item to return + * @param {Int} id id of content item to return + * @param {Int} languageId optional ID of the language to retrieve the item in * @returns {Promise} resourcePromise object containing the content item. * */ diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 9f1bf27cb9..39c73c812e 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -1114,7 +1114,9 @@ namespace Umbraco.Web.Editors /// private ContentItemDisplay MapToDisplay(IContent content, int? languageId = null) { - //a language must be if this content item has any property type that can be varied by language + //a languageId must exist in the mapping context if this content item has any property type that can be varied by language + //otherwise the property validation will fail since it's expecting to be get/set with a language ID. If a languageId is not explicitly + //sent up, then it means that the user is editing the default variant language. if (!languageId.HasValue && content.HasLanguageVariantPropertyType()) { languageId = Services.LocalizationService.GetDefaultVariantLanguage().Id; diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentVariation.cs b/src/Umbraco.Web/Models/ContentEditing/ContentVariation.cs index 917b701cec..daf71a9089 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentVariation.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentVariation.cs @@ -22,18 +22,6 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "segment")] public string Segment { get; set; } - //fixme not sure if we need these dates as metadata for displaying the variant info in the drop down? - // when we move to being able to edit all variants and switching then this might be irrelevant - - [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 = "state")] public string PublishedState { get; set; } diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/ContentPropertyMapperProfile.cs index 1b9b04e49a..b249760053 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentPropertyMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentPropertyMapperProfile.cs @@ -27,13 +27,13 @@ namespace Umbraco.Web.Models.Mapping .ForMember(tab => tab.Alias, expression => expression.Ignore()); //FROM Property TO ContentPropertyBasic - CreateMap().ConvertUsing((property, basic, arg3) => contentPropertyBasicConverter.Convert(property, basic, arg3)); + CreateMap().ConvertUsing(contentPropertyBasicConverter); //FROM Property TO ContentPropertyDto CreateMap().ConvertUsing(contentPropertyDtoConverter); //FROM Property TO ContentPropertyDisplay - CreateMap().ConvertUsing((property, basic, arg3) => contentPropertyDisplayConverter.Convert(property, basic, arg3)); + CreateMap().ConvertUsing(contentPropertyDisplayConverter); } } } diff --git a/src/Umbraco.Web/Models/Mapping/VariationResolver.cs b/src/Umbraco.Web/Models/Mapping/VariationResolver.cs index b7b29207bc..540323c23a 100644 --- a/src/Umbraco.Web/Models/Mapping/VariationResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/VariationResolver.cs @@ -22,17 +22,14 @@ namespace Umbraco.Web.Models.Mapping public IEnumerable Resolve(IContent source, ContentItemDisplay destination, IEnumerable destMember, ResolutionContext context) { var allLanguages = _localizationService.GetAllLanguages().OrderBy(x => x.Id).ToList(); - if (allLanguages.Count == 0) return Enumerable.Empty(); //there's only 1 language defined so we don't have language variants enabled + if (allLanguages.Count == 0) return Enumerable.Empty(); var langs = context.Mapper.Map, IEnumerable>(allLanguages, null, context); var variants = langs.Select(x => new ContentVariation { Language = x, //fixme these all need to the variant values but we need to wait for the db/service changes - Name = source.Name , - ExpireDate = source.ExpireDate, - PublishDate = source.PublishDate, - ReleaseDate = source.ReleaseDate, + Name = source.Name , Exists = source.HasVariation(x.Id), //TODO: This needs to be wired up with new APIs when they are ready PublishedState = source.PublishedState.ToString() }).ToList();