Skip to content

Commit

Permalink
Improve notification messages and localization dnnsoftware#6115
Browse files Browse the repository at this point in the history
  • Loading branch information
tvatavuk committed Oct 9, 2024
1 parent 0d4383a commit 47fc85b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@ public void DoActionOnStateChanged(StateTransaction stateTransaction)

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
{
var contentItem = GetContentItem(stateTransaction.ContentItemId);

// TODO: add real message with localization
return new ActionMessage
=> new ()
{
Subject = $"CompleteState TabAction {nameof(CompleteState)}: {contentItem.ContentTitle}",
Body = $"CompleteState TabAction {nameof(CompleteState)}...",
Subject = GetString($"{nameof(CompleteState)}{nameof(ActionMessage.Subject)}", "Page Approval"),
Body = GetString($"{nameof(CompleteState)}{nameof(ActionMessage.Body)}", "Page '{0}' is in the '{1}' state and awaits review and approval.", GetTab(stateTransaction.ContentItemId).LocalizedTabName, currentState.StateName),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@ public void DoActionOnStateChanged(StateTransaction stateTransaction)

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
{
var contentItem = GetContentItem(stateTransaction.ContentItemId);

// TODO: add real message with localization
return new ActionMessage
=> new ()
{
Subject = $"CompleteWorkflow TabAction {nameof(CompleteWorkflow)}: {contentItem.ContentTitle}",
Body = $"CompleteWorkflow TabAction {nameof(CompleteWorkflow)}...",
Subject = GetString($"{nameof(CompleteWorkflow)}{nameof(ActionMessage.Subject)}", "Page Published"),
Body = GetString($"{nameof(CompleteWorkflow)}{nameof(ActionMessage.Body)}", "Page '{0}' has been published and is now live.", GetTab(stateTransaction.ContentItemId).LocalizedTabName),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@ public void DoActionOnStateChanged(StateTransaction stateTransaction)

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
{
var contentItem = GetContentItem(stateTransaction.ContentItemId);

// TODO: add real message with localization
return new ActionMessage
=> new ()
{
Subject = $"DiscardState TabAction {nameof(DiscardState)}: {contentItem.ContentTitle}",
Body = $"DiscardState TabAction {nameof(DiscardState)}...",
Subject = GetString($"{nameof(DiscardState)}{nameof(ActionMessage.Subject)}", "Page Rejected"),
Body = GetString($"{nameof(DiscardState)}{nameof(ActionMessage.Body)}", "The edits for page '{0}' were rejected, and it is now in '{1}' state.", GetTab(stateTransaction.ContentItemId).LocalizedTabName, currentState.StateName),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,11 @@ public void DoActionOnStateChanged(StateTransaction stateTransaction)

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
{
var contentItem = GetContentItem(stateTransaction.ContentItemId);

// TODO: add real message with localization
return new ActionMessage
=> new ()
{
Subject = $"DiscardWorkflow TabAction {nameof(DiscardWorkflow)}: {contentItem.ContentTitle}",
Body = $"DiscardWorkflow TabAction {nameof(DiscardWorkflow)}...",
Subject = GetString($"{nameof(DiscardWorkflow)}{nameof(ActionMessage.Subject)}", "Page Discarded"),
Body = GetString($"{nameof(DiscardWorkflow)}{nameof(ActionMessage.Body)}", "Edits for page '{0}' have been discarded.", GetTab(stateTransaction.ContentItemId).LocalizedTabName),
};
}

/// <summary>
/// Checks if the tab has only one version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ public void DoActionOnStateChanged(StateTransaction stateTransaction)

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
{
var contentItem = GetContentItem(stateTransaction.ContentItemId);

// TODO: add real message with localization
return new ActionMessage
=> new ()
{
Subject = $"StartWorkflow TabAction {nameof(StartWorkflow)}: {contentItem.ContentTitle}",
Body = $"StartWorkflow TabAction {nameof(StartWorkflow)}...",
Subject = GetString($"{nameof(StartWorkflow)}{nameof(ActionMessage.Subject)}", "Page Submitted"),
Body = GetString($"{nameof(StartWorkflow)}{nameof(ActionMessage.Body)}", "Page '{0}' is in the '{1}' state and waiting to be submitted.", GetTab(stateTransaction.ContentItemId).LocalizedTabName, currentState.StateName),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace DotNetNuke.Entities.Content.Workflow.Actions.TabActions
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Workflow.Dto;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Localization;

/// <summary>
/// TabActions base class.
Expand Down Expand Up @@ -58,5 +59,27 @@ internal static TabInfo GetTab(int contentItemId)

return CBO.FillObject<TabInfo>(DataProvider.Instance().ExecuteSQL(Sql, parameters));
}

/// <summary>
/// Gets the localized string value for the specified key.
/// </summary>
/// <param name="key">The key of the string to retrieve.</param>
/// <param name="defaultValue">The default value to return if the string is not found.</param>
/// <returns>The localized string value.</returns>
internal static string GetString(string key, string defaultValue)
{
var content = Localization.GetString(key, Localization.GlobalResourceFile);
return string.IsNullOrEmpty(content) ? defaultValue : content;
}

/// <summary>
/// Gets the formatted localized string value for the specified key for parameters.
/// </summary>
/// <param name="key">The key of the string to retrieve.</param>
/// <param name="defaultValue">The default value to return if the string is not found.</param>
/// <param name="params">The parameters to format the string.</param>
/// <returns>The formatted localized string value.</returns>
internal static string GetString(string key, string defaultValue, params object[] @params)
=> string.Format(GetString(key, defaultValue), @params);
}
}

0 comments on commit 47fc85b

Please sign in to comment.