Skip to content

Commit

Permalink
Merge pull request #697 from mixcore/feature/update-log-service
Browse files Browse the repository at this point in the history
update filter log
  • Loading branch information
nhathoang989 authored Sep 24, 2023
2 parents 5dee82b + 4b41cfa commit bb59dcf
Show file tree
Hide file tree
Showing 9 changed files with 4,041 additions and 3,783 deletions.
4,936 changes: 2,491 additions & 2,445 deletions src/applications/Mixcore/wwwroot/mix-app/js/app-portal.min.js

Large diffs are not rendered by default.

2,666 changes: 1,333 additions & 1,333 deletions src/applications/Mixcore/wwwroot/mix-app/js/app-shared.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="page-wrapper d-flex flex-column pt-4"><div class="container-xl"><div class="page-header d-print-none"><div class="row align-items-center"><div class="col"><div class="page-pretitle">Listing</div><h3 class="page-title">All Audit Logs</h3><div><a href="/admin/audit-log/stream" class="btn-link btn-primary">Log Streams</a></div></div></div></div></div><div class="page-body d-flex flex-row-reverse"><aside class="bd-sidebar sub-sidebar"><nav class="bd-links p-3" aria-label="Sub-section navigation"><div class="card card-body"><filter-list class="" request="request" callback="getList(pageIndex)"></filter-list></div></nav></aside><div class="content-body py-3 pe-3"><div class="card mb-5"><div class="card-body"><table id="list-page" class="table table-striped-x table-hover" dnd-list="data.items" dnd-disable-if="canDrag" cellspacing="0" ng-init="getList()"><thead class="thead-light"><tr><th scope="col" width="15px"><div class="form-check m-0 p-0"><input type="checkbox" class="form-check-inputx" ng-model="selectedList.isSelectAll" ng-change="selectAll(selectedList.isSelectAll)" id="customCheck_all"></div></th><th class="col">Endpoint</th><th class="col">Request Ip</th><th class="col">Created</th><th class="col">Created By</th><th class="col"></th><th class="col text-end"></th></tr></thead><tbody class=""><tr ng-repeat="item in data.items track by $index" dnd-draggable="item" dnd-effect-allowed="move" dnd-selected="selected = item" dnd-moved="updateInfos($index)" ng-class="{'selected': selected === item}" class="" sort-model="category" sort-model-id="{{item.id}}"><td class="align-middle"><div class="form-check"><input type="checkbox" class="form-check-input" id="customCheck_{{item.id}}" ng-model="item.isSelected" ng-change="select(item.id, item.isSelected)"> <label class="custom-control-label" for="customCheck_{{item.id}}"></label></div></td><td class=""><a href="" ng-click="view(item)" class="btn-link"><span ng-bind="item.endpoint|trim:50" ng-class="{'text-danger': !item.success}"></span></a></td><td><span ng-bind="item.requestIp|trim:50"></span></td><td class="text-secondary"><small>{{item.createdDateTime | utcToLocal:'dd.MM.yy hh:mm a'}}</small></td><td class="text-secondary"><small>{{item.createdBy}}</small></td><td><a class="dropdown-item border-radius-md" ng-click="view(item)"><span class="fa fa-eye"></span></a></td><td class="text-black-50"><small ng-if="item.status == 'Published'">🟢</small> <small ng-if="item.status == 'Schedule'">🟡</small> <small ng-if="item.status == 'Draft'">🔴</small> <small ng-if="item.status == 'Deleted'">⚫️</small></td></tr></tbody></table></div><div class="card-body"><paging class="small" page="data.pagingData.page" page-size="data.pagingData.pageSize" total="data.pagingData.total" ul-class="pagination justify-content-end m-0" a-class="page-link" paging-action="getList(page-1)" scroll-top="true"></paging></div></div></div></div></div>
<div class="page-wrapper d-flex flex-column pt-4"><div class="container-xl"><div class="page-header d-print-none"><div class="row align-items-center"><div class="col"><div class="page-pretitle">Listing</div><h3 class="page-title">All Audit Logs</h3><div><a href="/admin/audit-log/stream" class="btn-link btn-primary">Log Streams</a></div></div></div></div></div><div class="page-body d-flex flex-row-reverse"><aside class="bd-sidebar sub-sidebar"><nav class="bd-links p-3" aria-label="Sub-section navigation"><div class="card card-body"><filter-list class="" request="request" callback="getList(pageIndex)"></filter-list></div></nav></aside><div class="content-body py-3 pe-3"><div class="card mb-5" ng-init="getList()"><div ng-repeat="result in data.results track by $index" ng-if="result.data"><h3 ng-bind="result.searchDate | utcToLocal:'dd.MM.yy'"></h3><div class="card-body"><table id="list-page" class="table table-striped-x table-hover" dnd-list="data.items" dnd-disable-if="canDrag" cellspacing="0"><thead class="thead-light"><tr><th scope="col" width="15px"><div class="form-check m-0 p-0"><input type="checkbox" class="form-check-inputx" ng-model="selectedList.isSelectAll" ng-change="selectAll(selectedList.isSelectAll)" id="customCheck_all"></div></th><th class="col">Endpoint</th><th class="col">Request Ip</th><th class="col">Created</th><th class="col">Created By</th><th class="col"></th><th class="col text-end"></th></tr></thead><tbody class=""><tr ng-repeat="item in result.data.items track by $index" dnd-draggable="item" dnd-effect-allowed="move" dnd-selected="selected = item" dnd-moved="updateInfos($index)" ng-class="{'selected': selected === item}" class="" sort-model="category" sort-model-id="{{item.id}}"><td class="align-middle"><div class="form-check"><input type="checkbox" class="form-check-input" id="customCheck_{{item.id}}" ng-model="item.isSelected" ng-change="select(item.id, item.isSelected)"> <label class="custom-control-label" for="customCheck_{{item.id}}"></label></div></td><td class=""><a href="" ng-click="view(item)" class="btn-link"><span ng-bind="item.endpoint|trim:50" ng-class="{'text-danger': !item.success}"></span></a></td><td><span ng-bind="item.requestIp|trim:50"></span></td><td class="text-secondary"><small>{{item.createdDateTime | utcToLocal:'dd.MM.yy hh:mm a'}}</small></td><td class="text-secondary"><small>{{item.createdBy}}</small></td><td><a class="dropdown-item border-radius-md" ng-click="view(item)"><span class="fa fa-eye"></span></a></td><td class="text-black-50"><small ng-if="item.status == 'Published'">🟢</small> <small ng-if="item.status == 'Schedule'">🟡</small> <small ng-if="item.status == 'Draft'">🔴</small> <small ng-if="item.status == 'Deleted'">⚫️</small></td></tr></tbody></table></div></div><div class="card-body"><paging class="small" page="data.pagingData.page" page-size="data.pagingData.pageSize" total="data.pagingData.total" ul-class="pagination justify-content-end m-0" a-class="page-link" paging-action="getList(page-1)" scroll-top="true"></paging></div></div></div></div></div>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="page-wrapper d-flex flex-column pt-4"><div class="container-xl"><div class="page-header d-print-none"><div class="row align-items-center"><div class="col"><div class="page-pretitle">Listing</div><h3 class="page-title">All Queue Logs</h3></div></div></div></div><div class="page-body d-flex flex-row-reverse"><aside class="bd-sidebar sub-sidebar"><nav class="bd-links p-3" aria-label="Sub-section navigation"><div class="card card-body"><filter-list class="" request="request" callback="getList(pageIndex)"></filter-list></div></nav></aside><div class="content-body py-3 pe-3"><div class="card mb-5"><div class="card-body"><table id="list-page" class="table table-striped-x table-hover" dnd-list="data.items" dnd-disable-if="canDrag" cellspacing="0" ng-init="getList()"><thead class="thead-light"><tr><th scope="col" width="15px"><div class="form-check m-0 p-0"><input type="checkbox" class="form-check-inputx" ng-model="selectedList.isSelectAll" ng-change="selectAll(selectedList.isSelectAll)" id="customCheck_all"></div></th><th class="col">Topic</th><th class="col">State</th><th class="col">Action</th><th class="col">Created</th><th class="col"></th><th class="col text-end"></th></tr></thead><tbody class=""><tr ng-repeat="item in data.items track by $index" dnd-draggable="item" dnd-effect-allowed="move" dnd-selected="selected = item" dnd-moved="updateInfos($index)" ng-class="{'selected': selected === item}" class="" sort-model="category" sort-model-id="{{item.id}}"><td class="align-middle"><div class="form-check"><input type="checkbox" class="form-check-input" id="customCheck_{{item.id}}" ng-model="item.isSelected" ng-change="select(item.id, item.isSelected)"> <label class="custom-control-label" for="customCheck_{{item.id}}"></label></div></td><td class=""><a href="" ng-click="view(item)" class="btn-link"><span ng-bind="item.topicId|trim:50" class="{{item.objClass}}"></span></a></td><td><span ng-bind="item.state|trim:50"></span></td><td class="text-secondary"><small>{{item.action}}</small></td><td class="text-secondary"><small>{{item.createdDateTime | utcToLocal:'dd.MM.yy hh:mm a'}}</small></td><td><a class="dropdown-item border-radius-md" ng-click="view(item)"><span class="fa fa-eye"></span></a></td><td class="text-black-50"><small ng-if="item.status == 'Published'">🟢</small> <small ng-if="item.status == 'Schedule'">🟡</small> <small ng-if="item.status == 'Draft'">🔴</small> <small ng-if="item.status == 'Deleted'">⚫️</small></td></tr></tbody></table></div><div class="card-body"><paging class="small" page="data.pagingData.page" page-size="data.pagingData.pageSize" total="data.pagingData.total" ul-class="pagination justify-content-end m-0" a-class="page-link" paging-action="getList(page-1)" scroll-top="true"></paging></div></div></div></div></div>
<div class="page-wrapper d-flex flex-column pt-4"><div class="container-xl"><div class="page-header d-print-none"><div class="row align-items-center"><div class="col"><div class="page-pretitle">Listing</div><h3 class="page-title">All Queue Logs</h3></div></div></div></div><div class="page-body d-flex flex-row-reverse"><aside class="bd-sidebar sub-sidebar"><nav class="bd-links p-3" aria-label="Sub-section navigation"><div class="card card-body"><filter-list class="" request="request" callback="getList(pageIndex)"></filter-list></div></nav></aside><div class="content-body py-3 pe-3"><div class="card mb-5" ng-init="getList()"><div ng-repeat="result in data.results track by $index" ng-if="result.data"><h3 ng-bind="result.searchDate | utcToLocal:'dd.MM.yy'"></h3><div class="card-body"><table id="list-page" class="table table-striped-x table-hover" cellspacing="0"><thead class="thead-light"><tr><th scope="col" width="15px"><div class="form-check m-0 p-0"><input type="checkbox" class="form-check-inputx" ng-model="selectedList.isSelectAll" ng-change="selectAll(selectedList.isSelectAll)" id="customCheck_all"></div></th><th class="col">Topic</th><th class="col">State</th><th class="col">Action</th><th class="col">Created</th><th class="col"></th><th class="col text-end"></th></tr></thead><tbody class=""><tr ng-repeat="item in result.data.items track by $index" dnd-draggable="item" dnd-effect-allowed="move" dnd-selected="selected = item" dnd-moved="updateInfos($index)" ng-class="{'selected': selected === item}" class="" sort-model="category" sort-model-id="{{item.id}}"><td class="align-middle"><div class="form-check"><input type="checkbox" class="form-check-input" id="customCheck_{{item.id}}" ng-model="item.isSelected" ng-change="select(item.id, item.isSelected)"> <label class="custom-control-label" for="customCheck_{{item.id}}"></label></div></td><td class=""><a href="" ng-click="view(item)" class="btn-link"><span ng-bind="item.topicId|trim:50" class="{{item.objClass}}"></span></a></td><td><span ng-bind="item.state|trim:50"></span></td><td class="text-secondary"><small>{{item.action}}</small></td><td class="text-secondary"><small>{{item.createdDateTime | utcToLocal:'dd.MM.yy hh:mm a'}}</small></td><td><a class="dropdown-item border-radius-md" ng-click="view(item)"><span class="fa fa-eye"></span></a></td><td class="text-black-50"><small ng-if="item.status == 'Published'">🟢</small> <small ng-if="item.status == 'Schedule'">🟡</small> <small ng-if="item.status == 'Draft'">🔴</small> <small ng-if="item.status == 'Deleted'">⚫️</small></td></tr></tbody></table></div></div><div class="card-body"><paging class="small" page="data.pagingData.page" page-size="data.pagingData.pageSize" total="data.pagingData.total" ul-class="pagination justify-content-end m-0" a-class="page-link" paging-action="getList(page-1)" scroll-top="true"></paging></div></div></div></div></div>
91 changes: 91 additions & 0 deletions src/modules/mix.log/Controllers/MixAuditLogController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using Mix.Constant.Constants;
using Mix.Database.Entities.AuditLog;
using Mix.Database.Entities.Queue;
using Mix.Heart.Enums;
using Mix.Heart.Exceptions;
using Mix.Heart.Models;
using Mix.Heart.Services;
using Mix.Heart.UnitOfWork;
using Mix.Identity.Constants;
using Mix.Lib.Attributes;
using Mix.Lib.Base;
using Mix.Lib.Interfaces;
using Mix.Lib.Models.Common;
using Mix.Lib.Services;
using Mix.Log.Lib.Models;
using Mix.Log.Lib.ViewModels;
using Mix.Queue.Interfaces;
using Mix.Queue.Models;
using Mix.Shared.Dtos;
using Mix.SignalR.Interfaces;

