event log UI improvements

This commit is contained in:
Shaun Walker 2019-10-23 10:13:58 -04:00
parent e710fd61ca
commit 7f9e47edb6
13 changed files with 314 additions and 19 deletions

View File

@ -0,0 +1,179 @@
@namespace Oqtane.Modules.Admin.Logs
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject ILogService LogService
@inject IPageService PageService
@inject IPageModuleService PageModuleService
@inject IUserService UserService
<table class="table table-borderless">
<tr>
<td>
<label class="control-label">Date: </label>
</td>
<td>
<input class="form-control" @bind="@logdate" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Category: </label>
</td>
<td>
<input class="form-control" @bind="@category" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Level: </label>
</td>
<td>
<input class="form-control" @bind="@level" disabled />
</td>
</tr>
@if (pagename != "")
{
<tr>
<td>
<label class="control-label">Page: </label>
</td>
<td>
<input class="form-control" @bind="@pagename" disabled />
</td>
</tr>
}
@if (moduletitle != "")
{
<tr>
<td>
<label class="control-label">Module: </label>
</td>
<td>
<input class="form-control" @bind="@moduletitle" disabled />
</td>
</tr>
}
@if (username != "")
{
<tr>
<td>
<label class="control-label">User: </label>
</td>
<td>
<input class="form-control" @bind="@username" disabled />
</td>
</tr>
}
<tr>
<td>
<label class="control-label">Template: </label>
</td>
<td>
<input class="form-control" @bind="@template" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Message: </label>
</td>
<td>
<textarea class="form-control" @bind="@message" rows="5" disabled />
</td>
</tr>
@if (!string.IsNullOrEmpty(exception))
{
<tr>
<td>
<label class="control-label">Exception: </label>
</td>
<td>
<textarea class="form-control" @bind="@exception" rows="5" disabled />
</td>
</tr>
}
<tr>
<td>
<label class="control-label">Properties: </label>
</td>
<td>
<textarea class="form-control" @bind="@properties" rows="5" disabled />
</td>
</tr>
<tr>
<td>
<label class="control-label">Server: </label>
</td>
<td>
<input class="form-control" @bind="@server" disabled />
</td>
</tr>
</table>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int logid;
string logdate = "";
string category = "";
string level = "";
string pagename = "";
string moduletitle = "";
string username = "";
string url = "";
string template = "";
string message = "";
string exception = "";
string properties = "";
string server = "";
protected override async Task OnInitializedAsync()
{
try
{
logid = Int32.Parse(PageState.QueryString["id"]);
Log log = await LogService.GetLogAsync(logid);
if (log != null)
{
logdate = log.LogDate.ToString();
category = log.Category;
level = log.Level;
if (log.PageId != null)
{
Page page = await PageService.GetPageAsync(log.PageId.Value);
if (page != null)
{
pagename = page.Name;
}
}
if (log.PageId != null && log.ModuleId != null)
{
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(log.PageId.Value, log.ModuleId.Value);
if (pagemodule != null)
{
moduletitle = pagemodule.Title;
}
}
if (log.UserId != null)
{
User user = await UserService.GetUserAsync(log.UserId.Value, PageState.Site.SiteId);
if (user != null)
{
username = user.Username;
}
}
url = log.Url;
template = log.MessageTemplate;
message = log.Message;
exception = log.Exception;
properties = log.Properties;
server = log.Server;
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Log {LogId} {Error}", logid, ex.Message);
AddModuleMessage("Error Loading Log", MessageType.Error);
}
}
}

View File

