From 9b3de7b655e07c612c824699b48a533c0448131a Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 7 Dec 2018 12:49:20 +1100 Subject: [PATCH] manually merges in publishing messaging when publishing something that has an expire date --- .../Models/ContentScheduleCollection.cs | 1 + src/Umbraco.Web.UI/Umbraco/config/lang/da.xml | 1 - src/Umbraco.Web.UI/Umbraco/config/lang/en.xml | 1 - .../Umbraco/config/lang/en_us.xml | 4 +- src/Umbraco.Web/Editors/ContentController.cs | 67 ++++++++++++++----- 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentScheduleCollection.cs b/src/Umbraco.Core/Models/ContentScheduleCollection.cs index 46813bdb45..4c06f8927d 100644 --- a/src/Umbraco.Core/Models/ContentScheduleCollection.cs +++ b/src/Umbraco.Core/Models/ContentScheduleCollection.cs @@ -169,6 +169,7 @@ namespace Umbraco.Core.Models /// Gets the schedule for a culture /// /// + /// /// public IEnumerable GetSchedule(string culture, ContentScheduleAction? action = null) { diff --git a/src/Umbraco.Web.UI/Umbraco/config/lang/da.xml b/src/Umbraco.Web.UI/Umbraco/config/lang/da.xml index 1289db1c0f..2186668c10 100644 --- a/src/Umbraco.Web.UI/Umbraco/config/lang/da.xml +++ b/src/Umbraco.Web.UI/Umbraco/config/lang/da.xml @@ -1004,7 +1004,6 @@ Mange hilsner fra Umbraco robotten og nu synligt for besøgende indtil {0} Indhold gemt Husk at publicere for at gøre det synligt for besøgende - Ændringerne bliver publiceret den {0} Send til Godkendelse Rettelser er blevet sendt til godkendelse Medie gemt diff --git a/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml b/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml index 445d3d88d2..5e22e1d689 100644 --- a/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml +++ b/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml @@ -1280,7 +1280,6 @@ To manage your website, simply open the Umbraco back office and start adding con and visible on the website until {0} Content saved Remember to publish to make changes visible - Changes will be published on {0} Sent For Approval Changes have been sent for approval Media saved diff --git a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml index 9e3c06ad3c..bfe19fe914 100644 --- a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml +++ b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml @@ -1295,13 +1295,13 @@ To manage your website, simply open the Umbraco back office and start adding con Dictionary item saved Content published and is visible on the website - and visible on the website until {0} + and visible on the website until %0% %0% documents published and visible on the website %0% published and visible on the website + %0% published and visible on the website until %1% %0% documents published for languages %1% and visible on the website Content saved Remember to publish to make changes visible - Changes will be published on {0} A schedule for publishing has been updated %0% saved Sent For Approval diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 53ecddd015..e80281e9de 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -739,11 +739,12 @@ namespace Umbraco.Web.Editors case ContentSaveAction.PublishNew: { var publishStatus = PublishInternal(contentItem, out wasCancelled, out var successfulCultures); + //global notifications - AddMessageForPublishStatus(new[] { publishStatus }, globalNotifications, successfulCultures); + AddMessageForPublishStatus(new[] { publishStatus }, globalNotifications, successfulCultures, contentItem.PersistedContent.ContentSchedule); //variant specific notifications foreach (var c in successfulCultures) - AddMessageForPublishStatus(new[] { publishStatus }, notifications.GetOrCreate(c), successfulCultures); + AddMessageForPublishStatus(new[] { publishStatus }, notifications.GetOrCreate(c), successfulCultures, contentItem.PersistedContent.ContentSchedule); } break; case ContentSaveAction.PublishWithDescendants: @@ -1153,7 +1154,6 @@ namespace Umbraco.Web.Editors /// Performs the publishing operation for a content item /// /// - /// /// /// /// if the content is variant this will return an array of cultures that will be published (passed validation rules) @@ -1863,12 +1863,13 @@ namespace Umbraco.Web.Editors /// /// Adds notification messages to the outbound display model for a given published status /// - /// + /// /// /// - /// This is null when dealing with invariant content, else it's the cultures that were succesfully published + /// This is null when dealing with invariant content, else it's the cultures that were succesfully published /// - private void AddMessageForPublishStatus(IEnumerable statuses, INotificationModel display, string[] successfulCultures = null) + /// + private void AddMessageForPublishStatus(IEnumerable statuses, INotificationModel display, string[] successfulCultures = null, ContentScheduleCollection contentSchedule = null) { var totalStatusCount = statuses.Count(); @@ -1914,21 +1915,57 @@ namespace Umbraco.Web.Editors var itemCount = status.Count(); if (totalStatusCount == 1 || totalStatusCount == itemCount) { + //inline method to output the messages for variants + void AddNotificationForVariants(IEnumerable cultures, ContentSchedule[] expire) + { + foreach (var c in cultures) + { + var expires = expire.FirstOrDefault(x => x.Culture.InvariantEquals(c)); + display.AddSuccessNotification( + Services.TextService.Localize("speechBubbles/editContentPublishedHeader"), + expires == null + ? Services.TextService.Localize("speechBubbles/editVariantPublishedText", new[] {_allLangs.Value[c].CultureName}) + : Services.TextService.Localize("speechBubbles/editVariantPublishedTextWithExpireDateText", new[] + { + _allLangs.Value[c].CultureName, + $"{expires.Date.ToLongDateString()} {expires.Date:HH:mm}" + })); + } + } + + //check the content schedule and get the release dates for all cultures (and use string.Empty if invariant) + var expireDates = contentSchedule == null + ? Array.Empty() + : (successfulCultures == null || successfulCultures.Length == 0 ? new[] { string.Empty } : successfulCultures) + .SelectMany(x => contentSchedule.GetSchedule(x, ContentScheduleAction.Expire)).ToArray(); + if (successfulCultures == null || totalStatusCount == itemCount) { //either invariant single publish, or bulk publish where all statuses are already published - display.AddSuccessNotification( - Services.TextService.Localize("speechBubbles/editContentPublishedHeader"), - Services.TextService.Localize("speechBubbles/editContentPublishedText")); + + if (expireDates.Length == 0) + { + //normal status, no release dates + display.AddSuccessNotification( + Services.TextService.Localize("speechBubbles/editContentPublishedHeader"), + Services.TextService.Localize("speechBubbles/editContentPublishedText")); + } + else if (successfulCultures == null) + { + //this is invariant with a release date + display.AddSuccessNotification( + Services.TextService.Localize("speechBubbles/editContentPublishedHeader"), + Services.TextService.Localize("speechBubbles/editContentPublishedWithExpireDateText", new[] {$"{expireDates[0].Date.ToLongDateString()} {expireDates[0].Date:HH:mm}"})); + } + else + { + //this is variant with release dates + AddNotificationForVariants(successfulCultures, expireDates); + } } else { - foreach (var c in successfulCultures) - { - display.AddSuccessNotification( - Services.TextService.Localize("speechBubbles/editContentPublishedHeader"), - Services.TextService.Localize("speechBubbles/editVariantPublishedText", new[] { _allLangs.Value[c].CultureName })); - } + AddNotificationForVariants(successfulCultures, expireDates); } } }