namespace Mix.Log.Controllers
Expand All @@ -36,8 +44,91 @@ public AuditLogController(

}

#region Routes

[HttpGet("search")]
public async Task<ActionResult> Search([FromQuery] SearchRequestDto req, CancellationToken cancellationToken = default)
{
SearchLogResponseModel<AuditLogViewModel> result = new();
if (req.FromDate.HasValue)
{
var searchRequest = BuildSearchRequest(req);
var searchDate = req.FromDate.Value;
var searchResult = await SearchByDate(searchRequest, searchDate, cancellationToken);
result.Results.Add(searchResult);
if (result.PagingData.TotalPage < searchResult.Data?.PagingData.TotalPage)
{
result.PagingData = searchResult.Data.PagingData;
}

if (req.ToDate.HasValue)
{
while (searchDate < req.ToDate.Value)
{
searchDate = searchDate.AddDays(1);
searchResult = await SearchByDate(searchRequest, searchDate, cancellationToken);
result.Results.Add(searchResult);
if (result.PagingData.TotalPage < searchResult.Data?.PagingData.TotalPage)
{
result.PagingData = searchResult.Data.PagingData;
}
}
}
return Ok(result);
}

var data = await base.SearchHandler(req, cancellationToken);
result.Results.Add(new()
{
SearchDate = DateTime.UtcNow,
Data = data,
});
result.PagingData = data.PagingData;

return Ok(result);
}

