- Improved the RetryHandler.

- Made the tester buttons on the settings pages a bit more robust and added an indication when it's testing (spinner)
pull/226/head
TidusJar 8 years ago
parent 96abba49f7
commit 741a4ae75c

@ -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<JObject>(() => Api.ExecuteJson<JObject> (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<JObject>(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<CouchPotatoStatus>(() => Api.Execute<CouchPotatoStatus> (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<CouchPotatoStatus>(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<CouchPotatoProfiles>(request,url));
var obj = RetryHandler.Execute<CouchPotatoProfiles>(() => Api.Execute<CouchPotatoProfiles> (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<CouchPotatoMovies>(request,baseUrl));
var obj = RetryHandler.Execute<CouchPotatoMovies>(() => Api.Execute<CouchPotatoMovies> (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
{

@ -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<HeadphonesGetIndex>();

@ -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<PlexAuthentication>(request, new Uri("https://plex.tv/users/sign_in.json")));
var obj = RetryHandler.Execute<PlexAuthentication>(() => Api.Execute<PlexAuthentication> (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<PlexFriends>(request, new Uri("https://plex.tv/pms/friends/all")));
var users = RetryHandler.Execute<PlexFriends>(() => Api.Execute<PlexFriends> (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<PlexSearch>(request, plexFullHost));
var search = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (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<PlexStatus>(request, uri));
var users = RetryHandler.Execute<PlexStatus>(() => Api.ExecuteXml<PlexStatus> (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<PlexAccount>(request, new Uri("https://plex.tv/users/account")));
var account = RetryHandler.Execute<PlexAccount>(() => Api.ExecuteXml<PlexAccount> (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<PlexLibraries>(request, plexFullHost));
var lib = RetryHandler.Execute<PlexLibraries>(() => Api.ExecuteXml<PlexLibraries> (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<PlexSearch>(request, plexFullHost));
var lib = RetryHandler.Execute<PlexSearch>(() => Api.ExecuteXml<PlexSearch> (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)
{

@ -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<Exception> ()
.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<Exception> ()
.WaitAndRetry(TimeSpan);
.WaitAndRetry(timeSpan);
return policy;
}
public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] TimeSpan, Action<Exception, TimeSpan> action)
public static RetryPolicy RetryAndWaitPolicy(TimeSpan[] timeSpan, Action<Exception, TimeSpan> action)
{
if(timeSpan == null)
{
timeSpan = DefaultTime;
}
var policy = Policy.Handle<Exception> ()
.WaitAndRetry(TimeSpan, (exception, timeSpan) => action(exception, timeSpan));
.WaitAndRetry(timeSpan, (exception, ts) => action(exception, ts));
return policy;
}
public static T Execute<T>(Func<T> action, TimeSpan[] timeSpan)
{
var policy = RetryAndWaitPolicy (timeSpan);
return policy.Execute (action);
}
public static T Execute<T>(Func<T> func, TimeSpan[] timeSpan, Action<Exception, TimeSpan> action)
{
if(timeSpan == null)
{
timeSpan = DefaultTime;
}
var policy = RetryAndWaitPolicy (timeSpan, action);
return policy.Execute (func);
}
}
}

@ -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<SickRageTvAdd>(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<SickRageSeasonList>(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<SickRageTvAdd>(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<SickrageShows>(request, baseUrl));

@ -157,10 +157,10 @@ namespace PlexRequests.Api
return policy.Execute(() => Api.ExecuteJson<List<Series>>(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;
}
}
}

@ -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()

@ -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);

@ -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 =>

@ -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("<option>Error!</option>");
return;
}
if (response.users.length > 1) {
$(response).each(function () {
$('#users').append("<option>" + this + "</option>");
});
@ -167,6 +174,8 @@
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
$('#users').html("");
$('#users').append("<option>Error!</option>");
}
});

@ -88,7 +88,7 @@
<div class="form-group">
<div>
<button id="testCp" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
<button id="testCp" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"> </div></button>
</div>
</div>
@ -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");
}
});
});

@ -106,7 +106,7 @@
<div class="form-group">
<div>
<button id="testEmail" type="submit" class="btn btn-primary-outline">Test</button>
<button id="testEmail" type="submit" class="btn btn-primary-outline">Test <div id="spinner"></div></button>
</div>
</div>
@ -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");
}
});

@ -75,7 +75,7 @@
<div class="form-group">
<div>
<button id="testHeadphones" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
<button id="testHeadphones" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"></div></button>
</div>
</div>
@ -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");
}
});

