mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Reworked the custom notifications... again. Need to figure out how to find the view to the model
This commit is contained in:
parent
f0ce5556c3
commit
a19e81d1f8
6 changed files with 112 additions and 35 deletions
|
@ -43,7 +43,7 @@ namespace PlexRequests.Core.Tests
|
||||||
var n = new NotificationMessageResolver();
|
var n = new NotificationMessageResolver();
|
||||||
var s = new NotificationSettings
|
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);
|
var result = n.ParseMessage(s, NotificationType.NewRequest, param);
|
||||||
|
@ -56,7 +56,7 @@ namespace PlexRequests.Core.Tests
|
||||||
var n = new NotificationMessageResolver();
|
var n = new NotificationMessageResolver();
|
||||||
var s = new NotificationSettings
|
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);
|
var result = n.ParseMessage(s, NotificationType.NewRequest, param);
|
||||||
|
|
37
PlexRequests.Core/NotificationMessage.cs
Normal file
37
PlexRequests.Core/NotificationMessage.cs
Normal file
|
@ -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;
|
private const char EndChar = (char)125;
|
||||||
public NotificationMessageContent ParseMessage<T>(T notification, NotificationType type, NotificationMessageCurlys c) where T : NotificationSettings
|
public NotificationMessageContent ParseMessage<T>(T notification, NotificationType type, NotificationMessageCurlys c) where T : NotificationSettings
|
||||||
{
|
{
|
||||||
var content = notification.Message.FirstOrDefault(x => x.Key == type).Value;
|
var content = notification.Message.FirstOrDefault(x => x.NotificationType == type);
|
||||||
|
if (content == null)
|
||||||
//if (string.IsNullOrEmpty(notificationToParse))
|
{
|
||||||
// return string.Empty;
|
return new NotificationMessageContent();
|
||||||
|
}
|
||||||
|
|
||||||
return Resolve(content.Body, content.Subject, c.Curlys);
|
return Resolve(content.Body, content.Subject, c.Curlys);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CacheKeys.cs" />
|
<Compile Include="CacheKeys.cs" />
|
||||||
|
<Compile Include="NotificationMessage.cs" />
|
||||||
<Compile Include="NotificationMessageContent.cs" />
|
<Compile Include="NotificationMessageContent.cs" />
|
||||||
<Compile Include="NotificationMessageCurlys.cs" />
|
<Compile Include="NotificationMessageCurlys.cs" />
|
||||||
<Compile Include="NotificationMessageResolver.cs" />
|
<Compile Include="NotificationMessageResolver.cs" />
|
||||||
|
|
|
@ -34,17 +34,16 @@ namespace PlexRequests.Core.SettingModels
|
||||||
{
|
{
|
||||||
public NotificationSettings()
|
public NotificationSettings()
|
||||||
{
|
{
|
||||||
Message = new Dictionary<NotificationType, NotificationMessageContent>
|
Message = new List<NotificationMessage>
|
||||||
{
|
{
|
||||||
{NotificationType.NewRequest, new NotificationMessageContent() },
|
new NotificationMessage { NotificationType = NotificationType.NewRequest },
|
||||||
{NotificationType.Issue, new NotificationMessageContent() },
|
new NotificationMessage { NotificationType = NotificationType.Issue },
|
||||||
{NotificationType.AdminNote, new NotificationMessageContent() },
|
new NotificationMessage { NotificationType = NotificationType.AdminNote },
|
||||||
{NotificationType.RequestApproved, new NotificationMessageContent() },
|
new NotificationMessage { NotificationType = NotificationType.RequestApproved },
|
||||||
{NotificationType.RequestAvailable, new NotificationMessageContent() },
|
new NotificationMessage { NotificationType = NotificationType.RequestAvailable },
|
||||||
{NotificationType.Test, new NotificationMessageContent() },
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public Dictionary<NotificationType, NotificationMessageContent> Message { get; set; }
|
public List<NotificationMessage> Message { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NotificationCurly
|
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")
|
@Html.Partial("_Sidebar")
|
||||||
@{
|
@{
|
||||||
int port;
|
int port;
|
||||||
|
@ -18,30 +21,30 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
|
|
||||||
@if (Model.Enabled)
|
@if (Model.Enabled)
|
||||||
{
|
{
|
||||||
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><label for="Enabled">Enabled</label>
|
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><label for="Enabled">Enabled</label>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<input type="checkbox" id="Enabled" name="Enabled"><label for="Enabled">Enabled</label>
|
<input type="checkbox" id="Enabled" name="Enabled"><label for="Enabled">Enabled</label>
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
|
|
||||||
@if (Model.EnableUserEmailNotifications)
|
@if (Model.EnableUserEmailNotifications)
|
||||||
{
|
{
|
||||||
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications" checked="checked"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
|
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications" checked="checked"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
|
<input type="checkbox" id="EnableUserEmailNotifications" name="EnableUserEmailNotifications"><label for="EnableUserEmailNotifications">Enable user email notifications</label>
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<small>Please note that if user notifications is enabled, the email will get sent with the SMTP set-up below.</small>
|
<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>
|
||||||
</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 class="form-group">
|
||||||
<div>
|
<div>
|
||||||
<button id="testEmail" type="submit" class="btn btn-primary-outline">Test <div id="spinner"></div></button>
|
<button id="testEmail" type="submit" class="btn btn-primary-outline">Test <div id="spinner"></div></button>
|
||||||
|
@ -102,6 +137,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -116,10 +152,13 @@
|
||||||
generateNotify("You must specify a valid Port.", "warning");
|
generateNotify("You must specify a valid Port.", "warning");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $form = $("#mainForm");
|
var $form = $("#mainForm");
|
||||||
|
var data = $form.serialize();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: $form.prop("method"),
|
type: $form.prop("method"),
|
||||||
data: $form.serialize(),
|
data: data,
|
||||||
url: $form.prop("action"),
|
url: $form.prop("action"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue