using System.Collections.Generic;
using System.Threading.Tasks;
using Dpz.Core.Web.Dashboard.Models;
using Dpz.Core.Web.Dashboard.Service;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MudBlazor;
namespace Dpz.Core.Web.Dashboard.Pages.Logs;
public partial class List
{
[Inject] private ILogService LogService { get; set; }
[Inject] private IDialogService DialogService { get; set; }
[Inject] private IJSRuntime JsRuntime { get; set; }
#region query parameter
private int _pageIndex = 1;
private string _logger = "";
private string _level = "";
private string _message = "";
private const int PageSize = 12;
#endregion
private MudTable<LogModel> _table;
private IList<string> _loggerList = new List<string>();
private IList<string> _levelList = new List<string>();
protected override async Task OnInitializedAsync()
{
_levelList = await LogService.GetLevelAsync();
_loggerList = await LogService.GetLoggerAsync();
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JsRuntime.InvokeVoidAsync("Prism.highlightAll");
await base.OnAfterRenderAsync(firstRender);
}
private async Task<TableData<LogModel>> LoadDataAsync(TableState state)
{
_pageIndex = _isSearch ? 1 : state.Page + 1;
var list = await LogService.GetPageAsync(_logger, _level, _message, _pageIndex, PageSize);
_isSearch = false;
return new TableData<LogModel>()
{
TotalItems = list.TotalItemCount,
Items = list
};
}
private bool _isSearch = false;
private void Search()
{
_isSearch = true;
_table.ReloadServerData();
}
private bool _viewLoading;
private async Task ViewDetailAsync(LogModel model)
{
_viewLoading = true;
if (string.IsNullOrEmpty(model.Detail))
{
model.Detail = await LogService.GetDetailAsync(model.Id);
}
_viewLoading = false;
model.ShowDetail = !model.ShowDetail;
}
}