@ -52,7 +52,7 @@
</div>
<div class="form-group">
<div>
<button id="testPlex" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
<button id="testPlex" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"></div></button>
</div>
</div>
@ -69,25 +69,34 @@
<script>
$(function () {
var base = '@Html.GetBaseUrl()';
$('#testPlex').click(function (e) {
e.preventDefault();
var url = createBaseUrl(base, '/test/plex');
var $form = $("#mainForm");
$('#spinner').attr("class", "fa fa-spinner fa-spin");
$.ajax({
type: $form.prop("method"),
url: url,
data: $form.serialize(),
dataType: "json",
success: function (response) {
$('#spinner').attr("class", "");
console.log(response);
if (response.result === true) {
generateNotify(response.message, "success");
$('#spinner').attr("class", "fa fa-check");
$('#authToken').val(response.authToken);
} else {
generateNotify(response.message, "warning");
$('#spinner').attr("class", "fa fa-times");
}
},
error: function (e) {
$('#spinner').attr("class", "fa fa-times");
console.log(e);
generateNotify("Something went wrong!", "danger");
}

@ -39,7 +39,7 @@
<div class="form-group">
<div>
<button id="testPushbullet" type="submit" class="btn btn-primary-outline">Test</button>
<button id="testPushbullet" type="submit" class="btn btn-primary-outline">Test <div id="spinner"></div></button>
</div>
</div>
@ -56,6 +56,8 @@
$(function () {
var base = '@Html.GetBaseUrl()';
$('#save').click(function (e) {
$('#spinner').attr("class", "fa fa-spinner fa-spin");
e.preventDefault();
var $form = $("#mainForm");
@ -67,12 +69,15 @@
success: function (response) {
if (response.result === true) {
generateNotify(response.message, "success");
$('#spinner').attr("class", "fa fa-check");
} else {
generateNotify(response.message, "warning");
$('#spinner').attr("class", "fa fa-times");
}
},
error: function (e) {
console.log(e);
$('#spinner').attr("class", "fa fa-times");
generateNotify("Something went wrong!", "danger");
}
});

@ -39,7 +39,7 @@
<div class="form-group">
<div>
<button id="testPushover" type="submit" class="btn btn-primary-outline">Test</button>
<button id="testPushover" type="submit" class="btn btn-primary-outline">Test <div id="spinner"></div></button>
</div>
</div>
@ -59,6 +59,7 @@
$('#save').click(function (e) {
e.preventDefault();
$('#spinner').attr("class", "fa fa-spinner fa-spin");
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
@ -68,13 +69,16 @@
success: function (response) {
if (response.result === true) {
generateNotify(response.message, "success");
$('#spinner').attr("class", "fa fa-check");
} else {
generateNotify(response.message, "warning");
$('#spinner').attr("class", "fa fa-times");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
$('#spinner').attr("class", "fa fa-times");
}
});
});

@ -86,7 +86,7 @@
<div class="form-group">
<div>
<button id="testSickRage" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
<button id="testSickRage" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"></div></button>
</div>
</div>
@ -147,6 +147,8 @@
});
$('#testSickRage').click(function (e) {
$('#spinner').attr("class", "fa fa-spinner fa-spin");
e.preventDefault();
var qualityProfile = $("#profiles option:selected").val();
@ -165,13 +167,16 @@
console.log(response);
if (response.result === true) {
generateNotify(response.message, "success");
$('#spinner').attr("class", "fa fa-check");
} else {
generateNotify(response.message, "warning");
$('#spinner').attr("class", "fa fa-times");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
$('#spinner').attr("class", "fa fa-times");
}
});
});

@ -73,7 +73,7 @@
</div>
<div class="form-group">
<div>
<button type="submit" id="getProfiles" class="btn btn-primary-outline">Get Quality Profiles</button>
<button type="submit" id="getProfiles" class="btn btn-primary-outline">Get Quality Profiles <div id="getSpinner"/></button>
</div>
</div>
<div class="form-group">
@ -109,7 +109,7 @@
</div>
<div class="form-group">
<div>
<button id="testSonarr" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
<button id="testSonarr" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"/></button>
</div>
</div>
@ -200,17 +200,22 @@
});
$('#getProfiles').click(function (e) {
$('#getSpinner').attr("class", "fa fa-spinner fa-spin");
e.preventDefault();
if (!$('#Ip').val()) {
generateNotify("Please enter a valid IP/Hostname.", "warning");
$('#getSpinner').attr("class", "fa fa-times");
return;
}
if (!$('#portNumber').val()) {
generateNotify("Please enter a valid Port Number.", "warning");
$('#getSpinner').attr("class", "fa fa-times");
return;
}
if (!$('#ApiKey').val()) {
generateNotify("Please enter a valid ApiKey.", "warning");
$('#getSpinner').attr("class", "fa fa-times");
return;
}
var $form = $("#mainForm");
@ -221,11 +226,13 @@
dataType: "json",
success: function (response) {
response.forEach(function (result) {
$('#getSpinner').attr("class", "fa fa-check");
$("#select").append("<option value='" + result.id + "'>" + result.name + "</option>");
});
},
error: function (e) {
console.log(e);
$('#getSpinner').attr("class", "fa fa-times");
generateNotify("Something went wrong!", "danger");
}
});
@ -233,6 +240,8 @@
var base = '@Html.GetBaseUrl()';
$('#testSonarr').click(function (e) {
$('#spinner').attr("class", "fa fa-spinner fa-spin");
e.preventDefault();
var qualityProfile = $("#profiles option:selected").val();
@ -251,13 +260,16 @@
console.log(response);
if (response.result === true) {
generateNotify(response.message, "success");
$('#spinner').attr("class", "fa fa-check");
} else {
generateNotify(response.message, "warning");
$('#spinner').attr("class", "fa fa-times");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
$('#spinner').attr("class", "fa fa-times");
}
});
});

@ -16,6 +16,7 @@
<br/><br/>
<input class="btn btn-success-outline" type="submit" value="Login"/>
<input type="hidden" id="DateTimeOffset" name="DateTimeOffset" />
<input type="hidden" id="redirect" name="redirect" value="@Model.Redirect"/>
</form>
@if (!Model.AdminExists)
{

@ -45,7 +45,8 @@
@if (!Context.CurrentUser.IsAuthenticated())
{
<li><a href="@url/login"><i class="fa fa-user"></i> Admin</a></li>
<li><a href="@url/login?redirect=@Context.Request.Path"><i class="fa fa-user"></i> Admin</a></li>
}
else
{

Loading…
Cancel
Save