@ -8,20 +8,36 @@
}
else
{
<div class="form-group">
<label>Level: </label>
<select class="form-control" @onchange="(e => LevelChanged(e))">
<option value="-">&lt;All Levels&gt;</option>
<option value="Trace">Trace</option>
<option value="Debug">Debug</option>
<option value="Information">Information</option>
<option value="Warning">Warning</option>
<option value="Error">Error</option>
<option value="Critical">Critical</option>
</select>
<label>Rows: </label>
<select class="form-control" @onchange="(e => RowsChanged(e))">
<option value="10">10</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
<Pager Items="@Logs">
<Header>
<th>Date</th>
<th>Level</th>
<th>Url</th>
<th>Category</th>
<th>Message</th>
<th>Level</th>
<th>&nbsp;</th>
</Header>
<Row>
<td>@context.LogDate</td>
<td>@context.Level</td>
<td>@context.Url</td>
<td>@context.Category</td>
<td>@context.Message</td>
<td>@context.Level</td>
<td><ActionLink Action="Detail" Parameters="@($"id=" + context.LogId.ToString())" /></td>
</Row>
</Pager>
}
@ -29,10 +45,50 @@ else
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string level = "-";
string rows = "50";
List<Log> Logs;
protected override async Task OnInitializedAsync()
{
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId);
try
{
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Logs {Error}", ex.Message);
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
private async void LevelChanged(ChangeEventArgs e)
{
try
{
level = (string)e.Value;
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Logs {Error}", ex.Message);
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
private async void RowsChanged(ChangeEventArgs e)
{
try
{
rows = (string)e.Value;
Logs = await LogService.GetLogsAsync(PageState.Site.SiteId, ((level == "-") ? "" : level), int.Parse(rows));
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Logs {Error}", ex.Message);
AddModuleMessage("Error Loading Logs", MessageType.Error);
}
}
}

View File

@ -8,7 +8,8 @@ namespace Oqtane.Services
{
public interface ILogService
{
Task<List<Log>> GetLogsAsync(int SiteId);
Task<List<Log>> GetLogsAsync(int SiteId, string Level, int Rows);
Task<Log> GetLogAsync(int LogId);
Task Log(int? PageId, int? ModuleId, int? UserId, string component, LogLevel level, Exception exception, string message, params object[] args);
}
}

View File

@ -8,6 +8,7 @@ namespace Oqtane.Services
{
Task<List<PageModule>> GetPageModulesAsync();
Task<PageModule> GetPageModuleAsync(int PageModuleId);
Task<PageModule> GetPageModuleAsync(int PageId, int ModuleId);
Task<PageModule> AddPageModuleAsync(PageModule PageModule);
Task<PageModule> UpdatePageModuleAsync(PageModule PageModule);
Task UpdatePageModuleOrderAsync(int PageId, string Pane);

View File

@ -27,9 +27,14 @@ namespace Oqtane.Services
get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Log"); }
}
public async Task<List<Log>> GetLogsAsync(int SiteId)
public async Task<List<Log>> GetLogsAsync(int SiteId, string Level, int Rows)
{
return await http.GetJsonAsync<List<Log>>(apiurl + "?siteid=" + SiteId.ToString());
return await http.GetJsonAsync<List<Log>>(apiurl + "?siteid=" + SiteId.ToString() + "&level=" + Level + "&rows=" + Rows.ToString());
}
public async Task<Log> GetLogAsync(int LogId)
{
return await http.GetJsonAsync<Log>(apiurl + "/" + LogId.ToString());
}
public async Task Log(int? PageId, int? ModuleId, int? UserId, string category, LogLevel level, Exception exception, string message, params object[] args)

View File

@ -36,6 +36,11 @@ namespace Oqtane.Services
return await http.GetJsonAsync<PageModule>(apiurl + "/" + PageModuleId.ToString());
}
public async Task<PageModule> GetPageModuleAsync(int PageId, int ModuleId)
{
return await http.GetJsonAsync<PageModule>(apiurl + "/" + PageId.ToString() + "/" + ModuleId.ToString());
}
public async Task<PageModule> AddPageModuleAsync(PageModule PageModule)
{
return await http.PostJsonAsync<PageModule>(apiurl, PageModule);

View File

@ -3,6 +3,8 @@ using Oqtane.Models;
using System.Collections.Generic;
using Oqtane.Repository;
using Oqtane.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Oqtane.Shared;
namespace Oqtane.Controllers
{
@ -19,11 +21,20 @@ namespace Oqtane.Controllers
this.Logs = Logs;
}
// GET: api/<controller>?siteid=x
// GET: api/<controller>?siteid=x&level=y
[HttpGet]
public IEnumerable<Log> Get(string siteid)
[Authorize(Roles = Constants.AdminRole)]
public IEnumerable<Log> Get(string siteid, string level, string rows)
{
return Logs.GetLogs(int.Parse(siteid));
return Logs.GetLogs(int.Parse(siteid), level, int.Parse(rows));
}
// GET api/<controller>/5
[HttpGet("{id}")]
[Authorize(Roles = Constants.AdminRole)]
public Log Get(int id)
{
return Logs.GetLog(id);
}
// POST api/<controller>

View File

@ -37,6 +37,13 @@ namespace Oqtane.Controllers
return PageModules.GetPageModule(id);
}
// GET: api/<controller>/pageid/moduleid
[HttpGet("{pageid}/{moduleid}")]
public PageModule Get(int pageid, int moduleid)
{
return PageModules.GetPageModule(pageid, moduleid);
}
// POST api/<controller>
[HttpPost]
[Authorize(Roles = Constants.AdminRole)]

View File

@ -22,6 +22,7 @@ namespace Oqtane.Controllers
// GET: api/<controller>
[HttpGet]
[Authorize(Roles = Constants.HostRole)]
public IEnumerable<Tenant> Get()
{
return Tenants.GetTenants();
@ -29,6 +30,7 @@ namespace Oqtane.Controllers
// GET api/<controller>/5
[HttpGet("{id}")]
[Authorize(Roles = Constants.HostRole)]
public Tenant Get(int id)
{
return Tenants.GetTenant(id);

View File

@ -5,7 +5,8 @@ namespace Oqtane.Repository
{
public interface ILogRepository
{
IEnumerable<Log> GetLogs(int SiteId, string Level, int Rows);
Log GetLog(int LogId);
void AddLog(Log Log);
IEnumerable<Log> GetLogs(int SiteId);
}
}

View File

@ -10,6 +10,7 @@ namespace Oqtane.Repository
PageModule AddPageModule(PageModule PageModule);
PageModule UpdatePageModule(PageModule PageModule);
PageModule GetPageModule(int PageModuleId);
PageModule GetPageModule(int PageId, int ModuleId);
void DeletePageModule(int PageModuleId);
}
}

View File

@ -14,15 +14,29 @@ namespace Oqtane.Repository
db = context;
}
public IEnumerable<Log> GetLogs(int SiteId, string Level, int Rows)
{
if (Level == null)
{
return db.Log.Where(item => item.SiteId == SiteId).
OrderByDescending(item => item.LogDate).Take(Rows);
}
else
{
return db.Log.Where(item => item.SiteId == SiteId && item.Level == Level)
.OrderByDescending(item => item.LogDate).Take(Rows);
}
}
public Log GetLog(int LogId)
{
return db.Log.Find(LogId);
}
public void AddLog(Log Log)
{
db.Log.Add(Log);
db.SaveChanges();
}
public IEnumerable<Log> GetLogs(int SiteId)
{
return db.Log.Where(item => item.SiteId == SiteId).OrderByDescending(item=> item.LogDate).Take(50);
}
}
}

View File

@ -62,6 +62,18 @@ namespace Oqtane.Repository
return pagemodule;
}
public PageModule GetPageModule(int PageId, int ModuleId)
{
PageModule pagemodule = db.PageModule.Include(item => item.Module) // eager load modules
.SingleOrDefault(item => item.PageId == PageId && item.ModuleId == ModuleId);
if (pagemodule != null)
{
IEnumerable<Permission> permissions = Permissions.GetPermissions("Module", pagemodule.ModuleId);
pagemodule.Module.Permissions = Permissions.EncodePermissions(pagemodule.ModuleId, permissions);
}
return pagemodule;
}
public void DeletePageModule(int PageModuleId)
{
PageModule PageModule = db.PageModule.Find(PageModuleId);