added couchpotato page

pull/13/head
Jamie Rees 9 years ago
parent a00d5b69f2
commit f1b33cf794

@ -35,6 +35,7 @@ namespace RequestPlex.UI
container.Register<ISettingsService<RequestPlexSettings>, SettingsServiceV2<RequestPlexSettings>>();
container.Register<ISettingsService<CouchPotatoSettings>, SettingsServiceV2<CouchPotatoSettings>>();
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();

@ -42,29 +42,32 @@ namespace RequestPlex.UI.Modules
{
public class AdminModule : NancyModule
{
private ISettingsService<RequestPlexSettings> Service { get; set; }
public AdminModule(ISettingsService<RequestPlexSettings> service)
private ISettingsService<RequestPlexSettings> RpService { get; set; }
private ISettingsService<CouchPotatoSettings> CpService { get; set; }
public AdminModule(ISettingsService<RequestPlexSettings> rpService, ISettingsService<CouchPotatoSettings> 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<RequestPlexSettings>();
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<CouchPotatoSettings>();
CpService.SaveSettings(couchPotatoSettings);
return View["/Admin/CouchPotato", model];
return Context.GetRedirect("~/admin/couchpotato");
}
}
}

@ -214,6 +214,9 @@
<Content Include="Views\Requests\Index.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Admin\CouchPotato.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>

@ -0,0 +1,69 @@
@Html.Partial("/Admin/_Sidebar")
@{
int port;
if (Model.Port == 0)
{
port = 5050;
}
else
{
port = Model.Port;
}
}
<div class="col-sm-8">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset>
<legend>CouchPotato Settings</legend>
<div class="form-group">
<label for="Enabled" class="col-lg-2 control-label">Enable CouchPotato</label>
<div class="col-lg-10 checkbox">
<label>
@if (Model.Enabled)
{
<input type="checkbox" id="Enabled" name="Enabled" checked="checked">
}
else
{
<input type="checkbox" id="Enabled" name="Enabled">
}
</label>
</div>
</div>
<div class="form-group">
<label for="Ip" class="col-lg-2 control-label">CouchPotato Hostname or IP</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="Ip" name="Ip" placeholder="localhost" value="@Model.Ip">
</div>
</div>
<div class="form-group">
<label for="portNumber" class="col-lg-2 control-label">Port</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="portNumber" name="Port" placeholder="Port Number" value="@port">
</div>
</div>
<div class="form-group">
<label for="ApiKey" class="col-lg-2 control-label">CouchPotato API Key</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="ApiKey" name="ApiKey" value="@Model.ApiKey">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>

@ -11,18 +11,9 @@
port = Model.Port;
}
if (Model.PlexAuthToken == null)
{
authToken = string.Empty;
}
else
{
authToken = Model.PlexAuthToken;
}
}
<div class="col-sm-8">
<form class="form-horizontal" method="POST" id="mainForm">
<form class="form-horizontal" method="POST" action="/admin/couchpotato" id="mainForm">
<fieldset>
<legend>Request Plex Settings</legend>
<div class="form-group">
@ -43,7 +34,7 @@
}
else
{
<input type="checkbox" id="SearchForMovies" name="SearchForMovies" checked="checked">
<input type="checkbox" id="SearchForMovies" name="SearchForMovies">
}
</label>
</div>
@ -77,7 +68,7 @@
<div class="form-group">
<label for="authToken" class="col-lg-2 control-label">Plex Authorization Token</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@authToken">
<input type="text" class="form-control" id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@Model.PlexAuthToken">
</div>
</div>
@ -135,7 +126,6 @@
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="reset" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>

@ -1,8 +1,8 @@
<div class="col-lg-3 col-md-3 col-sm-4">
<div class="list-group table-of-contents">
<a class="list-group-item" href="/admin">Request Plex Settings</a>
<a class="list-group-item" href="/couchpotato">CouchPotato Settings</a>
<a class="list-group-item" href="/sonarr">Sonarr Settings</a>
<a class="list-group-item" href="/sickbeard">Sickbeard Settings</a>
<a class="list-group-item" href="/admin/couchpotato">CouchPotato Settings</a>
<a class="list-group-item" href="/admin/sonarr">Sonarr Settings</a>
<a class="list-group-item" href="/admin/sickbeard">Sickbeard Settings</a>
</div>
</div>
Loading…
Cancel
Save