From f1b33cf794c3745f8fdce95e75d1c2368a41bbbd Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Tue, 1 Mar 2016 23:04:56 +0000 Subject: [PATCH] added couchpotato page --- RequestPlex.UI/Bootstrapper.cs | 1 + RequestPlex.UI/Modules/AdminModule.cs | 44 +++++++----- RequestPlex.UI/RequestPlex.UI.csproj | 3 + RequestPlex.UI/Views/Admin/CouchPotato.cshtml | 69 +++++++++++++++++++ RequestPlex.UI/Views/Admin/Settings.cshtml | 16 +---- RequestPlex.UI/Views/Admin/_Sidebar.cshtml | 6 +- 6 files changed, 107 insertions(+), 32 deletions(-) create mode 100644 RequestPlex.UI/Views/Admin/CouchPotato.cshtml diff --git a/RequestPlex.UI/Bootstrapper.cs b/RequestPlex.UI/Bootstrapper.cs index 1995c6d1f..e3c6f678e 100644 --- a/RequestPlex.UI/Bootstrapper.cs +++ b/RequestPlex.UI/Bootstrapper.cs @@ -35,6 +35,7 @@ namespace RequestPlex.UI container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); container.Register, GenericRepository>(); diff --git a/RequestPlex.UI/Modules/AdminModule.cs b/RequestPlex.UI/Modules/AdminModule.cs index 7e7709d54..deba84a1d 100644 --- a/RequestPlex.UI/Modules/AdminModule.cs +++ b/RequestPlex.UI/Modules/AdminModule.cs @@ -42,29 +42,32 @@ namespace RequestPlex.UI.Modules { public class AdminModule : NancyModule { - private ISettingsService Service { get; set; } - public AdminModule(ISettingsService service) + private ISettingsService RpService { get; set; } + private ISettingsService CpService { get; set; } + public AdminModule(ISettingsService rpService, ISettingsService cpService ) : base("admin") { - Service = service; + RpService = rpService; + CpService = cpService; #if !DEBUG this.RequiresAuthentication(); #endif - Get["admin/"] = _ => Admin(); + Get["/"] = _ => Admin(); - Post["admin/"] = _ => SaveAdmin(); + Post["/"] = _ => SaveAdmin(); - Post["admin/requestauth"] = _ => RequestAuthToken(); + Post["/requestauth"] = _ => RequestAuthToken(); - Get["admin/getusers"] = _ => GetUsers(); + Get["/getusers"] = _ => GetUsers(); - Get["admin/couchpotato"] = _ => CouchPotato(); + Get["/couchpotato"] = _ => CouchPotato(); + Post["/couchpotato"] = _ => SaveCouchPotato(); } private Negotiator Admin() { dynamic model = new ExpandoObject(); - var settings = Service.GetSettings(); + var settings = RpService.GetSettings(); model = settings; return View["/Admin/Settings", model]; @@ -74,7 +77,7 @@ namespace RequestPlex.UI.Modules { var model = this.Bind(); - Service.SaveSettings(model); + RpService.SaveSettings(model); return Context.GetRedirect("~/admin"); @@ -91,11 +94,11 @@ namespace RequestPlex.UI.Modules var plex = new PlexApi(); var model = plex.GetToken(user.username, user.password); - var oldSettings = Service.GetSettings(); + var oldSettings = RpService.GetSettings(); if (oldSettings != null) { oldSettings.PlexAuthToken = model.user.authentication_token; - Service.SaveSettings(oldSettings); + RpService.SaveSettings(oldSettings); } else { @@ -103,7 +106,7 @@ namespace RequestPlex.UI.Modules { PlexAuthToken = model.user.authentication_token }; - Service.SaveSettings(newModel); + RpService.SaveSettings(newModel); } return Response.AsJson(new {Result = true, AuthToken = model.user.authentication_token}); @@ -112,20 +115,29 @@ namespace RequestPlex.UI.Modules private Response GetUsers() { - var token = Service.GetSettings().PlexAuthToken; + var token = RpService.GetSettings().PlexAuthToken; var api = new PlexApi(); var users = api.GetUsers(token); var usernames = users.User.Select(x => x.Username); return Response.AsJson(usernames); //TODO usernames are not populated. } - private Response CouchPotato() + private Negotiator CouchPotato() { dynamic model = new ExpandoObject(); + var settings = CpService.GetSettings(); + model = settings; + return View["/Admin/CouchPotato", model]; + } + private Response SaveCouchPotato() + { + var couchPotatoSettings = this.Bind(); + CpService.SaveSettings(couchPotatoSettings); - return View["/Admin/CouchPotato", model]; + return Context.GetRedirect("~/admin/couchpotato"); } + } } \ No newline at end of file diff --git a/RequestPlex.UI/RequestPlex.UI.csproj b/RequestPlex.UI/RequestPlex.UI.csproj index f2920dd7c..8d8f9deae 100644 --- a/RequestPlex.UI/RequestPlex.UI.csproj +++ b/RequestPlex.UI/RequestPlex.UI.csproj @@ -214,6 +214,9 @@ Always + + Always + web.config diff --git a/RequestPlex.UI/Views/Admin/CouchPotato.cshtml b/RequestPlex.UI/Views/Admin/CouchPotato.cshtml new file mode 100644 index 000000000..82fc522bb --- /dev/null +++ b/RequestPlex.UI/Views/Admin/CouchPotato.cshtml @@ -0,0 +1,69 @@ +@Html.Partial("/Admin/_Sidebar") +@{ + int port; + if (Model.Port == 0) + { + port = 5050; + } + else + { + port = Model.Port; + } +} +
+
+
+ CouchPotato Settings + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ + +
+ +
+
+ + +
+ +
+ +
+
+ + + + +
+
+ +
+
+
+
+
+ + diff --git a/RequestPlex.UI/Views/Admin/Settings.cshtml b/RequestPlex.UI/Views/Admin/Settings.cshtml index d128cc31c..9ee447639 100644 --- a/RequestPlex.UI/Views/Admin/Settings.cshtml +++ b/RequestPlex.UI/Views/Admin/Settings.cshtml @@ -11,18 +11,9 @@ port = Model.Port; } - if (Model.PlexAuthToken == null) - { - authToken = string.Empty; - } - else - { - authToken = Model.PlexAuthToken; - } - }
-
+
Request Plex Settings
@@ -43,7 +34,7 @@ } else { - + }
@@ -77,7 +68,7 @@
- +
@@ -135,7 +126,6 @@
-
diff --git a/RequestPlex.UI/Views/Admin/_Sidebar.cshtml b/RequestPlex.UI/Views/Admin/_Sidebar.cshtml index 9e21b91e3..f679b5fd8 100644 --- a/RequestPlex.UI/Views/Admin/_Sidebar.cshtml +++ b/RequestPlex.UI/Views/Admin/_Sidebar.cshtml @@ -1,8 +1,8 @@  \ No newline at end of file