diff --git a/Ombi.Api.Interfaces/ISonarrApi.cs b/Ombi.Api.Interfaces/ISonarrApi.cs index 203020737..881f469eb 100644 --- a/Ombi.Api.Interfaces/ISonarrApi.cs +++ b/Ombi.Api.Interfaces/ISonarrApi.cs @@ -36,14 +36,16 @@ namespace Ombi.Api.Interfaces List GetProfiles(string apiKey, Uri baseUrl); SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, + int rootFolderId, int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false); SonarrAddSeries AddSeriesNew(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, - int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, + int rootFolderId, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false); SystemStatus SystemStatus(string apiKey, Uri baseUrl); + List GetRootFolders(string apiKey, Uri baseUrl); List GetSeries(string apiKey, Uri baseUrl); Series GetSeries(string seriesId, string apiKey, Uri baseUrl); diff --git a/Ombi.Api.Models/Ombi.Api.Models.csproj b/Ombi.Api.Models/Ombi.Api.Models.csproj index 003b6d465..c180f5624 100644 --- a/Ombi.Api.Models/Ombi.Api.Models.csproj +++ b/Ombi.Api.Models/Ombi.Api.Models.csproj @@ -101,6 +101,7 @@ + diff --git a/Ombi.Api.Models/Sonarr/SonarrRootFolder.cs b/Ombi.Api.Models/Sonarr/SonarrRootFolder.cs new file mode 100644 index 000000000..d506feba6 --- /dev/null +++ b/Ombi.Api.Models/Sonarr/SonarrRootFolder.cs @@ -0,0 +1,35 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: SonarrRootFolder.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +namespace Ombi.Api.Models.Sonarr +{ + public class SonarrRootFolder + { + public int id { get; set; } + public string path { get; set; } + public long freespace { get; set; } + } +} \ No newline at end of file diff --git a/Ombi.Api/SonarrApi.cs b/Ombi.Api/SonarrApi.cs index 7c80883dc..c4c448628 100644 --- a/Ombi.Api/SonarrApi.cs +++ b/Ombi.Api/SonarrApi.cs @@ -62,7 +62,23 @@ namespace Ombi.Api return obj; } - public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false) + public List GetRootFolders(string apiKey, Uri baseUrl) + { + var request = new RestRequest { Resource = "/api/rootfolder", Method = Method.GET }; + + request.AddHeader("X-Api-Key", apiKey); + var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetRootFolders for Sonarr, Retrying {0}", timespan), new TimeSpan[] { + TimeSpan.FromSeconds (2), + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(10) + }); + + var obj = policy.Execute(() => Api.ExecuteJson>(request, baseUrl)); + + return obj; + } + + public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int rootFolderId, int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false) { Log.Debug("Adding series {0}", title); Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount); @@ -132,7 +148,7 @@ namespace Ombi.Api return result; } - public SonarrAddSeries AddSeriesNew(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false) + public SonarrAddSeries AddSeriesNew(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int rootFolderId, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false) { var request = new RestRequest { diff --git a/Ombi.Core/CacheKeys.cs b/Ombi.Core/CacheKeys.cs index 889ac6df7..39ed7a71b 100644 --- a/Ombi.Core/CacheKeys.cs +++ b/Ombi.Core/CacheKeys.cs @@ -47,5 +47,6 @@ namespace Ombi.Core public const string WatcherQueued = nameof(WatcherQueued); public const string GetPlexRequestSettings = nameof(GetPlexRequestSettings); public const string LastestProductVersion = nameof(LastestProductVersion); + public const string SonarrRootFolders = nameof(SonarrRootFolders); } } \ No newline at end of file diff --git a/Ombi.Core/SettingModels/SonarrSettings.cs b/Ombi.Core/SettingModels/SonarrSettings.cs index 31f96b3e6..ee309e376 100644 --- a/Ombi.Core/SettingModels/SonarrSettings.cs +++ b/Ombi.Core/SettingModels/SonarrSettings.cs @@ -33,6 +33,7 @@ namespace Ombi.Core.SettingModels public string QualityProfile { get; set; } public bool SeasonFolders { get; set; } public string RootPath { get; set; } - + public string RootFolder { get; set; } + } } \ No newline at end of file diff --git a/Ombi.Core/TvSender.cs b/Ombi.Core/TvSender.cs index 1e97e3550..34be1bb76 100644 --- a/Ombi.Core/TvSender.cs +++ b/Ombi.Core/TvSender.cs @@ -51,7 +51,7 @@ namespace Ombi.Core public async Task SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model) { - return await SendToSonarr(sonarrSettings, model, string.Empty); + return await SendToSonarr(sonarrSettings, model, string.Empty, string.Empty); } /// @@ -61,7 +61,7 @@ namespace Ombi.Core /// /// /// - public async Task SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId) + public async Task SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId, string rootFolderId) { var qualityProfile = 0; var episodeRequest = model.Episodes.Any(); @@ -82,6 +82,17 @@ namespace Ombi.Core var latest = model.SeasonsRequested?.Equals("Latest", StringComparison.CurrentCultureIgnoreCase); var specificSeasonRequest = model.SeasonList?.Any(); + var rootFolder = 0; + if (!string.IsNullOrEmpty(rootFolderId)) + { + int.TryParse(qualityId, out rootFolder); + } + + if (rootFolder <= 0) + { + int.TryParse(sonarrSettings.RootFolder, out rootFolder); + } + if (episodeRequest) { // Does series exist? @@ -96,7 +107,7 @@ namespace Ombi.Core // Series doesn't exist, need to add it as unmonitored. var addResult = await Task.Run(() => SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, - sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, new int[0], sonarrSettings.ApiKey, + sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, rootFolder, new int[0], sonarrSettings.ApiKey, sonarrSettings.FullUri, false)); @@ -125,7 +136,7 @@ namespace Ombi.Core { // Set the series as monitored with a season count as 0 so it doesn't search for anything SonarrApi.AddSeriesNew(model.ProviderId, model.Title, qualityProfile, - sonarrSettings.SeasonFolders, sonarrSettings.RootPath, new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13}, sonarrSettings.ApiKey, + sonarrSettings.SeasonFolders, sonarrSettings.RootPath, rootFolder, new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13}, sonarrSettings.ApiKey, sonarrSettings.FullUri); await Task.Delay(TimeSpan.FromSeconds(1)); diff --git a/Ombi.Core/TvSenderOld.cs b/Ombi.Core/TvSenderOld.cs index 6594fe5b8..5edbda02c 100644 --- a/Ombi.Core/TvSenderOld.cs +++ b/Ombi.Core/TvSenderOld.cs @@ -49,12 +49,12 @@ namespace Ombi.Core private ISickRageApi SickrageApi { get; } private static Logger Log = LogManager.GetCurrentClassLogger(); - public async Task SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model) + public async Task SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string rootFolderId = null) { - return await SendToSonarr(sonarrSettings, model, string.Empty); + return await SendToSonarr(sonarrSettings, model, string.Empty, rootFolderId); } - public async Task SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId) + public async Task SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId, string rootFolderId) { var qualityProfile = 0; var episodeRequest = model.Episodes.Any(); @@ -67,6 +67,17 @@ namespace Ombi.Core { int.TryParse(sonarrSettings.QualityProfile, out qualityProfile); } + var rootFolder = 0; + if (!string.IsNullOrEmpty(rootFolderId)) + { + int.TryParse(qualityId, out rootFolder); + } + + if (rootFolder <= 0) + { + int.TryParse(sonarrSettings.RootFolder, out rootFolder); + } + var series = await GetSonarrSeries(sonarrSettings, model.ProviderId); @@ -84,7 +95,7 @@ namespace Ombi.Core // Series doesn't exist, need to add it as unmonitored. var addResult = await Task.Run(() => SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, - sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, new int[0], sonarrSettings.ApiKey, + sonarrSettings.SeasonFolders, sonarrSettings.RootPath, rootFolder, 0, new int[0], sonarrSettings.ApiKey, sonarrSettings.FullUri, false)); @@ -156,7 +167,7 @@ namespace Ombi.Core var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, - sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.SeasonCount, model.SeasonList, sonarrSettings.ApiKey, + sonarrSettings.SeasonFolders, sonarrSettings.RootPath, rootFolder, model.SeasonCount, model.SeasonList, sonarrSettings.ApiKey, sonarrSettings.FullUri, true, true); return result; diff --git a/Ombi.UI/ModelDataProviders/SonarrSettingsDataProvider.cs b/Ombi.UI/ModelDataProviders/SonarrSettingsDataProvider.cs index 694973e6a..ba4b727bd 100644 --- a/Ombi.UI/ModelDataProviders/SonarrSettingsDataProvider.cs +++ b/Ombi.UI/ModelDataProviders/SonarrSettingsDataProvider.cs @@ -53,6 +53,7 @@ namespace Ombi.UI.ModelDataProviders with.Property(x => x.SeasonFolders).Description("Sonarr's season folders").Required(false); + with.Property(x => x.RootFolder).Description("Sonarr's root folder").Required(true); with.Property(x => x.RootPath).Description("Sonarr's root path").Required(false); }); } diff --git a/Ombi.UI/Models/RequestViewModel.cs b/Ombi.UI/Models/RequestViewModel.cs index b6db27bca..cbe59eea4 100644 --- a/Ombi.UI/Models/RequestViewModel.cs +++ b/Ombi.UI/Models/RequestViewModel.cs @@ -58,5 +58,6 @@ namespace Ombi.UI.Models public Store.EpisodesModel[] Episodes { get; set; } public bool Denied { get; set; } public string DeniedReason { get; set; } + public RootFolderModel[] RootFolders { get; set; } } } diff --git a/Ombi.UI/Models/RootFolderModel.cs b/Ombi.UI/Models/RootFolderModel.cs new file mode 100644 index 000000000..9d15024fe --- /dev/null +++ b/Ombi.UI/Models/RootFolderModel.cs @@ -0,0 +1,36 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: RootFolderModel.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +namespace Ombi.UI.Models +{ + + public class RootFolderModel + { + public string Id { get; set; } + public string Path { get; set; } + public long FreeSpace { get; set; } + } +} \ No newline at end of file diff --git a/Ombi.UI/Modules/Admin/IntegrationModule.cs b/Ombi.UI/Modules/Admin/IntegrationModule.cs index 1322e7c64..36ec5fcc9 100644 --- a/Ombi.UI/Modules/Admin/IntegrationModule.cs +++ b/Ombi.UI/Modules/Admin/IntegrationModule.cs @@ -54,7 +54,7 @@ namespace Ombi.UI.Modules.Admin { public IntegrationModule(ISettingsService settingsService, ISettingsService watcher, ISettingsService cp,ISecurityExtensions security, IAnalytics a, ISettingsService radarrSettings, - ICacheProvider cache, IRadarrApi radarrApi) : base("admin", settingsService, security) + ICacheProvider cache, IRadarrApi radarrApi, ISonarrApi sonarrApi) : base("admin", settingsService, security) { WatcherSettings = watcher; @@ -63,9 +63,13 @@ namespace Ombi.UI.Modules.Admin Cache = cache; RadarrApi = radarrApi; RadarrSettings = radarrSettings; + SonarrApi = sonarrApi; Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx); + + Post["/sonarrrootfolders"] = _ => GetSonarrRootFolders(); + Get["/watcher", true] = async (x, ct) => await Watcher(); Post["/watcher", true] = async (x, ct) => await SaveWatcher(); @@ -82,6 +86,7 @@ namespace Ombi.UI.Modules.Admin private IRadarrApi RadarrApi { get; } private ICacheProvider Cache { get; } private IAnalytics Analytics { get; } + private ISonarrApi SonarrApi { get; } private async Task Watcher() { @@ -182,5 +187,20 @@ namespace Ombi.UI.Modules.Admin return Response.AsJson(profiles); } + private Response GetSonarrRootFolders() + { + var settings = this.Bind(); + + var rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri); + + // set the cache + if (rootFolders != null) + { + Cache.Set(CacheKeys.SonarrRootFolders, rootFolders); + } + + return Response.AsJson(rootFolders); + } + } } \ No newline at end of file diff --git a/Ombi.UI/Modules/ApprovalModule.cs b/Ombi.UI/Modules/ApprovalModule.cs index 9781b79a9..0f92abfb3 100644 --- a/Ombi.UI/Modules/ApprovalModule.cs +++ b/Ombi.UI/Modules/ApprovalModule.cs @@ -65,7 +65,7 @@ namespace Ombi.UI.Modules FaultQueue = faultQueue; MovieSender = movieSender; - Post["/approve", true] = async (x, ct) => await Approve((int)Request.Form.requestid, (string)Request.Form.qualityId); + Post["/approve", true] = async (x, ct) => await Approve((int)Request.Form.requestid, (string)Request.Form.qualityId, (string)Request.Form.rootFolderId ?? null); Post["/deny", true] = async (x, ct) => await DenyRequest((int)Request.Form.requestid, (string)Request.Form.reason); Post["/approveall", true] = async (x, ct) => await ApproveAll(); Post["/approveallmovies", true] = async (x, ct) => await ApproveAllMovies(); @@ -92,7 +92,7 @@ namespace Ombi.UI.Modules /// /// The request identifier. /// - private async Task Approve(int requestId, string qualityId) + private async Task Approve(int requestId, string qualityId, string rootFolderId = null) { Log.Info("approving request {0}", requestId); @@ -110,7 +110,7 @@ namespace Ombi.UI.Modules case RequestType.Movie: return await RequestMovieAndUpdateStatus(request, qualityId); case RequestType.TvShow: - return await RequestTvAndUpdateStatus(request, qualityId); + return await RequestTvAndUpdateStatus(request, qualityId, rootFolderId); case RequestType.Album: return await RequestAlbumAndUpdateStatus(request); default: @@ -118,7 +118,7 @@ namespace Ombi.UI.Modules } } - private async Task RequestTvAndUpdateStatus(RequestedModel request, string qualityId) + private async Task RequestTvAndUpdateStatus(RequestedModel request, string qualityId, string rootFolderId) { var sender = new TvSenderOld(SonarrApi, SickRageApi); // TODO put back diff --git a/Ombi.UI/Modules/RequestsModule.cs b/Ombi.UI/Modules/RequestsModule.cs index 4faefa206..5030a3686 100644 --- a/Ombi.UI/Modules/RequestsModule.cs +++ b/Ombi.UI/Modules/RequestsModule.cs @@ -160,6 +160,37 @@ namespace Ombi.UI.Modules } } + IEnumerable rootFolders = new List(); + if (IsAdmin) + { + try + { + var sonarrSettings = await SonarrSettings.GetSettingsAsync(); + if (sonarrSettings.Enabled) + { + var result = Cache.GetOrSetAsync(CacheKeys.SonarrRootFolders, async () => + { + return await Task.Run(() => SonarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri)); + }); + rootFolders = result.Result.Select(x => new RootFolderModel { Id = x.id.ToString(), Path = x.path }).ToList(); + } + // @TODO Sick Rage Root Folders + //else + //{ + // var sickRageSettings = await SickRageSettings.GetSettingsAsync(); + // if (sickRageSettings.Enabled) + // { + // qualities = sickRageSettings.Qualities.Select(x => new QualityModel { Id = x.Key, Name = x.Value }).ToList(); + // } + //} + } + catch (Exception e) + { + Log.Info(e); + } + + } + var canManageRequest = Security.HasAnyPermissions(User, Permissions.Administrator, Permissions.ManageRequests); var viewModel = dbMovies.Select(movie => new RequestViewModel @@ -185,7 +216,8 @@ namespace Ombi.UI.Modules IssueId = movie.IssueId, Denied = movie.Denied, DeniedReason = movie.DeniedReason, - Qualities = qualities.ToArray() + Qualities = qualities.ToArray(), + RootFolders = rootFolders.ToArray(), }).ToList(); return Response.AsJson(viewModel); @@ -235,7 +267,7 @@ namespace Ombi.UI.Modules } - + var canManageRequest = Security.HasAnyPermissions(User, Permissions.Administrator, Permissions.ManageRequests); var viewModel = dbTv.Select(tv => new RequestViewModel diff --git a/Ombi.UI/Ombi.UI.csproj b/Ombi.UI/Ombi.UI.csproj index 22dd6175d..3d51318d0 100644 --- a/Ombi.UI/Ombi.UI.csproj +++ b/Ombi.UI/Ombi.UI.csproj @@ -250,6 +250,7 @@ + diff --git a/Ombi.UI/Views/Admin/Sonarr.cshtml b/Ombi.UI/Views/Admin/Sonarr.cshtml index f2b4ca49a..7048a4152 100644 --- a/Ombi.UI/Views/Admin/Sonarr.cshtml +++ b/Ombi.UI/Views/Admin/Sonarr.cshtml @@ -17,14 +17,14 @@ Sonarr Settings
- @if (Model.Enabled) - { - - } - else - { - - } + @if (Model.Enabled) + { + + } + else + { + + }
@@ -51,14 +51,14 @@
- @if (Model.Ssl) - { - - } - else - { - - } + @if (Model.Ssl) + { + + } + else + { + + }
@@ -69,7 +69,7 @@
- +
@@ -80,32 +80,47 @@
-
- - + + +
+ +
+
+ +
+ +
+ @*
+ +
+ + +
+
*@ +
- @if (Model.SeasonFolders) - { - - } - else - { - - } - + @if (Model.SeasonFolders) + { + + } + else + { + + } +
- +
@@ -161,6 +176,39 @@ } + @if (!string.IsNullOrEmpty(Model.RootFolder)) + { + + + console.log('Hit root folders..'); + + var rootFolderSelected = @Model.RootFolder; + if (!rootFolderSelected) { + return; + } + var $form = $("#mainForm"); + $.ajax({ + type: $form.prop("method"), + data: $form.serialize(), + url: "sonarrrootfolders", + dataType: "json", + success: function(response) { + response.forEach(function(result) { + if (result.id == rootFolderSelected) { + $("#selectRootFolder").append(""); + } else { + $("#selectRootFolder").append(""); + } + }); + }, + error: function(e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + + } + $('#save').click(function(e) { e.preventDefault(); @@ -201,17 +249,17 @@ e.preventDefault(); if (!$('#Ip').val()) { generateNotify("Please enter a valid IP/Hostname.", "warning"); - $('#getSpinner').attr("class", "fa fa-times"); + $('#getSpinner').attr("class", "fa fa-times"); return; } if (!$('#portNumber').val()) { generateNotify("Please enter a valid Port Number.", "warning"); - $('#getSpinner').attr("class", "fa fa-times"); + $('#getSpinner').attr("class", "fa fa-times"); return; } if (!$('#ApiKey').val()) { generateNotify("Please enter a valid ApiKey.", "warning"); - $('#getSpinner').attr("class", "fa fa-times"); + $('#getSpinner').attr("class", "fa fa-times"); return; } var $form = $("#mainForm"); @@ -222,18 +270,58 @@ dataType: "json", success: function (response) { response.forEach(function (result) { - $('#getSpinner').attr("class", "fa fa-check"); + $('#getSpinner').attr("class", "fa fa-check"); $("#select").append(""); }); }, error: function (e) { console.log(e); - $('#getSpinner').attr("class", "fa fa-times"); + $('#getSpinner').attr("class", "fa fa-times"); generateNotify("Something went wrong!", "danger"); } }); }); + $('#getRootFolders').click(function (e) { + + $('#getRootFolderSpinner').attr("class", "fa fa-spinner fa-spin"); + e.preventDefault(); + if (!$('#Ip').val()) { + generateNotify("Please enter a valid IP/Hostname.", "warning"); + $('#getRootFolderSpinner').attr("class", "fa fa-times"); + return; + } + if (!$('#portNumber').val()) { + generateNotify("Please enter a valid Port Number.", "warning"); + $('#getRootFolderSpinner').attr("class", "fa fa-times"); + return; + } + if (!$('#ApiKey').val()) { + generateNotify("Please enter a valid ApiKey.", "warning"); + $('#getRootFolderSpinner').attr("class", "fa fa-times"); + return; + } + var $form = $("#mainForm"); + $.ajax({ + type: $form.prop("method"), + data: $form.serialize(), + url: "sonarrrootfolders", + dataType: "json", + success: function (response) { + response.forEach(function (result) { + $('#getRootFolderSpinner').attr("class", "fa fa-check"); + $("#selectRootFolder").append(""); + }); + }, + error: function (e) { + console.log(e); + $('#getRootFolderSpinner').attr("class", "fa fa-times"); + generateNotify("Something went wrong!", "danger"); + } + }); + }); + + var base = '@Html.GetBaseUrl()'; $('#testSonarr').click(function (e) { @@ -245,7 +333,7 @@ var data = $form.serialize(); data = data + "&qualityProfile=" + qualityProfile; - + var url = createBaseUrl(base, '/test/sonarr'); $.ajax({ type: $form.prop("method"), @@ -256,16 +344,16 @@ console.log(response); if (response.result === true) { generateNotify(response.message, "success"); - $('#spinner').attr("class", "fa fa-check"); + $('#spinner').attr("class", "fa fa-check"); } else { generateNotify(response.message, "warning"); - $('#spinner').attr("class", "fa fa-times"); + $('#spinner').attr("class", "fa fa-times"); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); - $('#spinner').attr("class", "fa fa-times"); + $('#spinner').attr("class", "fa fa-times"); } }); });