Skip to content

Commit

Permalink
added settings page for #8
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Mar 14, 2016
1 parent 5153afd commit 334a6f3
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 5 deletions.
1 change: 1 addition & 0 deletions PlexRequests.UI/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected override void ConfigureRequestContainer(TinyIoCContainer container, Na
container.Register<ISettingsService<AuthenticationSettings>, SettingsServiceV2<AuthenticationSettings>>();
container.Register<ISettingsService<PlexSettings>, SettingsServiceV2<PlexSettings>>();
container.Register<ISettingsService<SonarrSettings>, SettingsServiceV2<SonarrSettings>>();
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
container.Register<IRequestService, RequestService>();

Expand Down
28 changes: 25 additions & 3 deletions PlexRequests.UI/Modules/AdminModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class AdminModule : NancyModule
private ISettingsService<AuthenticationSettings> AuthService { get; set; }
private ISettingsService<PlexSettings> PlexService { get; set; }
private ISettingsService<SonarrSettings> SonarrService { get; set; }
private ISettingsService<EmailNotificationSettings> EmailService { get; set; }
private ISonarrApi SonarrApi { get; set; }

private static Logger Log = LogManager.GetCurrentClassLogger();
Expand All @@ -59,18 +60,20 @@ public AdminModule(ISettingsService<PlexRequestSettings> rpService,
ISettingsService<AuthenticationSettings> auth
, ISettingsService<PlexSettings> plex,
ISettingsService<SonarrSettings> sonarr,
ISonarrApi sonarrApi) : base("admin")
ISonarrApi sonarrApi,
ISettingsService<EmailNotificationSettings> email) : base("admin")
{
RpService = rpService;
CpService = cpService;
AuthService = auth;
PlexService = plex;
SonarrService = sonarr;
SonarrApi = sonarrApi;
EmailService = email;

//#if !DEBUG
#if !DEBUG
this.RequiresAuthentication();
//#endif
#endif
Get["/"] = _ => Admin();

Get["/authentication"] = _ => Authentication();
Expand All @@ -92,6 +95,9 @@ ISettingsService<AuthenticationSettings> auth
Post["/sonarr"] = _ => SaveSonarr();

Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();

Get["/emailnotification"] = _ => EmailNotifications();
Post["/emailnotification"] = _ => SaveEmailNotifications();
}

private Negotiator Authentication()
Expand Down Expand Up @@ -239,5 +245,21 @@ private Response GetSonarrQualityProfiles()
return Response.AsJson(profiles);
}


private Negotiator EmailNotifications()
{
var settings = EmailService.GetSettings();
return View["EmailNotifications",settings];
}

private Response SaveEmailNotifications()
{
var settings = this.Bind<EmailNotificationSettings>();
Log.Trace(settings.DumpJson());

var result = EmailService.SaveSettings(settings);
Log.Info("Saved email settings, result: {0}", result);
return Context.GetRedirect("~/admin/emailnotification");
}
}
}
3 changes: 3 additions & 0 deletions PlexRequests.UI/PlexRequests.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@
<Content Include="Views\Admin\Sonarr.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Admin\EmailNotifications.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>
Expand Down
7 changes: 6 additions & 1 deletion PlexRequests.UI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#endregion
using System;
using FluentScheduler;

using NLog;

using Owin;
using PlexRequests.UI.Jobs;
using TaskFactory = FluentScheduler.TaskFactory;
Expand All @@ -34,6 +37,8 @@ namespace PlexRequests.UI
{
public class Startup
{

private static Logger Log = LogManager.GetCurrentClassLogger();
public void Configuration(IAppBuilder app)
{
try
Expand All @@ -44,7 +49,7 @@ public void Configuration(IAppBuilder app)
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
Log.Fatal(exception);
throw;
}

Expand Down
92 changes: 92 additions & 0 deletions PlexRequests.UI/Views/Admin/EmailNotifications.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@Html.Partial("_Sidebar")
@{
int port;
if (Model.EmailPort == 0)
{
port = 25;
}
else
{
port = Model.EmailPort;
}
}
<div class="col-sm-8 col-sm-push-1">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset>
<legend>Email Notifications</legend>

<div class="form-group">
<div class="checkbox">
<label>
@if (Model.Enabled)
{
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><text>Enabled</text>
}
else
{
<input type="checkbox" id="Enabled" name="Enabled"><text>Enabled</text>
}
</label>
</div>
</div>
<div class="form-group">
<label for="EmailHost" class="control-label">SMTP Hostname or IP</label>
<div class="">
<input type="text" class="form-control form-control-custom " id="EmailHost" name="EmailHost" placeholder="localhost" value="@Model.EmailHost">
</div>
</div>

<div class="form-group">
<label for="EmailPort" class="control-label">SMTP Port</label>

<div class="">
<input type="text" class="form-control form-control-custom " id="EmailPort" name="EmailPort" placeholder="Port Number" value="@port">
</div>
</div>


<div class="form-group">
<label for="RecipientEmail" class="control-label">Email Recipient</label>
<div>
<input type="text" class="form-control form-control-custom " id="RecipientEmail" name="RecipientEmail" value="@Model.RecipientEmail">
</div>
</div>

<div class="form-group">
<div class="checkbox">
<label>
@if (Model.EmailAuthentication)
{
<input type="checkbox" id="EmailAuthentication" name="EmailAuthentication" checked="checked"><text>Authenticate</text>
}
else
{
<input type="checkbox" id="EmailAuthentication" name="EmailAuthentication"><text>Authenticate</text>
}
</label>
</div>
</div>

<div class="form-group">
<label for="EmailUsername" class="control-label">Username</label>
<div>
<input type="text" class="form-control form-control-custom " id="EmailUsername" name="EmailUsername" value="@Model.EmailUsername">
</div>
</div>

<div class="form-group">
<label for="EmailPassword" class="control-label">Password</label>
<div>
<input type="password" class="form-control form-control-custom " id="EmailPassword" name="EmailPassword" value="@Model.EmailPassword">
</div>
</div>


<div class="form-group">
<div>
<button type="submit" class="btn btn-primary-outline">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
10 changes: 9 additions & 1 deletion PlexRequests.UI/Views/Admin/_Sidebar.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@
else
{
<a class="list-group-item" href="/admin/sonarr">Sonarr Settings</a>

}
@*<a class="list-group-item" href="/admin/sickbeard">Sickbeard Settings</a>*@

@if (Context.Request.Path == "/admin/emailnotification")
{
<a class="list-group-item active" href="/admin/emailnotification">Email Notifications</a>
}
else
{
<a class="list-group-item" href="/admin/emailnotification">Email Notifications</a>
}
</div>
</div>

0 comments on commit 334a6f3

Please sign in to comment.