More work on the settings

This commit is contained in:
Jamie Rees 2016-03-01 22:50:41 +00:00
parent 8c9bd41057
commit a00d5b69f2
14 changed files with 152 additions and 39 deletions

View file

@ -64,6 +64,9 @@
<ItemGroup> <ItemGroup>
<Compile Include="ISettingsService.cs" /> <Compile Include="ISettingsService.cs" />
<Compile Include="RequestService.cs" /> <Compile Include="RequestService.cs" />
<Compile Include="SettingModels\SonarrSettings.cs" />
<Compile Include="SettingModels\SickRageSettings.cs" />
<Compile Include="SettingModels\CouchPotatoSettings.cs" />
<Compile Include="SettingModels\RequestPlexSettings.cs" /> <Compile Include="SettingModels\RequestPlexSettings.cs" />
<Compile Include="SettingModels\Settings.cs" /> <Compile Include="SettingModels\Settings.cs" />
<Compile Include="SettingsService.cs" /> <Compile Include="SettingsService.cs" />

View file

@ -0,0 +1,10 @@
namespace RequestPlex.Core.SettingModels
{
public class CouchPotatoSettings : Settings
{
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public bool Enabled { get; set; }
}
}

View file

@ -31,5 +31,9 @@ namespace RequestPlex.Core.SettingModels
public int Port { get; set; } public int Port { get; set; }
public bool UserAuthentication { get; set; } public bool UserAuthentication { get; set; }
public string PlexAuthToken { get; set; } public string PlexAuthToken { get; set; }
public bool SearchForMovies { get; set; }
public bool SearchForTvShows { get; set; }
public bool RequireApprovial { get; set; }
public int WeeklyRequestLimit { get; set; }
} }
} }

View file

@ -0,0 +1,10 @@
namespace RequestPlex.Core.SettingModels
{
public class SickRageSettings : Settings
{
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public bool Enabled { get; set; }
}
}

View file

@ -0,0 +1,10 @@
namespace RequestPlex.Core.SettingModels
{
public class SonarrSettings : Settings
{
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public bool Enabled { get; set; }
}
}

View file

@ -0,0 +1,15 @@
using System.Diagnostics;
using System.Reflection;
namespace RequestPlex.Helpers
{
public class AssemblyHelper
{
public static string GetAssemblyVersion()
{
var assembly = Assembly.GetExecutingAssembly();
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.FileVersion;
}
}
}

View file

@ -45,6 +45,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AssemblyHelper.cs" />
<Compile Include="ICacheProvider.cs" /> <Compile Include="ICacheProvider.cs" />
<Compile Include="MemoryCacheProvider.cs" /> <Compile Include="MemoryCacheProvider.cs" />
<Compile Include="ObjectCopier.cs" /> <Compile Include="ObjectCopier.cs" />

View file

@ -16,6 +16,10 @@ namespace RequestPlex.Store
public DateTime ReleaseDate { get; set; } public DateTime ReleaseDate { get; set; }
public RequestType Type { get; set; } public RequestType Type { get; set; }
public string Status { get; set; } public string Status { get; set; }
public string RequestedStatus { get; set; }
public string RequestedBy { get; set; }
public DateTime RequestedDate { get; set; }
} }
public enum RequestType public enum RequestType

View file

@ -26,7 +26,12 @@ CREATE TABLE IF NOT EXISTS Requested
Title varchar(50) NOT NULL, Title varchar(50) NOT NULL,
PosterPath varchar(50) NOT NULL, PosterPath varchar(50) NOT NULL,
ReleaseDate varchar(50) NOT NULL, ReleaseDate varchar(50) NOT NULL,
Status varchar(50) NOT NULL Status varchar(50) NOT NULL,
RequestStatus varchar(50) NOT NULL,
RequestedBy varchar(50) NOT NULL,
RequestedDate varchar(50) NOT NULL,
Available varchar(50) NOT NULL
); );
CREATE TABLE IF NOT EXISTS GlobalSettings CREATE TABLE IF NOT EXISTS GlobalSettings

View file

