diff --git a/PlexRequests.Api/CouchPotatoApi.cs b/PlexRequests.Api/CouchPotatoApi.cs index e48cfd84d..b63c85661 100644 --- a/PlexRequests.Api/CouchPotatoApi.cs +++ b/PlexRequests.Api/CouchPotatoApi.cs @@ -62,13 +62,12 @@ namespace PlexRequests.Api request.AddUrlSegment("imdbid", imdbid); request.AddUrlSegment("title", title); - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { + var obj = RetryHandler.Execute(() => Api.ExecuteJson (request, baseUrl),new TimeSpan[] { TimeSpan.FromSeconds (2), TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling AddMovie for CP, Retrying {0}", timespan)); + TimeSpan.FromSeconds(10)}, + (exception, timespan) => Log.Error (exception, "Exception when calling AddMovie for CP, Retrying {0}", timespan)); - var obj = (JObject)policy.Execute( () => Api.ExecuteJson(request, baseUrl)); Log.Trace("CP movie Add result count {0}", obj.Count); if (obj.Count > 0) @@ -105,13 +104,15 @@ namespace PlexRequests.Api }; request.AddUrlSegment("apikey", apiKey); - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { + + + var obj = RetryHandler.Execute(() => Api.Execute (request, url),new TimeSpan[] { TimeSpan.FromSeconds (2), TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan)); - - return (CouchPotatoStatus)policy.Execute( () => Api.Execute(request,url)); + TimeSpan.FromSeconds(10)}, + (exception, timespan) => Log.Error (exception, "Exception when calling GetStatus for CP, Retrying {0}", timespan)); + + return obj; } public CouchPotatoProfiles GetProfiles(Uri url, string apiKey) @@ -125,13 +126,10 @@ namespace PlexRequests.Api request.AddUrlSegment("apikey", apiKey); - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetProfiles for CP, Retrying {0}", timespan)); - - return (CouchPotatoProfiles)policy.Execute( () => Api.Execute(request,url)); + var obj = RetryHandler.Execute(() => Api.Execute (request, url),null, + (exception, timespan) => Log.Error (exception, "Exception when calling GetProfiles for CP, Retrying {0}", timespan)); + + return obj; } public CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status) @@ -145,13 +143,15 @@ namespace PlexRequests.Api request.AddUrlSegment("status", string.Join(",", status)); try { - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (5), - TimeSpan.FromSeconds(10), - TimeSpan.FromSeconds(30) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan)); - - return (CouchPotatoMovies)policy.Execute( () => Api.Execute(request,baseUrl)); + var obj = RetryHandler.Execute(() => Api.Execute (request, baseUrl), + new TimeSpan[] { + TimeSpan.FromSeconds (5), + TimeSpan.FromSeconds(10), + TimeSpan.FromSeconds(30) + }, + (exception, timespan) => Log.Error (exception, "Exception when calling GetMovies for CP, Retrying {0}", timespan)); + + return obj; } catch (Exception e) // Request error is already logged in the ApiRequest class { diff --git a/PlexRequests.Api/HeadphonesApi.cs b/PlexRequests.Api/HeadphonesApi.cs index 34cecb8fe..94c29f126 100644 --- a/PlexRequests.Api/HeadphonesApi.cs +++ b/PlexRequests.Api/HeadphonesApi.cs @@ -71,7 +71,7 @@ namespace PlexRequests.Api return albumResult; } - catch (JsonSerializationException jse) + catch (Exception jse) { Log.Error(jse); return false; // If there is no matching result we do not get returned a JSON string, it just returns "false". @@ -94,7 +94,7 @@ namespace PlexRequests.Api return result; } - catch (JsonSerializationException jse) + catch (Exception jse) { Log.Error(jse); return new List(); diff --git a/PlexRequests.Api/PlexApi.cs b/PlexRequests.Api/PlexApi.cs index 4ef2e9fe2..1b20a68e9 100644 --- a/PlexRequests.Api/PlexApi.cs +++ b/PlexRequests.Api/PlexApi.cs @@ -47,6 +47,17 @@ namespace PlexRequests.Api Version = AssemblyHelper.GetAssemblyVersion(); } + public PlexApi (IApiRequest api) + { + Api = api; + } + + private IApiRequest Api { get; } + + private const string SignInUri = "https://plex.tv/users/sign_in.json"; + private const string FriendsUri = "https://plex.tv/pms/friends/all"; + private const string GetAccountUri = "https://plex.tv/users/account"; + private static Logger Log = LogManager.GetCurrentClassLogger(); private static string Version { get; } @@ -69,15 +80,11 @@ namespace PlexRequests.Api request.AddJsonBody(userModel); - var api = new ApiRequest(); - - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling SignIn for Plex, Retrying {0}", timespan)); - - return (PlexAuthentication)policy.Execute(() => api.Execute(request, new Uri("https://plex.tv/users/sign_in.json"))); + var obj = RetryHandler.Execute(() => Api.Execute (request, new Uri(SignInUri)), + null, + (exception, timespan) => Log.Error (exception, "Exception when calling SignIn for Plex, Retrying {0}", timespan)); + + return obj; } public PlexFriends GetUsers(string authToken) @@ -89,14 +96,10 @@ namespace PlexRequests.Api AddHeaders(ref request, authToken); - var api = new ApiRequest(); - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetUsers for Plex, Retrying {0}", timespan)); - - var users = (PlexFriends)policy.Execute(() =>api.ExecuteXml(request, new Uri("https://plex.tv/pms/friends/all"))); + var users = RetryHandler.Execute(() => Api.Execute (request, new Uri(FriendsUri)), + null, + (exception, timespan) => Log.Error (exception, "Exception when calling GetUsers for Plex, Retrying {0}", timespan)); + return users; } @@ -119,14 +122,9 @@ namespace PlexRequests.Api request.AddUrlSegment("searchTerm", searchTerm); AddHeaders(ref request, authToken); - var api = new ApiRequest(); - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling SearchContent for Plex, Retrying {0}", timespan)); - - var search = (PlexSearch)policy.Execute(() => api.ExecuteXml(request, plexFullHost)); + var search = RetryHandler.Execute(() => Api.ExecuteXml (request, plexFullHost), + null, + (exception, timespan) => Log.Error (exception, "Exception when calling SearchContent for Plex, Retrying {0}", timespan)); return search; } @@ -139,15 +137,11 @@ namespace PlexRequests.Api }; AddHeaders(ref request, authToken); - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetStatus for Plex, Retrying {0}", timespan)); - - var api = new ApiRequest(); - var users = (PlexStatus)policy.Execute(() => api.ExecuteXml(request, uri)); + var users = RetryHandler.Execute(() => Api.ExecuteXml (request, uri), + null, + (exception, timespan) => Log.Error (exception, "Exception when calling GetStatus for Plex, Retrying {0}", timespan)); + return users; } @@ -160,16 +154,10 @@ namespace PlexRequests.Api AddHeaders(ref request, authToken); - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetAccount for Plex, Retrying: {0}", timespan)); - - - var api = new ApiRequest(); - var account = (PlexAccount)policy.Execute(() => api.ExecuteXml(request, new Uri("https://plex.tv/users/account"))); - + var account = RetryHandler.Execute(() => Api.ExecuteXml (request, new Uri(GetAccountUri)), + null, + (exception, timespan) => Log.Error (exception, "Exception when calling GetAccount for Plex, Retrying {0}", timespan)); + return account; } @@ -183,16 +171,17 @@ namespace PlexRequests.Api AddHeaders(ref request, authToken); - var api = new ApiRequest(); try { - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (5), - TimeSpan.FromSeconds(10), - TimeSpan.FromSeconds(30) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetLibrarySections for Plex, Retrying {0}", timespan)); - - return (PlexLibraries)policy.Execute(() => api.ExecuteXml(request, plexFullHost)); + var lib = RetryHandler.Execute(() => Api.ExecuteXml (request, plexFullHost), + new TimeSpan[] { + TimeSpan.FromSeconds (5), + TimeSpan.FromSeconds(10), + TimeSpan.FromSeconds(30) + }, + (exception, timespan) => Log.Error (exception, "Exception when calling GetLibrarySections for Plex, Retrying {0}", timespan)); + + return lib; } catch (Exception e) { @@ -212,16 +201,17 @@ namespace PlexRequests.Api request.AddUrlSegment("libraryId", libraryId); AddHeaders(ref request, authToken); - var api = new ApiRequest(); try { - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (5), - TimeSpan.FromSeconds(10), - TimeSpan.FromSeconds(30) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan)); - - return (PlexSearch)policy.Execute(() => api.ExecuteXml(request, plexFullHost)); + var lib = RetryHandler.Execute(() => Api.ExecuteXml (request, plexFullHost), + new TimeSpan[] { + TimeSpan.FromSeconds (5), + TimeSpan.FromSeconds(10), + TimeSpan.FromSeconds(30) + }, + (exception, timespan) => Log.Error (exception, "Exception when calling GetLibrary for Plex, Retrying {0}", timespan)); + + return lib; } catch (Exception e) { diff --git a/PlexRequests.Api/RetryHandler.cs b/PlexRequests.Api/RetryHandler.cs index 20267b228..c9e336f9e 100644 --- a/PlexRequests.Api/RetryHandler.cs +++ b/PlexRequests.Api/RetryHandler.cs @@ -1,34 +1,71 @@ using System; using Polly.Retry; using Polly; +using System.Threading.Tasks; namespace PlexRequests.Api { public static class RetryHandler { - public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] TimeSpan, Action action) + + private static TimeSpan[] DefaultTime = new TimeSpan[] { + TimeSpan.FromSeconds (2), + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(10)}; + + public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] timeSpan, Action action) { + if(timeSpan == null) + { + timeSpan = DefaultTime; + } var policy = Policy.Handle () - .WaitAndRetry(TimeSpan, (exception, timeSpan) => action()); + .WaitAndRetry(timeSpan, (e, ts) => action()); return policy; } - public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] TimeSpan) + public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] timeSpan) { + if(timeSpan == null) + { + timeSpan = DefaultTime; + } var policy = Policy.Handle () - .WaitAndRetry(TimeSpan); + .WaitAndRetry(timeSpan); return policy; } - public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] TimeSpan, Action action) + public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] timeSpan, Action action) { + if(timeSpan == null) + { + timeSpan = DefaultTime; + } var policy = Policy.Handle () - .WaitAndRetry(TimeSpan, (exception, timeSpan) => action(exception, timeSpan)); + .WaitAndRetry(timeSpan, (exception, ts) => action(exception, ts)); return policy; } + + public static T Execute(Func action, TimeSpan[] timeSpan) + { + var policy = RetryAndWaitPolicy (timeSpan); + + return policy.Execute (action); + } + + public static T Execute(Func func, TimeSpan[] timeSpan, Action action) + { + if(timeSpan == null) + { + timeSpan = DefaultTime; + } + var policy = RetryAndWaitPolicy (timeSpan, action); + + return policy.Execute (func); + } } } diff --git a/PlexRequests.Api/SickrageApi.cs b/PlexRequests.Api/SickrageApi.cs index 72dc9d468..9ecc535c2 100644 --- a/PlexRequests.Api/SickrageApi.cs +++ b/PlexRequests.Api/SickrageApi.cs @@ -83,11 +83,7 @@ namespace PlexRequests.Api request.AddQueryParameter("initial", quality); } - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling AddSeries for SR, Retrying {0}", timespan)); + var policy = RetryHandler.RetryAndWaitPolicy (null,(exception, timespan) => Log.Error (exception, "Exception when calling AddSeries for SR, Retrying {0}", timespan)); var obj = policy.Execute( () => Api.Execute(request, baseUrl)); @@ -164,11 +160,7 @@ namespace PlexRequests.Api }; - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling Ping for SR, Retrying {0}", timespan)); + var policy = RetryHandler.RetryAndWaitPolicy (null,(exception, timespan) => Log.Error (exception, "Exception when calling Ping for SR, Retrying {0}", timespan)); @@ -191,11 +183,8 @@ namespace PlexRequests.Api try { - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling VerifyShowHasLoaded for SR, Retrying {0}", timespan)); + var policy = RetryHandler.RetryAndWaitPolicy (null,(exception, timespan) => + Log.Error (exception, "Exception when calling VerifyShowHasLoaded for SR, Retrying {0}", timespan)); var obj = policy.Execute( () => Api.ExecuteJson(request, baseUrl)); @@ -224,12 +213,8 @@ namespace PlexRequests.Api return await Task.Run(() => { - var policy = RetryHandler.RetryAndWaitPolicy (new TimeSpan[] { - TimeSpan.FromSeconds (2), - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10) - }, (exception, timespan) => Log.Error (exception, "Exception when calling AddSeason for SR, Retrying {0}", timespan)); - + var policy = RetryHandler.RetryAndWaitPolicy (null,(exception, timespan) => + Log.Error (exception, "Exception when calling AddSeason for SR, Retrying {0}", timespan)); var result = policy.Execute(() => Api.Execute(request, baseUrl)); @@ -255,8 +240,8 @@ namespace PlexRequests.Api TimeSpan.FromSeconds (5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30) - }, (exception, timespan) => Log.Error (exception, "Exception when calling GetShows for SR, Retrying {0}", timespan)); - + }, (exception, timespan) => + Log.Error (exception, "Exception when calling GetShows for SR, Retrying {0}", timespan)); return policy.Execute(() => Api.Execute(request, baseUrl)); diff --git a/PlexRequests.Api/SonarrApi.cs b/PlexRequests.Api/SonarrApi.cs index 7d26a8d5e..b56e969a7 100644 --- a/PlexRequests.Api/SonarrApi.cs +++ b/PlexRequests.Api/SonarrApi.cs @@ -157,10 +157,10 @@ namespace PlexRequests.Api return policy.Execute(() => Api.ExecuteJson>(request, baseUrl)); } - catch (ApiRequestException) + catch (Exception e) { - Log.Error("There has been an API exception when getting the Sonarr Series"); - return null; + Log.Error(e, "There has been an API exception when getting the Sonarr Series"); + return null; } } } diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index a738e9951..36549b4d4 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -23,6 +23,10 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ +using System.Net; +using PlexRequests.Helpers.Exceptions; + + #endregion using System.Collections.Generic; @@ -273,18 +277,27 @@ namespace PlexRequests.UI.Modules return Response.AsJson(string.Empty); } - var users = PlexApi.GetUsers(token); - if (users == null) - { - return Response.AsJson(string.Empty); - } - if (users.User == null || users.User?.Length == 0) - { - return Response.AsJson(string.Empty); - } + try { + var users = PlexApi.GetUsers(token); + if (users == null) + { + return Response.AsJson(string.Empty); + } + if (users.User == null || users.User?.Length == 0) + { + return Response.AsJson(string.Empty); + } - var usernames = users.User.Select(x => x.Title); - return Response.AsJson(usernames); + var usernames = users.User.Select(x => x.Title); + return Response.AsJson(new {Result = true, Users = usernames}); + } catch (Exception ex) { + Log.Error (ex); + if (ex is WebException || ex is ApiRequestException) { + return Response.AsJson (new { Result = false, Message ="Could not load the user list! We have connectivity problems connecting to Plex, Please ensure we can access Plex.Tv, The error has been logged." }); + } + + return Response.AsJson (new { Result = false, Message = ex.Message}); + } } private Negotiator CouchPotato() diff --git a/PlexRequests.UI/Modules/ApplicationTesterModule.cs b/PlexRequests.UI/Modules/ApplicationTesterModule.cs index 69e2df08d..55df3310f 100644 --- a/PlexRequests.UI/Modules/ApplicationTesterModule.cs +++ b/PlexRequests.UI/Modules/ApplicationTesterModule.cs @@ -87,7 +87,7 @@ namespace PlexRequests.UI.Modules : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to CouchPotato, please check your settings." }); } - catch (ApplicationException e) // Exceptions are expected if we cannot connect so we will just log and swallow them. + catch (Exception e) // Exceptions are expected if we cannot connect so we will just log and swallow them. { Log.Warn("Exception thrown when attempting to get CP's status: "); Log.Warn(e); @@ -116,7 +116,7 @@ namespace PlexRequests.UI.Modules : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Sonarr, please check your settings." }); } - catch (ApplicationException e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. + catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. { Log.Warn("Exception thrown when attempting to get Sonarr's status: "); Log.Warn(e); @@ -150,7 +150,7 @@ namespace PlexRequests.UI.Modules : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Plex, please check your settings." }); } - catch (ApplicationException e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. + catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. { Log.Warn("Exception thrown when attempting to get Plex's status: "); Log.Warn(e); @@ -179,7 +179,7 @@ namespace PlexRequests.UI.Modules : Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to SickRage, please check your settings." }); } - catch (ApplicationException e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. + catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them. { Log.Warn("Exception thrown when attempting to get SickRage's status: "); Log.Warn(e); @@ -214,7 +214,7 @@ namespace PlexRequests.UI.Modules } return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Headphones, please check your settings." }); } - catch (ApplicationException e) + catch (Exception e) { Log.Warn("Exception thrown when attempting to get Headphones's status: "); Log.Warn(e); diff --git a/PlexRequests.UI/Modules/LoginModule.cs b/PlexRequests.UI/Modules/LoginModule.cs index 83616a80b..a8a02baba 100644 --- a/PlexRequests.UI/Modules/LoginModule.cs +++ b/PlexRequests.UI/Modules/LoginModule.cs @@ -46,6 +46,7 @@ namespace PlexRequests.UI.Modules { { dynamic model = new ExpandoObject(); + model.Redirect = Request.Query.redirect.Value ?? string.Empty; model.Errored = Request.Query.error.HasValue; var adminCreated = UserMapper.DoUsersExist(); model.AdminExists = adminCreated; @@ -61,6 +62,7 @@ namespace PlexRequests.UI.Modules var username = (string)Request.Form.Username; var password = (string)Request.Form.Password; var dtOffset = (int)Request.Form.DateTimeOffset; + var redirect = (string)Request.Form.Redirect; var userId = UserMapper.ValidateUser(username, password); @@ -75,12 +77,8 @@ namespace PlexRequests.UI.Modules } Session[SessionKeys.UsernameKey] = username; Session[SessionKeys.ClientDateTimeOffsetKey] = dtOffset; - if (!string.IsNullOrEmpty(BaseUrl)) - { - return this.LoginAndRedirect(userId.Value, expiry, $"/{BaseUrl}"); - } - return this.LoginAndRedirect(userId.Value, expiry); + return this.LoginAndRedirect(userId.Value, expiry, redirect); }; Get["/register"] = x => diff --git a/PlexRequests.UI/Views/Admin/Authentication.cshtml b/PlexRequests.UI/Views/Admin/Authentication.cshtml index d223db1b8..1abbd3788 100644 --- a/PlexRequests.UI/Views/Admin/Authentication.cshtml +++ b/PlexRequests.UI/Views/Admin/Authentication.cshtml @@ -153,10 +153,17 @@ url = createBaseUrl(base, url); $.ajax({ type: "Get", - url: "getusers", + url: url, dataType: "json", success: function (response) { - if (response.length > 1) { + + $('#users').html(""); + if(!response.result){ + generateNotify(response.message,"danger"); + $('#users').append(""); + return; + } + if (response.users.length > 1) { $(response).each(function () { $('#users').append(""); }); @@ -167,6 +174,8 @@ error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); + $('#users').html(""); + $('#users').append(""); } }); diff --git a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml index fb54a6c33..0e52986e2 100644 --- a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml +++ b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml @@ -88,7 +88,7 @@
- +
@@ -170,6 +170,8 @@ e.preventDefault(); var $form = $("#mainForm"); var url = createBaseUrl(baseUrl,"/test/cp"); + $('#spinner').attr("class", "fa fa-spinner fa-spin"); + $.ajax({ type: $form.prop("method"), url: url, @@ -178,15 +180,18 @@ success: function (response) { console.log(response); if (response.result === true) { + $('#spinner').attr("class", "fa fa-check"); generateNotify(response.message, "success"); $('#authToken').val(response.authToken); } else { generateNotify(response.message, "warning"); + $('#spinner').attr("class", "fa fa-times"); } }, error: function (e) { console.log(e); - generateNotify("Something went wrong!", "danger"); + generateNotify("Something went wrong!", "danger"); + $('#spinner').attr("class", "fa fa-times"); } }); }); diff --git a/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml b/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml index 978283d2c..ef12311e3 100644 --- a/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml +++ b/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml @@ -106,7 +106,7 @@
- +
@@ -150,7 +150,8 @@ }); }); - $('#testEmail').click(function (e) { + $('#testEmail').click(function (e) { + $('#spinner').attr("class", "fa fa-spinner fa-spin"); var url = createBaseUrl(base, '/admin/testemailnotification'); e.preventDefault(); @@ -167,13 +168,16 @@ dataType: "json", success: function (response) { if (response.result === true) { + $('#spinner').attr("class", "fa fa-check"); generateNotify(response.message, "success"); } else { + $('#spinner').attr("class", "fa fa-times"); generateNotify(response.message, "warning"); } }, error: function (e) { console.log(e); + $('#spinner').attr("class", "fa fa-times"); generateNotify("Something went wrong!", "danger"); } }); diff --git a/PlexRequests.UI/Views/Admin/Headphones.cshtml b/PlexRequests.UI/Views/Admin/Headphones.cshtml index 47629aebc..4145b53bf 100644 --- a/PlexRequests.UI/Views/Admin/Headphones.cshtml +++ b/PlexRequests.UI/Views/Admin/Headphones.cshtml @@ -75,7 +75,7 @@
- +
@@ -96,6 +96,8 @@ var base = '@Html.GetBaseUrl()'; $('#testHeadphones').click(function (e) { + + $('#spinner').attr("class", "fa fa-spinner fa-spin"); e.preventDefault(); var $form = $("#mainForm"); var url = createBaseUrl(base, '/test/headphones'); @@ -107,13 +109,16 @@ success: function (response) { console.log(response); if (response.result === true) { + $('#spinner').attr("class", "fa fa-check"); generateNotify(response.message, "success"); } else { + $('#spinner').attr("class", "fa fa-times"); generateNotify(response.message, "warning"); } }, error: function (e) { console.log(e); + $('#spinner').attr("class", "fa fa-times"); generateNotify("Something went wrong!", "danger"); } }); diff --git a/PlexRequests.UI/Views/Admin/Plex.cshtml b/PlexRequests.UI/Views/Admin/Plex.cshtml index 7282218d1..a4b9a2787 100644 --- a/PlexRequests.UI/Views/Admin/Plex.cshtml +++ b/PlexRequests.UI/Views/Admin/Plex.cshtml @@ -52,7 +52,7 @@
- +
@@ -69,25 +69,34 @@