#endregion

#region Overrides

private async Task<SearchLogResult<AuditLogViewModel>> SearchByDate(SearchQueryModel<AuditLog, Guid> searchRequest, DateTime searchDate, CancellationToken cancellationToken)
{
try
{

string fileName = $"{MixFolders.MixAuditLogFolder}/{searchDate.ToString("MM_yyyy")}/auditlog_{searchDate.ToString("dd_MM_yyyy")}.sqlite";

if (!System.IO.File.Exists(fileName))
{
return new()
{
SearchDate = searchDate
};
}

using (var context = new AuditLogDbContext(searchDate))
{
using (var AuditLogUow = new UnitOfWorkInfo(context))
{
return new()
{
SearchDate = searchDate,
Data = await AuditLogViewModel.GetRepository(AuditLogUow, CacheService)
.GetPagingAsync(searchRequest.Predicate, searchRequest.PagingData, cancellationToken)
};
}
}
}
catch (MixException)
{
throw;
}
catch (Exception ex)
{
throw new MixException(MixErrorStatus.Badrequest, ex);
}
}
#endregion
}
}
95 changes: 95 additions & 0 deletions src/modules/mix.log/Controllers/MixQueueLogController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualBasic;
using Mix.Constant.Constants;
using Mix.Database.Entities.Queue;
using Mix.Heart.Enums;
using Mix.Heart.Exceptions;
using Mix.Heart.Models;
using Mix.Heart.Services;
using Mix.Heart.UnitOfWork;
using Mix.Identity.Constants;
using Mix.Lib.Attributes;
using Mix.Lib.Base;
using Mix.Lib.Interfaces;
using Mix.Lib.Models.Common;
using Mix.Lib.Services;
using Mix.Log.Lib.Models;
using Mix.Log.Lib.ViewModels;
using Mix.Queue.Interfaces;
using Mix.Queue.Models;
using Mix.Service.Services;
using Mix.Shared.Dtos;
using Mix.SignalR.Interfaces;

