Reworked the custom notifications... again. Need to figure out how to find the view to the model

pull/470/head
tidusjar 9 years ago
parent f0ce5556c3
commit a19e81d1f8

@ -43,7 +43,7 @@ namespace PlexRequests.Core.Tests
var n = new NotificationMessageResolver();
var s = new NotificationSettings
{
Message = new Dictionary<NotificationType, NotificationMessageContent> { { NotificationType.NewRequest, new NotificationMessageContent { Body = body } } }
Message = new List<NotificationMessage> { 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, NotificationMessageContent> { { NotificationType.NewRequest, new NotificationMessageContent {Subject = subject} } }
Message = new List<NotificationMessage> { new NotificationMessage { NotificationType = NotificationType.NewRequest, Subject = subject }}
};
var result = n.ParseMessage(s, NotificationType.NewRequest, param);

@ -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; }
}
}

@ -38,10 +38,11 @@ namespace PlexRequests.Core
private const char EndChar = (char)125;
public NotificationMessageContent ParseMessage<T>(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);
}

@ -67,6 +67,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CacheKeys.cs" />
<Compile Include="NotificationMessage.cs" />
<Compile Include="NotificationMessageContent.cs" />
<Compile Include="NotificationMessageCurlys.cs" />
<Compile Include="NotificationMessageResolver.cs" />

@ -34,17 +34,16 @@ namespace PlexRequests.Core.SettingModels
{
public NotificationSettings()
{
Message = new Dictionary<NotificationType, NotificationMessageContent>
Message = new List<NotificationMessage>
{
{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<NotificationType, NotificationMessageContent> Message { get; set; }
public List<NotificationMessage> Message { get; set; }
}
public static class NotificationCurly

@ -1,4 +1,7 @@
@using PlexRequests.UI.Helpers
@using System.Linq
@using PlexRequests.Core.Models
@using PlexRequests.UI.Helpers
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.EmailNotificationSettings>
@Html.Partial("_Sidebar")
@{
int port;
@ -18,30 +21,30 @@
<div class="form-group">
<div class="checkbox">
@if (Model.Enabled)
{
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><label for="Enabled">Enabled</label>
}
else
{
<input type="checkbox" id="Enabled" name="Enabled"><label for="Enabled">Enabled</label>
}
@if (Model.Enabled)
{
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><label for="Enabled">Enabled</label>
}
else
{
<input type="checkbox" id="Enabled" name="Enabled"><label for="Enabled">Enabled</label>
}
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.EnableUserEmailNotifications)
{
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications" checked="checked"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
}
else
{
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
}
@if (Model.EnableUserEmailNotifications)
{
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications" checked="checked"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
}
else
{
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
}
</div>
</div>
<small>Please note that if user notifications is enabled, the email will get sent with the SMTP set-up below.</small>
@ -90,6 +93,38 @@
</div>
</div>
<!--Accordion Item-->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
@for (var i = 0; i < Model.Message.Count; i++)
{
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="@(i)headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#@(i)collapseOne" aria-controls="@(i)collapseOne">
@Model.Message[i].NotificationType.ToString()
</a>
</h4>
</div>
<div id="@(i)collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="@(i)headingOne">
<div class="panel-body">
<div class="form-group">
<label for="@(Model.Message[i])" class="control-label"> @Model.Message[i].NotificationType.ToString() Subject</label>
<div>
<input type="text" class="form-control form-control-custom " id="@(Model.Message[i].Subject)" name="Message[@(i)].Subject" value="@(Model.Message[i].Subject)">
</div>
</div>
<div class="form-group">
<label for="@(Model.Message[i].Body)" class="control-label">@Model.Message[i].NotificationType.ToString() Body</label>
<div>
<input type="text" class="form-control form-control-custom " id="@(Model.Message[i].Body)" name="Message[@(i)].Body" value="@(Model.Message[i].Body)">
</div>
</div>
</div>
</div>
</div>
}
</div>
<div class="form-group">
<div>
<button id="testEmail" type="submit" class="btn btn-primary-outline">Test <div id="spinner"></div></button>
@ -102,6 +137,7 @@
</div>
</div>
</fieldset>
</form>
</div>
@ -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) {

Loading…
Cancel
Save