mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Added the settings page for #32
This commit is contained in:
parent
c7826003bc
commit
5843dee2a5
8 changed files with 275 additions and 1 deletions
|
@ -76,6 +76,7 @@ namespace PlexRequests.UI
|
|||
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
|
||||
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
|
||||
container.Register<ISettingsService<PushoverNotificationSettings>, SettingsServiceV2<PushoverNotificationSettings>>();
|
||||
container.Register<ISettingsService<HeadphonesSettings>, SettingsServiceV2<HeadphonesSettings>>();
|
||||
|
||||
// Repo's
|
||||
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
using Humanizer;
|
||||
using MarkdownSharp;
|
||||
|
||||
|
@ -65,6 +67,7 @@ namespace PlexRequests.UI.Modules
|
|||
private ISettingsService<EmailNotificationSettings> EmailService { get; }
|
||||
private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; }
|
||||
private ISettingsService<PushoverNotificationSettings> PushoverService { get; }
|
||||
private ISettingsService<HeadphonesSettings> HeadphonesSerivce { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private IPushbulletApi PushbulletApi { get; }
|
||||
|
@ -89,7 +92,8 @@ namespace PlexRequests.UI.Modules
|
|||
ISettingsService<PushoverNotificationSettings> pushoverSettings,
|
||||
IPushoverApi pushoverApi,
|
||||
IRepository<LogEntity> logsRepo,
|
||||
INotificationService notify) : base("admin")
|
||||
INotificationService notify,
|
||||
ISettingsService<HeadphonesSettings> headphones) : base("admin")
|
||||
{
|
||||
RpService = rpService;
|
||||
CpService = cpService;
|
||||
|
@ -107,6 +111,7 @@ namespace PlexRequests.UI.Modules
|
|||
PushoverService = pushoverSettings;
|
||||
PushoverApi = pushoverApi;
|
||||
NotificationService = notify;
|
||||
HeadphonesSerivce = headphones;
|
||||
|
||||
#if !DEBUG
|
||||
this.RequiresAuthentication();
|
||||
|
@ -151,6 +156,9 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/loglevel"] = _ => GetLogLevels();
|
||||
Post["/loglevel"] = _ => UpdateLogLevels(Request.Form.level);
|
||||
Get["/loadlogs"] = _ => LoadLogs();
|
||||
|
||||
Get["/headphones"] = _ => Headphones();
|
||||
Post["/headphones"] = _ => SaveHeadphones();
|
||||
}
|
||||
|
||||
private Negotiator Authentication()
|
||||
|
@ -509,5 +517,32 @@ namespace PlexRequests.UI.Modules
|
|||
LoggingHelper.ReconfigureLogLevel(newLevel);
|
||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}"});
|
||||
}
|
||||
|
||||
private Negotiator Headphones()
|
||||
{
|
||||
var settings = HeadphonesSerivce.GetSettings();
|
||||
return View["Headphones", settings];
|
||||
}
|
||||
|
||||
private Response SaveHeadphones()
|
||||
{
|
||||
var settings = this.Bind<HeadphonesSettings>();
|
||||
|
||||
var valid = this.Validate(settings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
var error = valid.SendJsonError();
|
||||
Log.Info("Error validating Headphones settings, message: {0}", error.Message);
|
||||
return Response.AsJson(error);
|
||||
}
|
||||
Log.Trace(settings.DumpJson());
|
||||
|
||||
var result = HeadphonesSerivce.SaveSettings(settings);
|
||||
|
||||
Log.Info("Saved headphones settings, result: {0}", result);
|
||||
return Response.AsJson(result
|
||||
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Headphones!" }
|
||||
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,6 +57,7 @@ namespace PlexRequests.UI.Modules
|
|||
Post["/sonarr"] = _ => SonarrTest();
|
||||
Post["/plex"] = _ => PlexTest();
|
||||
Post["/sickrage"] = _ => SickRageTest();
|
||||
Post["/headphones"] = _ => HeadphonesTest();
|
||||
|
||||
}
|
||||
|
||||
|
@ -168,5 +169,10 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response HeadphonesTest()
|
||||
{
|
||||
throw new NotImplementedException(); //TODO
|
||||
}
|
||||
}
|
||||
}
|
|
@ -371,6 +371,9 @@
|
|||
<Content Include="Views\Admin\PushoverNotifications.cshtml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Views\Admin\Headphones.cshtml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>web.config</DependentUpon>
|
||||
</None>
|
||||
|
|
162
PlexRequests.UI/Views/Admin/Headphones.cshtml
Normal file
162
PlexRequests.UI/Views/Admin/Headphones.cshtml
Normal file
|
@ -0,0 +1,162 @@
|
|||
@Html.Partial("_Sidebar")
|
||||
@{
|
||||
int port;
|
||||
if (Model.Port == 0)
|
||||
{
|
||||
port = 8081;
|
||||
}
|
||||
else
|
||||
{
|
||||
port = Model.Port;
|
||||
}
|
||||
}
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
<form class="form-horizontal" method="POST" id="mainForm">
|
||||
<fieldset>
|
||||
<legend>Headphones Settings</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">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@if (Model.Ssl)
|
||||
{
|
||||
<input type="checkbox" id="Ssl" name="Ssl" checked="checked"><text>SSL</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="checkbox" id="Ssl" name="Ssl"><text>SSL</text>
|
||||
}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="Ip" class="control-label">Headphones Hostname or IP</label>
|
||||
<div class="">
|
||||
<input type="text" class="form-control form-control-custom " id="Ip" name="Ip" placeholder="localhost" value="@Model.Ip">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="portNumber" class="control-label">Port</label>
|
||||
|
||||
<div class="">
|
||||
<input type="text" class="form-control form-control-custom " id="portNumber" name="Port" placeholder="Port Number" value="@port">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ApiKey" class="control-label">Headphones API Key</label>
|
||||
<div>
|
||||
<input type="text" class="form-control form-control-custom " id="ApiKey" name="ApiKey" value="@Model.ApiKey">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="SubDir" class="control-label">Headphones SubDirectory</label>
|
||||
<div>
|
||||
<input type="text" class="form-control form-control-custom " id="SubDir" name="SubDir" value="@Model.SubDir">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button type="submit" id="getProfiles" class="btn btn-primary-outline">Get Quality Profiles</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="testHeadphones" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
|
||||
$('#testHeadphones').click(function (e) {
|
||||
e.preventDefault();
|
||||
var $form = $("#mainForm");
|
||||
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
url: "/test/headphones",
|
||||
data: $form.serialize(),
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
console.log(response);
|
||||
if (response.result === true) {
|
||||
generateNotify(response.message, "success");
|
||||
$('#authToken').val(response.authToken);
|
||||
} else {
|
||||
generateNotify(response.message, "warning");
|
||||
}
|
||||
},
|
||||
error: function (e) {
|
||||
console.log(e);
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#save').click(function (e) {
|
||||
e.preventDefault();
|
||||
var port = $('#portNumber').val();
|
||||
if (isNaN(port)) {
|
||||
generateNotify("You must specify a Port.", "warning");
|
||||
return;
|
||||
}
|
||||
var $form = $("#mainForm");
|
||||
var qualityProfile = $("#profiles option:selected").val();
|
||||
var data = $form.serialize();
|
||||
data = data + "&profileId=" + qualityProfile;
|
||||
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
data: data,
|
||||
url: $form.prop("action"),
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
if (response.result === true) {
|
||||
generateNotify(response.message, "success");
|
||||
} else {
|
||||
generateNotify(response.message, "warning");
|
||||
}
|
||||
},
|
||||
error: function (e) {
|
||||
console.log(e);
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
|
@ -52,6 +52,14 @@
|
|||
{
|
||||
<a class="list-group-item" href="/admin/sickrage">SickRage</a>
|
||||
}
|
||||
@if (Context.Request.Path == "/admin/headphones")
|
||||
{
|
||||
<a class="list-group-item active" href="/admin/headphones">Headphones</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a class="list-group-item" href="/admin/headphones">Headphones</a>
|
||||
}
|
||||
|
||||
@if (Context.Request.Path == "/admin/emailnotification")
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue