From 16823e27398824401aa81584a14d74178c614ebc Mon Sep 17 00:00:00 2001 From: dhruvb14 Date: Tue, 31 Jan 2017 22:03:57 -0500 Subject: [PATCH] Begin Implementing Mass Email Section --- Ombi.Services/Interfaces/IMassEmail.cs | 9 +++ Ombi.Services/Interfaces/IRecentlyAdded.cs | 2 +- Ombi.Services/Jobs/RecentlyAdded.cs | 10 ++- Ombi.Services/Ombi.Services.csproj | 1 + Ombi.UI/Modules/Admin/AdminModule.cs | 41 ++++++++++-- Ombi.UI/Views/Admin/NewsletterSettings.cshtml | 65 ++++++++++++++++--- 6 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 Ombi.Services/Interfaces/IMassEmail.cs diff --git a/Ombi.Services/Interfaces/IMassEmail.cs b/Ombi.Services/Interfaces/IMassEmail.cs new file mode 100644 index 000000000..f3433c5f0 --- /dev/null +++ b/Ombi.Services/Interfaces/IMassEmail.cs @@ -0,0 +1,9 @@ +using Quartz; + +namespace Ombi.Services.Jobs +{ + public interface IMassEmail + { + void MassEmailAdminTest(); + } +} \ No newline at end of file diff --git a/Ombi.Services/Interfaces/IRecentlyAdded.cs b/Ombi.Services/Interfaces/IRecentlyAdded.cs index 09a7220f5..c18ca8e27 100644 --- a/Ombi.Services/Interfaces/IRecentlyAdded.cs +++ b/Ombi.Services/Interfaces/IRecentlyAdded.cs @@ -5,7 +5,7 @@ namespace Ombi.Services.Jobs public interface IRecentlyAdded { void Execute(IJobExecutionContext context); - void Test(); + void RecentlyAddedAdminTest(); void Start(); } } \ No newline at end of file diff --git a/Ombi.Services/Jobs/RecentlyAdded.cs b/Ombi.Services/Jobs/RecentlyAdded.cs index 563dd35a5..ece148398 100644 --- a/Ombi.Services/Jobs/RecentlyAdded.cs +++ b/Ombi.Services/Jobs/RecentlyAdded.cs @@ -48,7 +48,7 @@ using Quartz; namespace Ombi.Services.Jobs { - public class RecentlyAdded : HtmlTemplateGenerator, IJob, IRecentlyAdded + public class RecentlyAdded : HtmlTemplateGenerator, IJob, IRecentlyAdded, IMassEmail { public RecentlyAdded(IPlexApi api, ISettingsService plexSettings, ISettingsService email, IJobRecord rec, @@ -105,7 +105,13 @@ namespace Ombi.Services.Jobs Start(); } - public void Test() + public void RecentlyAddedAdminTest() + { + Log.Debug("Starting Recently Added Newsletter Test"); + var settings = NewsletterSettings.GetSettings(); + Start(settings, true); + } + public void MassEmailAdminTest() { Log.Debug("Starting Test Newsletter"); var settings = NewsletterSettings.GetSettings(); diff --git a/Ombi.Services/Ombi.Services.csproj b/Ombi.Services/Ombi.Services.csproj index 1735094dd..0e47b3669 100644 --- a/Ombi.Services/Ombi.Services.csproj +++ b/Ombi.Services/Ombi.Services.csproj @@ -87,6 +87,7 @@ + diff --git a/Ombi.UI/Modules/Admin/AdminModule.cs b/Ombi.UI/Modules/Admin/AdminModule.cs index a83ff8bd1..005646165 100644 --- a/Ombi.UI/Modules/Admin/AdminModule.cs +++ b/Ombi.UI/Modules/Admin/AdminModule.cs @@ -92,6 +92,7 @@ namespace Ombi.UI.Modules.Admin private IJobRecord JobRecorder { get; } private IAnalytics Analytics { get; } private IRecentlyAdded RecentlyAdded { get; } + private IMassEmail MassEmail { get; } private ISettingsService NotifySettings { get; } private ISettingsService DiscordSettings { get; } private IDiscordApi DiscordApi { get; } @@ -222,6 +223,9 @@ namespace Ombi.UI.Modules.Admin Get["/newsletter", true] = async (x, ct) => await Newsletter(); Post["/newsletter", true] = async (x, ct) => await SaveNewsletter(); + Post["/testnewsletteradminemail"] = x => TestNewsletterAdminEmail(); + Post["/testmassadminemail"] = x => TestMassAdminEmail(); + Post["/sendmassemail"] = x => SendMassEmail(); Post["/createapikey"] = x => CreateApiKey(); @@ -246,7 +250,6 @@ namespace Ombi.UI.Modules.Admin Get["/notificationsettings", true] = async (x, ct) => await NotificationSettings(); Post["/notificationsettings"] = x => SaveNotificationSettings(); - Post["/recentlyAddedTest"] = x => RecentlyAddedTest(); } private async Task Authentication() @@ -1229,13 +1232,41 @@ namespace Ombi.UI.Modules.Admin var model = this.Bind(); return View["NotificationSettings", model]; } - - private Response RecentlyAddedTest() + + private Response TestNewsletterAdminEmail() + { + try + { + Log.Debug("Clicked Admin Newsletter Email Test"); + RecentlyAdded.RecentlyAddedAdminTest(); + return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); + } + catch (Exception e) + { + Log.Error(e); + return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message }); + } + } + private Response TestMassAdminEmail() + { + try + { + Log.Debug("Clicked Admin Mass Email Test"); + RecentlyAdded.RecentlyAddedAdminTest(); + return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); + } + catch (Exception e) + { + Log.Error(e); + return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message }); + } + } + private Response SendMassEmail() { try { - Log.Debug("Clicked TEST"); - RecentlyAdded.Test(); + Log.Debug("Clicked Send Mass Email"); + RecentlyAdded.RecentlyAddedAdminTest(); return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" }); } catch (Exception e) diff --git a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml index 898a7a761..0a1e07852 100644 --- a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml +++ b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml @@ -28,17 +28,17 @@
-
+
- You can add multiple email addresses by using the ; delimiter -
+ You can add multiple email addresses by using the ; delimiter +
- +
@@ -46,7 +46,7 @@
- +
@@ -54,6 +54,23 @@ +
+
+ Mass Email +
+ + + + Supports HTML + +
+
+
+ +
+
+
+
@@ -90,26 +107,54 @@ $('#recentlyAddedBtn').click(function (e) { e.preventDefault(); var base = '@Html.GetBaseUrl()'; - var url = createBaseUrl(base, '/admin/recentlyAddedTest'); - $('#spinner').attr("class", "fa fa-spinner fa-spin"); + var url = createBaseUrl(base, '/admin/testnewsletteradminemail'); + $('#testEmailSpinner').attr("class", "fa fa-spinner fa-spin"); + $.ajax({ + type: "post", + url: url, + dataType: "json", + success: function (response) { + if (response) { + generateNotify(response.message, "success"); + $('#testEmailSpinner').attr("class", "fa fa-check"); + } else { + + generateNotify(response.message, "danger"); + $('#testEmailSpinner').attr("class", "fa fa-times"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + $('#testEmailSpinner').attr("class", "fa fa-times"); + } + }); + }); + + $('#sendMassEmailBtn').click(function (e) { + e.preventDefault(); + var base = '@Html.GetBaseUrl()'; + var url = createBaseUrl(base, '/admin/testmassadminemail'); + $('#sendMassEmailSpinner').attr("class", "fa fa-spinner fa-spin"); $.ajax({ type: "post", url: url, + data: $("#massEmailBody").val(), dataType: "json", success: function (response) { if (response) { generateNotify(response.message, "success"); - $('#spinner').attr("class", "fa fa-check"); + $('#sendMassEmailSpinner').attr("class", "fa fa-check"); } else { generateNotify(response.message, "danger"); - $('#spinner').attr("class", "fa fa-times"); + $('#sendMassEmailSpinner').attr("class", "fa fa-times"); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); - $('#spinner').attr("class", "fa fa-times"); + $('#sendMassEmailSpinner').attr("class", "fa fa-times"); } }); });