Gets success notifications showing in the save/publish dialogs

This commit is contained in:
Shannon
2018-09-04 16:16:11 +10:00
parent f9657ae04d
commit 3f4e6dfce8
11 changed files with 139 additions and 46 deletions

View File

@@ -8,6 +8,7 @@ using System.Text;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.ModelBinding;
using System.Web.Http.ValueProviders;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Logging;
@@ -644,7 +645,12 @@ namespace Umbraco.Web.Editors
bool wasCancelled;
//used to track successful notifications
var notifications = new SimpleNotificationModel();
var globalNotifications = new SimpleNotificationModel();
var notifications = new Dictionary<string, SimpleNotificationModel>
{
//global (non variant specific) notifications
[string.Empty] = globalNotifications
};
switch (contentItem.Action)
{
@@ -659,14 +665,14 @@ namespace Umbraco.Web.Editors
var cultureErrors = ModelState.GetCulturesWithPropertyErrors();
foreach (var c in contentItem.Variants.Where(x => x.Save && !cultureErrors.Contains(x.Culture)).Select(x => x.Culture).ToArray())
{
notifications.AddSuccessNotification(
Services.TextService.Localize("speechBubbles/editVariantSavedHeader", new[] {_allLangs.Value[c].CultureName}),
Services.TextService.Localize("speechBubbles/editContentSavedText"));
AddSuccessNotification(notifications, c,
Services.TextService.Localize("speechBubbles/editContentSavedHeader"),
Services.TextService.Localize("speechBubbles/editVariantSavedText", new[] {_allLangs.Value[c].CultureName}));
}
}
else if (ModelState.IsValid)
{
notifications.AddSuccessNotification(
globalNotifications.AddSuccessNotification(
Services.TextService.Localize("speechBubbles/editContentSavedHeader"),
Services.TextService.Localize("speechBubbles/editContentSavedText"));
}
@@ -683,14 +689,14 @@ namespace Umbraco.Web.Editors
var cultureErrors = ModelState.GetCulturesWithPropertyErrors();
foreach (var c in contentItem.Variants.Where(x => x.Save && !cultureErrors.Contains(x.Culture)).Select(x => x.Culture).ToArray())
{
notifications.AddSuccessNotification(
AddSuccessNotification(notifications, c,
Services.TextService.Localize("speechBubbles/editContentSendToPublish"),
Services.TextService.Localize("speechBubbles/editVariantSendToPublishText", new[] { _allLangs.Value[c].CultureName }));
}
}
else if (ModelState.IsValid)
{
notifications.AddSuccessNotification(
globalNotifications.AddSuccessNotification(
Services.TextService.Localize("speechBubbles/editContentSendToPublish"),
Services.TextService.Localize("speechBubbles/editContentSendToPublishText"));
}
@@ -699,7 +705,13 @@ namespace Umbraco.Web.Editors
case ContentSaveAction.Publish:
case ContentSaveAction.PublishNew:
PublishInternal(contentItem, ref publishStatus, out wasCancelled, out var successfulCultures);
AddMessageForPublishStatus(publishStatus, notifications, successfulCultures);
//global notifications
AddMessageForPublishStatus(publishStatus, globalNotifications, successfulCultures);
//variant specific notifications
foreach (var c in successfulCultures)
{
AddMessageForPublishStatus(publishStatus, notifications.GetOrCreate(c), successfulCultures);
}
break;
default:
throw new ArgumentOutOfRangeException();
@@ -709,7 +721,12 @@ namespace Umbraco.Web.Editors
var display = MapToDisplay(contentItem.PersistedContent);
//merge the tracked success messages with the outgoing model
display.Notifications.AddRange(notifications.Notifications);
display.Notifications.AddRange(globalNotifications.Notifications);
foreach (var v in display.Variants)
{
if (notifications.TryGetValue(v.Language.IsoCode, out var n))
v.Notifications.AddRange(n.Notifications);
}
//lasty, if it is not valid, add the modelstate to the outgoing object and throw a 403
HandleInvalidModelState(display);
@@ -731,6 +748,25 @@ namespace Umbraco.Web.Editors
return display;
}
/// <summary>
/// Used to add success notifications globally and for the culture
/// </summary>
/// <param name="notifications"></param>
/// <param name="culture"></param>
/// <param name="header"></param>
/// <param name="msg"></param>
/// <remarks>
/// global notifications will be shown if all variant processing is successful and the save/publish dialog is closed, otherwise
/// variant specific notifications are used to show success messagse in the save/publish dialog.
/// </remarks>
private static void AddSuccessNotification(IDictionary<string, SimpleNotificationModel> notifications, string culture, string header, string msg)
{
//add the global notification (which will display globally if all variants are successfully processed)
notifications[string.Empty].AddSuccessNotification(header, msg);
//add the variant specific notification (which will display in the dialog if all variants are not successfully processed)
notifications.GetOrCreate(culture).AddSuccessNotification(header, msg);
}
/// <summary>
/// Performs the publishing operation for a content item
/// </summary>
@@ -1412,8 +1448,8 @@ namespace Umbraco.Web.Editors
foreach (var c in successfulCultures)
{
display.AddSuccessNotification(
Services.TextService.Localize("speechBubbles/editVariantContentPublishedHeader", new[]{ _allLangs.Value[c].CultureName}),
Services.TextService.Localize("speechBubbles/editContentPublishedText"));
Services.TextService.Localize("speechBubbles/editContentPublishedHeader"),
Services.TextService.Localize("speechBubbles/editVariantPublishedText", new[] { _allLangs.Value[c].CultureName }));
}
}
break;

View File

@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
@@ -12,11 +13,12 @@ namespace Umbraco.Web.Models.ContentEditing
/// Represents the variant info for a content item
/// </summary>
[DataContract(Name = "contentVariant", Namespace = "")]
public class ContentVariantDisplay : ITabbedContent<ContentPropertyDisplay>, IContentProperties<ContentPropertyDisplay>
public class ContentVariantDisplay : ITabbedContent<ContentPropertyDisplay>, IContentProperties<ContentPropertyDisplay>, INotificationModel
{
public ContentVariantDisplay()
{
Tabs = new List<Tab<ContentPropertyDisplay>>();
Notifications = new List<Notification>();
}
[DataMember(Name = "name", IsRequired = true)]
@@ -59,6 +61,16 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "publishDate")]
public DateTime? PublishDate { 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>
/// <remarks>
/// The notifications assigned to a variant are currently only used to show custom messagse in the save/publish dialogs.
/// </remarks>
[DataMember(Name = "notifications")]
[ReadOnly(true)]
public List<Notification> Notifications { get; private set; }
}
}

View File

@@ -20,9 +20,12 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "header")]
public string Header { get; set; }
[DataMember(Name = "message")]
public string Message { get; set; }
[DataMember(Name = "type")]
public SpeechBubbleIcon NotificationType { get; set; }
}
}