Added the code to get the quality profiles from Sonarr

Started plugging that into the UI
This commit is contained in:
Jamie Rees 2016-03-10 22:24:37 +00:00
commit 640e76e167
10 changed files with 266 additions and 10 deletions

View file

@ -69,6 +69,7 @@ namespace PlexRequests.UI
container.Register<ISettingsService<CouchPotatoSettings>, SettingsServiceV2<CouchPotatoSettings>>();
container.Register<ISettingsService<AuthenticationSettings>, SettingsServiceV2<AuthenticationSettings>>();
container.Register<ISettingsService<PlexSettings>, SettingsServiceV2<PlexSettings>>();
container.Register<ISettingsService<SonarrSettings>, SettingsServiceV2<SonarrSettings>>();
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
container.Register<IRequestService, RequestService>();

View file

@ -49,14 +49,20 @@ namespace PlexRequests.UI.Modules
private ISettingsService<CouchPotatoSettings> CpService { get; set; }
private ISettingsService<AuthenticationSettings> AuthService { get; set; }
private ISettingsService<PlexSettings> PlexService { get; set; }
private ISettingsService<SonarrSettings> SonarrService { get; set; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public AdminModule(ISettingsService<PlexRequestSettings> rpService, ISettingsService<CouchPotatoSettings> cpService, ISettingsService<AuthenticationSettings> auth, ISettingsService<PlexSettings> plex) : base("admin")
public AdminModule(ISettingsService<PlexRequestSettings> rpService,
ISettingsService<CouchPotatoSettings> cpService,
ISettingsService<AuthenticationSettings> auth
, ISettingsService<PlexSettings> plex,
ISettingsService<SonarrSettings> sonarr ) : base("admin")
{
RpService = rpService;
CpService = cpService;
AuthService = auth;
PlexService = plex;
SonarrService = sonarr;
#if !DEBUG
this.RequiresAuthentication();
@ -77,6 +83,11 @@ namespace PlexRequests.UI.Modules
Get["/plex"] = _ => Plex();
Post["/plex"] = _ => SavePlex();
Get["/sonarr"] = _ => Sonarr();
Post["/sonarr"] = _ => SaveSonarr();
Get["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
}
private Negotiator Authentication()
@ -201,5 +212,29 @@ namespace PlexRequests.UI.Modules
return Context.GetRedirect("~/admin/plex");
}
private Negotiator Sonarr()
{
var settings = SonarrService.GetSettings();
return View["Sonarr", settings];
}
private Response SaveSonarr()
{
var plexSettings = this.Bind<SonarrSettings>();
SonarrService.SaveSettings(plexSettings);
return Context.GetRedirect("~/admin/Sonarr");
}
private Response GetSonarrQualityProfiles()
{
var settings = SonarrService.GetSettings();
var api = new SonarrApi();
var profiles = api.GetProfiles(settings.ApiKey, settings.FullUri);
return Response.AsJson(profiles);
}
}
}

View file

@ -273,6 +273,9 @@
<Content Include="Views\Admin\Plex.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Admin\Sonarr.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>

View file

@ -0,0 +1,84 @@
@Html.Partial("_Sidebar")
@{
int port;
if (Model.Port == 0)
{
port = 80;
}
else
{
port = Model.Port;
}
}
<div class="col-sm-8 col-sm-push-1">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset>
<legend>Sonarr Settings</legend>
<div class="form-group">
<label for="Ip" class="control-label">Sonarr 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">Sonarr 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="select" class="control-label">Quality Profiles</label>
<div>
<select class="form-control" id="select">
</select>
</div>
</div>
<div class="form-group">
<div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
<script>
$(function () {
$.ajax({
type: "GET",
url: "sonarrprofiles",
dataType: "json",
success: function (response) {
response.forEach(function (result) {
$("#select").append("<option>" + result.name + "</option>");
});
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
})
</script>

View file

@ -43,6 +43,15 @@
<li><a href="/search">Search</a></li>
}
@if (Context.Request.Path == "/requests")
{
<li class="active"><a href="/requests">Requests</a></li>
}
else
{
<li><a href="/requests">Requests</a></li>
}
@if (Context.CurrentUser.IsAuthenticated())
{
if (Context.Request.Path == "/admin")
@ -54,14 +63,6 @@
<li><a href="/admin">Admin</a></li>
}
}
@if (Context.Request.Path == "/requests")
{
<li class="active"><a href="/requests">Requests</a></li>
}
else
{
<li><a href="/requests">Requests</a></li>
}
</ul>
<ul class="nav navbar-nav navbar-right">
@if (!Context.CurrentUser.IsAuthenticated())