Added log page and log api

This commit is contained in:
Pinga 2023-08-30 16:10:49 +03:00
parent 5133b005a5
commit b245bae65a
3 changed files with 98 additions and 63 deletions

View file

@ -1,6 +1,6 @@
{% extends "layouts/app.twig" %}
{% block title %}Log History{% endblock %}
{% block title %}{{ __('Log History') }}{% endblock %}
{% block content %}
<div class="page-wrapper">
@ -14,7 +14,7 @@
Overview
</div>
<h2 class="page-title">
Log History
{{ __('Log History') }}
</h2>
</div>
<!-- Page title actions -->
@ -42,51 +42,26 @@
<!-- Page body -->
<div class="page-body">
<div class="container-xl">
<div class="col-12">
<div class="card">
<div class="card-body">
<div id="table-logs" class="table-responsive">
<table class="table">
<thead>
<tr>
<th><button class="table-sort" data-sort="sort-date">Date</button></th>
<th><button class="table-sort" data-sort="sort-registrar">Registrar</button></th>
<th><button class="table-sort" data-sort="sort-command">Command</button></th>
<th><button class="table-sort" data-sort="sort-object">Object</button></th>
<th><button class="table-sort" data-sort="sort-result">Result</button></th>
<th><button class="table-sort" data-sort="sort-message">Message</button></th>
<th><button class="table-sort" data-sort="sort-milliseconds">Milliseconds</button></th>
<th><button class="table-sort" data-sort="sort-cltrid">clTRID</button></th>
<th>Actions</th>
</tr>
</thead>
<tbody class="table-tbody">
{% for log in logs %}
<tr>
<td class="sort-date">{{ log.cldate }}</td>
<td class="sort-registrar">{{ log.registrar_id }}</td>
<td class="sort-command">{{ log.cmd }}</td>
<td class="sort-object">{{ log.obj_id }}</td>
<td class="sort-result">{{ log.code }}</td>
<td class="sort-message">{{ log.msg }}</td>
<td class="sort-milliseconds">{{ log.clmicrosecond }}</td>
<td class="sort-cltrid">{{ log.clTRID }}</td>
<td class="text-end">
<span class="dropdown">
<button class="btn dropdown-toggle align-text-top" data-bs-boundary="viewport" data-bs-toggle="dropdown">Actions</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item" href="#">
Action
</a>
<a class="dropdown-item" href="#">
Another action
</a>
<div class="card-body border-bottom py-3">
<div class="d-flex">
<div class="text-secondary">
<button class="btn btn-info btn-icon" onclick="downloadCSV()"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 15a1 1 0 0 0 1 1h2a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-2a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1"></path><path d="M17 8l2 8l2 -8"></path><path d="M7 10a2 2 0 1 0 -4 0v4a2 2 0 1 0 4 0"></path></svg></button>
<button class="btn btn-info btn-icon" onclick="downloadJSON()"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M20 16v-8l3 8v-8"></path><path d="M15 8a2 2 0 0 1 2 2v4a2 2 0 1 1 -4 0v-4a2 2 0 0 1 2 -2z"></path><path d="M1 8h3v6.5a1.5 1.5 0 0 1 -3 0v-.5"></path><path d="M7 15a1 1 0 0 0 1 1h1a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h1a1 1 0 0 1 1 1"></path></svg></button>
<button class="btn btn-green btn-icon" onclick="downloadXLSX()"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M14 3v4a1 1 0 0 0 1 1h4"></path><path d="M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"></path><path d="M4 15l4 6"></path><path d="M4 21l4 -6"></path><path d="M17 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"></path><path d="M11 15v6h3"></path></svg></button>
<button class="btn btn-red btn-icon" onclick="downloadPDF()"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 8v8h2a2 2 0 0 0 2 -2v-4a2 2 0 0 0 -2 -2h-2z"></path><path d="M3 12h2a2 2 0 1 0 0 -4h-2v8"></path><path d="M17 12h3"></path><path d="M21 8h-4v8"></path></svg></button>
</div>
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table><ul class="pagination"></ul>
<div class="ms-auto text-secondary">
Search:
<div class="ms-2 d-inline-block">
<input id="search-input" type="text" class="form-control" aria-label="Search logs">
</div>
</div>
</div>
</div>
<div class="table-responsive">
<div id="logTable"></div>
</div>
</div>
</div>

View file

@ -1,17 +1,60 @@
<script src="/assets/libs/list.js/dist/list.min.js" defer></script>
<script src="/assets/js/tabulator.min.js" defer></script>
<script src="/assets/js/tabler.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.6.0/jspdf.plugin.autotable.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
const list = new List('table-logs', {
sortClass: 'table-sort',
listClass: 'table-tbody',
valueNames: [ 'sort-date', 'sort-registrar', 'sort-command', 'sort-object',
'sort-result', 'sort-message', 'sort-milliseconds', 'sort-cltrid'
var table;
document.addEventListener("DOMContentLoaded", function(){
table = new Tabulator("#logTable", {
ajaxURL:"/log-api/records/transaction_identifier", // Set the URL for your JSON data
ajaxConfig:"GET",
pagination:"local",
paginationSize:10,
ajaxResponse:function(url, params, response){
return response.records;
},
layout:"fitColumns",
responsiveLayout: "hide",
initialSort:[
{column:"cldate", dir:"desc"}, // sorting by the "cldate" field in descending order
],
columns:[
{title:"Date", field:"cldate", headerSort:true},
{title:"Registrar", field:"registrar_id", headerSort:true},
{title:"Command", field:"cmd", headerSort:true, responsive:0},
{title:"Object Type", field:"obj_type", headerSort:true, responsive:0},
{title:"Object", field:"obj_id", headerSort:true, responsive:0},
{title:"Result", field:"code", headerSort:true},
{title:"Message", field:"msg", headerSort:true, responsive:0, download:false},
{title:"clTRID", field:"clTRID", headerSort:true, responsive:0, download:false},
{title:"Milliseconds", field:"svmicrosecond", headerSort:false, download:false},
],
page: 10,
pagination: true
});
})
var searchInput = document.getElementById("search-input");
searchInput.addEventListener("input", function(){
table.setFilter("cmd", "like", searchInput.value);
});
});
function downloadCSV() {
table.download("csv", "data.csv");
}
function downloadJSON() {
table.download("json", "data.json");
}
function downloadXLSX() {
table.download("xlsx", "data.xlsx", {sheetName:"My Contacts"});
}
function downloadPDF() {
table.download("pdf", "data.pdf", {
orientation:"portrait",
title:"My Contacts",
jsPDF:{unit:"mm", format:"a4", orientation:"p"}
});
}
</script>

View file

@ -79,6 +79,23 @@ $app->any('/api[/{params:.*}]', function (
return $response;
});
$app->any('/log-api[/{params:.*}]', function (
ServerRequest $request,
Response $response,
$args
) use ($container) {
$db = config('connections');
$config = new Config([
'username' => $db['mysql']['username'],
'password' => $db['mysql']['password'],
'database' => 'registryTransaction',
'basePath' => '/log-api',
]);
$api = new Api($config);
$response = $api->handle($request);
return $response;
});
$app->add(function (Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Server\RequestHandlerInterface $handler) {
try {
return $handler->handle($request);