feat(templates): add localized push templates and actions
Share template keys across email and push with independent editors and revisions. Render localized actions and preserve version-one delivery. Ref: IT-1627
This commit is contained in:
+2
-1
@@ -16,6 +16,7 @@ public sealed class EmailTemplateEditViewModel
|
||||
public List<EmailTemplateLanguageEditViewModel> Languages { get; set; } = [];
|
||||
public int ActiveLanguageIndex { get; set; }
|
||||
public string? KeyFilter { get; set; }
|
||||
public bool LockKey { get; set; }
|
||||
public bool IsNew => Id == null;
|
||||
public string PageTitle => IsNew ? "Create Email Template" : "Edit Email Template";
|
||||
public string PageTitle => IsNew ? "Create Template" : "Template: " + Key;
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace HrynCo.NotificationService.Web.Controllers.Admin.ViewModels;
|
||||
|
||||
public sealed class PushTemplateEditViewModel
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public Guid ServiceId { get; set; }
|
||||
public Guid Revision { get; set; }
|
||||
public string ServiceName { get; set; } = "";
|
||||
[Required, StringLength(100)]
|
||||
public string Key { get; set; } = "";
|
||||
[Required]
|
||||
public string VariablesJson { get; set; } = "[]";
|
||||
public List<PushTemplateLanguageEditViewModel> Languages { get; set; } = [];
|
||||
public int ActiveLanguageIndex { get; set; }
|
||||
public string? KeyFilter { get; set; }
|
||||
public bool LockKey { get; set; }
|
||||
public bool ConfirmDelete { get; set; }
|
||||
public bool IsNew => Id is null;
|
||||
public string PageTitle => IsNew ? "Create Template" : "Template: " + Key;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace HrynCo.NotificationService.Web.Controllers.Admin.ViewModels;
|
||||
|
||||
public sealed class PushTemplateLanguageEditViewModel : IValidatableObject
|
||||
{
|
||||
[Required, StringLength(10)]
|
||||
public string LanguageCode { get; set; } = "";
|
||||
[DisplayFormat(ConvertEmptyStringToNull = false)]
|
||||
public string Title { get; set; } = "";
|
||||
[DisplayFormat(ConvertEmptyStringToNull = false)]
|
||||
public string Body { get; set; } = "";
|
||||
[Required]
|
||||
public string ActionsJson { get; set; } = "{}";
|
||||
[BindNever]
|
||||
public bool IsPresent { get; set; }
|
||||
public bool HasContent => !string.IsNullOrWhiteSpace(Title) || !string.IsNullOrWhiteSpace(Body) || HasActions();
|
||||
|
||||
private bool HasActions()
|
||||
{
|
||||
try
|
||||
{
|
||||
var actions = DAL.Abstract.Templates.PushTemplateActionValidation.Parse(ActionsJson);
|
||||
return actions.DefaultAction is not null || actions.Buttons.Count > 0;
|
||||
}
|
||||
catch (DAL.Abstract.Templates.EmailTemplateWriteException) { return true; }
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (!HasContent) yield break;
|
||||
if (string.IsNullOrWhiteSpace(Title))
|
||||
yield return new ValidationResult("Title is required for a populated language.", [nameof(Title)]);
|
||||
if (string.IsNullOrWhiteSpace(Body))
|
||||
yield return new ValidationResult("Body is required for a populated language.", [nameof(Body)]);
|
||||
}
|
||||
}
|
||||
+1
@@ -6,5 +6,6 @@ public sealed class ServiceTemplatesViewModel
|
||||
{
|
||||
public required NotificationServiceInfo Service { get; init; }
|
||||
public string? KeyFilter { get; init; }
|
||||
public IReadOnlyList<PushTemplateDefinition> PushDefinitions { get; set; } = [];
|
||||
public IReadOnlyList<EmailTemplateDefinition> Definitions { get; set; } = [];
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
namespace HrynCo.NotificationService.Web.Controllers.Admin.ViewModels;
|
||||
|
||||
public sealed class TemplateChannelNavigationViewModel
|
||||
{
|
||||
public Guid ServiceId { get; init; }
|
||||
public string ServiceName { get; init; } = "";
|
||||
public string Key { get; init; } = "";
|
||||
public string? KeyFilter { get; init; }
|
||||
public bool IsPush { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user