namespace Mix.Log.Controllers
Expand Down Expand Up @@ -42,5 +50,92 @@ public MixQueueLogController(
mixTenantService)
{
}

#region Routes

[HttpGet("search")]
public async Task<ActionResult> Search([FromQuery] SearchRequestDto req, CancellationToken cancellationToken = default)
{
SearchLogResponseModel<MixQueueMessageLogViewModel> result = new();
if (req.FromDate.HasValue)
{
var searchRequest = BuildSearchRequest(req);
var searchDate = req.FromDate.Value;
var searchResult = await SearchByDate(searchRequest, searchDate, cancellationToken);
result.Results.Add(searchResult);
if (result.PagingData.TotalPage < searchResult.Data?.PagingData.TotalPage)
{
result.PagingData = searchResult.Data.PagingData;
}

if (req.ToDate.HasValue)
{
while (searchDate < req.ToDate.Value)
{
searchDate = searchDate.AddDays(1);
searchResult = await SearchByDate(searchRequest, searchDate, cancellationToken);
if (result.PagingData.TotalPage < searchResult.Data?.PagingData.TotalPage)
{
result.PagingData = searchResult.Data.PagingData;
}
}
}
return Ok(result);
}

var data = await base.SearchHandler(req, cancellationToken);
result.Results.Add(new()
{
SearchDate = DateTime.UtcNow,
Data = data,
});
result.PagingData = data.PagingData;

return Ok(result);
}

#endregion

#region Overrides

private async Task<SearchLogResult<MixQueueMessageLogViewModel>> SearchByDate(SearchQueryModel<MixQueueMessageLog, Guid> searchRequest, DateTime searchDate, CancellationToken cancellationToken)
{
try
{

string fileName = $"{MixFolders.MixQueueLogFolder}/{searchDate.ToString("MM_yyyy")}/queuelog_{searchDate.ToString("dd_MM_yyyy")}.sqlite";

if (!System.IO.File.Exists(fileName))
{
return new()
{
SearchDate = searchDate
};
}

using (var context = new MixQueueDbContext(searchDate))
{
using (var MixQueueMessageLogUow = new UnitOfWorkInfo(context))
{
return new()
{
SearchDate = searchDate,
Data = await MixQueueMessageLogViewModel.GetRepository(MixQueueMessageLogUow, CacheService)
.GetPagingAsync(searchRequest.Predicate, searchRequest.PagingData, cancellationToken)
};
}
}
}
catch (MixException)
{
throw;
}
catch (Exception ex)
{
throw new MixException(MixErrorStatus.Badrequest, ex);
}
}

#endregion
}
}
Loading

0 comments on commit bb59dcf

Please sign in to comment.