@ -30,6 +30,7 @@ using System.Web.UI;
using Nancy; using Nancy;
using Nancy.Extensions; using Nancy.Extensions;
using Nancy.ModelBinding; using Nancy.ModelBinding;
using Nancy.Responses.Negotiation;
using Nancy.Security; using Nancy.Security;
using RequestPlex.Api; using RequestPlex.Api;
@ -60,19 +61,12 @@ namespace RequestPlex.UI.Modules
} }
private Response Admin() private Negotiator Admin()
{ {
dynamic model = new ExpandoObject(); dynamic model = new ExpandoObject();
model.Errored = Request.Query.error.HasValue;
model.Port = null;
var settings = Service.GetSettings(); var settings = Service.GetSettings();
if (settings != null)
{
model.Port = settings.Port;
model.PlexAuthToken = settings.PlexAuthToken;
}
model = settings;
return View["/Admin/Settings", model]; return View["/Admin/Settings", model];
} }
@ -112,7 +106,7 @@ namespace RequestPlex.UI.Modules
Service.SaveSettings(newModel); Service.SaveSettings(newModel);
} }
return Context.GetRedirect("~/admin"); return Response.AsJson(new {Result = true, AuthToken = model.user.authentication_token});
} }

View file

@ -1,11 +1,9 @@
using System; using System;
using System.Diagnostics;
using Microsoft.Owin.Hosting; using Microsoft.Owin.Hosting;
using Mono.Data.Sqlite; using Mono.Data.Sqlite;
using Nancy.Hosting.Self;
using RequestPlex.Core; using RequestPlex.Core;
using RequestPlex.Core.SettingModels; using RequestPlex.Core.SettingModels;
using RequestPlex.Helpers; using RequestPlex.Helpers;
@ -18,6 +16,8 @@ namespace RequestPlex.UI
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
var assemblyVer = AssemblyHelper.GetAssemblyVersion();
Console.WriteLine($"Version: {assemblyVer}");
var uri = "http://localhost:3579/"; var uri = "http://localhost:3579/";
var s = new Setup(); var s = new Setup();
s.SetupDb(); s.SetupDb();
@ -32,8 +32,8 @@ namespace RequestPlex.UI
using (WebApp.Start<Startup>(uri)) using (WebApp.Start<Startup>(uri))
{ {
Console.WriteLine("Running on {0}", uri); Console.WriteLine($"Request Plex is running on {uri}");
Console.WriteLine("Press enter to exit"); Console.WriteLine("Press any key to exit");
Console.ReadLine(); Console.ReadLine();
} }
} }

View file

