This commit is contained in:
tidusjar 2016-06-27 16:16:33 +01:00
commit 6aae347297
2 changed files with 172 additions and 122 deletions

View file

@ -46,6 +46,8 @@ using NLog;
using MarkdownSharp;
using Nancy.Responses;
using PlexRequests.Api;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
@ -204,6 +206,8 @@ namespace PlexRequests.UI.Modules
Get["/scheduledjobs", true] = async (x, ct) => await GetScheduledJobs();
Post["/scheduledjobs", true] = async (x, ct) => await SaveScheduledJobs();
Post["/clearlogs", true] = async (x, ct) => await ClearLogs();
}
private async Task<Negotiator> Authentication()
@ -888,5 +892,23 @@ namespace PlexRequests.UI.Modules
? new JsonResponseModel { Result = true }
: new JsonResponseModel { Result = false, Message = "Could not save to Db Please check the logs" });
}
private async Task<Response> ClearLogs()
{
try
{
var allLogs = await LogsRepo.GetAllAsync();
foreach (var logEntity in allLogs)
{
await LogsRepo.DeleteAsync(logEntity);
}
return Response.AsJson(new JsonResponseModel { Result = true });
}
catch (Exception e)
{
Log.Error(e);
return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message });
}
}
}
}

View file

@ -5,9 +5,11 @@
@{
var baseUrl = Html.GetBaseUrl();
var formAction = "/admin/loglevel";
var clearAction = "/admin/clearlogs";
if (!string.IsNullOrEmpty(baseUrl.ToHtmlString()))
{
formAction = "/" + baseUrl.ToHtmlString() + formAction;
clearAction = "/" + baseUrl.ToHtmlString() + clearAction;
}
}
@ -35,6 +37,10 @@
</div>
</form>
<form method="post" id="clearForm" action="@clearAction">
<button id="clearLogs" type="submit" class="btn btn-danger-outline ">Clear Logs</button>
</form>
<table id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
@ -118,6 +124,28 @@
});
});
$('#clearLogs').click(function() {
e.preventDefault();
var $form = $("#clearForm");
$.ajax({
type: $form.prop("method"),
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>