diff --git a/PlexRequests.Core.Tests/NotificationMessageResolverTests.cs b/PlexRequests.Core.Tests/NotificationMessageResolverTests.cs index fc52768e0..d4ccd4fed 100644 --- a/PlexRequests.Core.Tests/NotificationMessageResolverTests.cs +++ b/PlexRequests.Core.Tests/NotificationMessageResolverTests.cs @@ -43,7 +43,7 @@ namespace PlexRequests.Core.Tests var n = new NotificationMessageResolver(); var s = new NotificationSettings { - Message = new Dictionary { { NotificationType.NewRequest, new NotificationMessageContent { Body = body } } } + Message = new List { new NotificationMessage { NotificationType = NotificationType.NewRequest, Body = body } } }; var result = n.ParseMessage(s, NotificationType.NewRequest, param); @@ -56,7 +56,7 @@ namespace PlexRequests.Core.Tests var n = new NotificationMessageResolver(); var s = new NotificationSettings { - Message = new Dictionary { { NotificationType.NewRequest, new NotificationMessageContent {Subject = subject} } } + Message = new List { new NotificationMessage { NotificationType = NotificationType.NewRequest, Subject = subject }} }; var result = n.ParseMessage(s, NotificationType.NewRequest, param); diff --git a/PlexRequests.Core/NotificationMessage.cs b/PlexRequests.Core/NotificationMessage.cs new file mode 100644 index 000000000..5b897323c --- /dev/null +++ b/PlexRequests.Core/NotificationMessage.cs @@ -0,0 +1,37 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: NotificationMessage.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +using PlexRequests.Core.Models; + +namespace PlexRequests.Core +{ + public class NotificationMessage + { + public NotificationType NotificationType { get; set; } + public string Body { get; set; } + public string Subject { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/NotificationMessageResolver.cs b/PlexRequests.Core/NotificationMessageResolver.cs index 8d0734cd1..9271c7683 100644 --- a/PlexRequests.Core/NotificationMessageResolver.cs +++ b/PlexRequests.Core/NotificationMessageResolver.cs @@ -38,10 +38,11 @@ namespace PlexRequests.Core private const char EndChar = (char)125; public NotificationMessageContent ParseMessage(T notification, NotificationType type, NotificationMessageCurlys c) where T : NotificationSettings { - var content = notification.Message.FirstOrDefault(x => x.Key == type).Value; - - //if (string.IsNullOrEmpty(notificationToParse)) - // return string.Empty; + var content = notification.Message.FirstOrDefault(x => x.NotificationType == type); + if (content == null) + { + return new NotificationMessageContent(); + } return Resolve(content.Body, content.Subject, c.Curlys); } diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index a228cd255..69a511be9 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -67,6 +67,7 @@ + diff --git a/PlexRequests.Core/SettingModels/NotificationSettings.cs b/PlexRequests.Core/SettingModels/NotificationSettings.cs index 88b0f7081..e5e4702f8 100644 --- a/PlexRequests.Core/SettingModels/NotificationSettings.cs +++ b/PlexRequests.Core/SettingModels/NotificationSettings.cs @@ -34,17 +34,16 @@ namespace PlexRequests.Core.SettingModels { public NotificationSettings() { - Message = new Dictionary + Message = new List { - {NotificationType.NewRequest, new NotificationMessageContent() }, - {NotificationType.Issue, new NotificationMessageContent() }, - {NotificationType.AdminNote, new NotificationMessageContent() }, - {NotificationType.RequestApproved, new NotificationMessageContent() }, - {NotificationType.RequestAvailable, new NotificationMessageContent() }, - {NotificationType.Test, new NotificationMessageContent() }, + new NotificationMessage { NotificationType = NotificationType.NewRequest }, + new NotificationMessage { NotificationType = NotificationType.Issue }, + new NotificationMessage { NotificationType = NotificationType.AdminNote }, + new NotificationMessage { NotificationType = NotificationType.RequestApproved }, + new NotificationMessage { NotificationType = NotificationType.RequestAvailable }, }; } - public Dictionary Message { get; set; } + public List Message { get; set; } } public static class NotificationCurly diff --git a/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml b/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml index 0ea7078b1..b59b261a1 100644 --- a/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml +++ b/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml @@ -1,4 +1,7 @@ -@using PlexRequests.UI.Helpers +@using System.Linq +@using PlexRequests.Core.Models +@using PlexRequests.UI.Helpers +@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase @Html.Partial("_Sidebar") @{ int port; @@ -18,30 +21,30 @@
- - @if (Model.Enabled) - { - - } - else - { - - } - + + @if (Model.Enabled) + { + + } + else + { + + } +
- @if (Model.EnableUserEmailNotifications) - { - - } - else - { - - } - + @if (Model.EnableUserEmailNotifications) + { + + } + else + { + + } +
Please note that if user notifications is enabled, the email will get sent with the SMTP set-up below. @@ -90,6 +93,38 @@ + +
+ @for (var i = 0; i < Model.Message.Count; i++) + { +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ } +
+
@@ -102,6 +137,7 @@
+ @@ -116,10 +152,13 @@ generateNotify("You must specify a valid Port.", "warning"); return; } + var $form = $("#mainForm"); + var data = $form.serialize(); + $.ajax({ type: $form.prop("method"), - data: $form.serialize(), + data: data, url: $form.prop("action"), dataType: "json", success: function (response) {