@ -19,6 +19,7 @@
{ {
authToken = Model.PlexAuthToken; authToken = Model.PlexAuthToken;
} }
} }
<div class="col-sm-8"> <div class="col-sm-8">
<form class="form-horizontal" method="POST" id="mainForm"> <form class="form-horizontal" method="POST" id="mainForm">
@ -26,10 +27,52 @@
<legend>Request Plex Settings</legend> <legend>Request Plex Settings</legend>
<div class="form-group"> <div class="form-group">
<label for="portNumber" class="col-lg-2 control-label">Port</label> <label for="portNumber" class="col-lg-2 control-label">Port</label>
<div class="col-lg-10"> <div class="col-lg-10">
<input type="text" class="form-control" id="portNumber" name="Port" placeholder="Port Number" value="@port"> <input type="text" class="form-control" id="portNumber" name="Port" placeholder="Port Number" value="@port">
</div> </div>
</div> </div>
<small class="col-lg-10 col-lg-offset-2">You will have to restart after changing the port.</small>
<div class="form-group">
<label for="SearchForMovies" class="col-lg-2 control-label">Search for Movies</label>
<div class="col-lg-10 checkbox">
<label>
@if (Model.SearchForMovies)
{
<input type="checkbox" id="SearchForMovies" name="SearchForMovies" checked="checked">
}
else
{
<input type="checkbox" id="SearchForMovies" name="SearchForMovies" checked="checked">
}
</label>
</div>
</div>
<div class="form-group">
<label for="SearchForTvShows" class="col-lg-2 control-label">Search for TV Shows</label>
<div class="col-lg-10 checkbox">
<label>
@if (Model.SearchForTvShows)
{
<input type="checkbox" id="SearchForTvShows" name="SearchForTvShows" checked="checked">
}
else
{
<input type="checkbox" id="SearchForTvShows" name="SearchForTvShows">
}
</label>
</div>
</div>
<div class="form-group">
<label for="WeeklyRequestLimit" class="col-lg-2 control-label">Weekly Request Limit</label>
<div class="col-lg-10 checkbox">
<label>
<input type="number" id="WeeklyRequestLimit" name="WeeklyRequestLimit" value="@Model.WeeklyRequestLimit">
</label>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="authToken" class="col-lg-2 control-label">Plex Authorization Token</label> <label for="authToken" class="col-lg-2 control-label">Plex Authorization Token</label>
@ -39,7 +82,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="userpass" class="col-lg-2 control-label">Username and Password</label> <label for="username" class="col-lg-2 control-label">Username and Password</label>
<div class="col-lg-4"> <div class="col-lg-4">
<input type="text" class="form-control" id="username" name="Username" placeholder="Username"> <input type="text" class="form-control" id="username" name="Username" placeholder="Username">
</div> </div>
@ -55,15 +98,30 @@
<div class="form-group"> <div class="form-group">
<label for="userAuth" class="col-lg-2 control-label">Enable User Authentication</label> <label for="userAuth" class="col-lg-2 control-label">Enable User Authentication</label>
<div class="col-lg-4"> <div class="col-lg-4 checkbox">
<input type="checkbox" class="form-control" id="userAuth" name="UserAuthentication"> <label>
@if (Model.UserAuthentication)
{
<input type="checkbox" id="userAuth" name="UserAuthentication" checked="checked">
}
else
{
<input type="checkbox" id="userAuth" name="UserAuthentication">
}
</label>
</div> </div>
</div> </div>
<small>Current users that are allowed to authenticate: </small> <br />
<select id="users" multiple="" class="form-control col-lg-10 col-lg-offset-2"> <br />
</select> <small class="col-lg-offset-2">Current users that are allowed to authenticate: </small>
<br />
<br />
<div class="form-group"> <div class="form-group">
<select id="users" multiple="" class="col-lg-10 col-lg-offset-2"></select>
</div>
<div class="form-group">
<br />
<br />
<div class="col-lg-10 col-lg-offset-2"> <div class="col-lg-10 col-lg-offset-2">
<button id="refreshUsers" class="btn btn-primary">Refresh Users</button> <button id="refreshUsers" class="btn btn-primary">Refresh Users</button>
</div> </div>
@ -74,7 +132,6 @@
<br /> <br />
<br /> <br />
<div> <div>
<small class="col-lg-10 col-lg-offset-2">Please note, you will have to restart after changing these settings.</small>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-lg-10 col-lg-offset-2"> <div class="col-lg-10 col-lg-offset-2">
@ -87,19 +144,11 @@
</div> </div>
@if (Model.Errored)
{
<div class="alert alert-dismissible alert-danger">
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-times"></i></button>
Please enter in a correct port number
</div>
}
<script> <script>
$(function () { $(function () {
if ($('#PlexAuthToken')) { if ($('#PlexAuthToken')) {
loadUserList(); loadUserList();
} }
$('#refreshUsers').click(function () { $('#refreshUsers').click(function () {
@ -107,6 +156,7 @@
}); });
$('#requestToken').click(function (e) { $('#requestToken').click(function (e) {
e.preventDefault();
var $form = $("#mainForm"); var $form = $("#mainForm");
$.ajax({ $.ajax({
type: $form.prop("method"), type: $form.prop("method"),
@ -115,11 +165,11 @@
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
console.log(response); console.log(response);
if (response.Result === true) { if (response.result === true) {
generateNotify("Success!", "success"); generateNotify("Success!", "success");
$('#authToken').val(response.authToken); $('#authToken').val(response.authToken);
} else { } else {
generateNotify(response.Message, "warning"); generateNotify(response.message, "warning");
} }
}, },
error: function (e) { error: function (e) {
@ -137,9 +187,13 @@
url: "admin/getusers", url: "admin/getusers",
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
response.each(function (user) { if (response.length > 1) {
$('#users').append("<option>" + user + "</option>"); response.each(function(user) {
}); $('#users').append("<option>" + user + "</option>");
});
} else {
$('#users').append("<option>No Users!</option>");
}
}, },
error: function (e) { error: function (e) {
console.log(e); console.log(e);

View file

@ -49,9 +49,11 @@
</div> </div>
<div class="col-sm-2 col-sm-push-3"> <div class="col-sm-2 col-sm-push-3">
<span class="label label-success">{{status}}</span> <span class="label label-success">{{status}}</span>
<br />
<br />
<form method="POST" action="/search/request/{{type}}" id="form{{id}}"> <form method="POST" action="/search/request/{{type}}" id="form{{id}}">
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" /> <input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
<button id="{{id}}" style="text-align: right" class="btn btn-primary requestMovie" type="submit"><i class="fa fa-plus"></i> TestBtn</button> <button id="{{id}}" style="text-align: right" class="btn btn-danger" type="submit"><i class="fa fa-plus"></i> Remove</button>
</form> </form>
</div> </div>

View file

@ -1,5 +1,6 @@
<div> <div>
<h2>Search</h2> <h2>Search</h2>
<h4>Want to wacth something that is not currently on Plex?! No problem! Just search for it below and request it!</h4>
<!-- Nav tabs --> <!-- Nav tabs -->
<ul id="nav-tabs" class="nav nav-tabs" role="tablist"> <ul id="nav-tabs" class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab">Movies</a></li> <li role="presentation" class="active"><a href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab">Movies</a></li>