ver. 0.310: logi integracji w panelu admin
Nowa zakladka "Logi" w sekcji Integracje - podglad tabeli pp_log z paginacja, sortowaniem, filtrami i rozwijalnym kontekstem JSON. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
namespace admin\Controllers;
|
||||
|
||||
use Domain\Integrations\IntegrationsRepository;
|
||||
use admin\ViewModels\Common\PaginatedTableViewModel;
|
||||
|
||||
class IntegrationsController
|
||||
{
|
||||
@@ -12,6 +13,114 @@ class IntegrationsController
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function logs(): string
|
||||
{
|
||||
$sortableColumns = ['id', 'action', 'order_id', 'message', 'date'];
|
||||
|
||||
$filterDefinitions = [
|
||||
[
|
||||
'key' => 'log_action',
|
||||
'label' => 'Akcja',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'key' => 'message',
|
||||
'label' => 'Wiadomosc',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'key' => 'order_id',
|
||||
'label' => 'ID zamowienia',
|
||||
'type' => 'text',
|
||||
],
|
||||
];
|
||||
|
||||
$listRequest = \admin\Support\TableListRequestFactory::fromRequest(
|
||||
$filterDefinitions,
|
||||
$sortableColumns,
|
||||
'id'
|
||||
);
|
||||
|
||||
$result = $this->repository->getLogs(
|
||||
$listRequest['filters'],
|
||||
$listRequest['sortColumn'],
|
||||
$listRequest['sortDir'],
|
||||
$listRequest['page'],
|
||||
$listRequest['perPage']
|
||||
);
|
||||
|
||||
$rows = [];
|
||||
$lp = ($listRequest['page'] - 1) * $listRequest['perPage'] + 1;
|
||||
|
||||
foreach ( $result['items'] as $item ) {
|
||||
$id = (int)($item['id'] ?? 0);
|
||||
$context = trim( (string)($item['context'] ?? '') );
|
||||
$contextHtml = '';
|
||||
if ( $context !== '' ) {
|
||||
$contextHtml = '<button class="btn btn-xs btn-default log-context-btn" data-id="' . $id . '">Pokaz</button>'
|
||||
. '<pre class="log-context-pre" id="log-context-' . $id . '" style="display:none;max-height:300px;overflow:auto;margin-top:5px;font-size:11px;white-space:pre-wrap;">'
|
||||
. htmlspecialchars( $context, ENT_QUOTES, 'UTF-8' )
|
||||
. '</pre>';
|
||||
}
|
||||
|
||||
$rows[] = [
|
||||
'lp' => $lp++ . '.',
|
||||
'action' => htmlspecialchars( (string)($item['action'] ?? ''), ENT_QUOTES, 'UTF-8' ),
|
||||
'order_id' => $item['order_id'] ? (int)$item['order_id'] : '-',
|
||||
'message' => htmlspecialchars( (string)($item['message'] ?? ''), ENT_QUOTES, 'UTF-8' ),
|
||||
'context' => $contextHtml,
|
||||
'date' => !empty( $item['date'] ) ? date( 'Y-m-d H:i:s', strtotime( (string)$item['date'] ) ) : '-',
|
||||
];
|
||||
}
|
||||
|
||||
$total = (int)$result['total'];
|
||||
$totalPages = max( 1, (int)ceil( $total / $listRequest['perPage'] ) );
|
||||
|
||||
$viewModel = new PaginatedTableViewModel(
|
||||
[
|
||||
['key' => 'lp', 'label' => 'Lp.', 'class' => 'text-center', 'sortable' => false],
|
||||
['key' => 'date', 'sort_key' => 'date', 'label' => 'Data', 'class' => 'text-center', 'sortable' => true],
|
||||
['key' => 'action', 'sort_key' => 'action', 'label' => 'Akcja', 'sortable' => true],
|
||||
['key' => 'order_id', 'sort_key' => 'order_id', 'label' => 'Zamowienie', 'class' => 'text-center', 'sortable' => true],
|
||||
['key' => 'message', 'sort_key' => 'message', 'label' => 'Wiadomosc', 'sortable' => true],
|
||||
['key' => 'context', 'label' => 'Kontekst', 'sortable' => false, 'raw' => true],
|
||||
],
|
||||
$rows,
|
||||
$listRequest['viewFilters'],
|
||||
[
|
||||
'column' => $listRequest['sortColumn'],
|
||||
'dir' => $listRequest['sortDir'],
|
||||
],
|
||||
[
|
||||
'page' => $listRequest['page'],
|
||||
'per_page' => $listRequest['perPage'],
|
||||
'total' => $total,
|
||||
'total_pages' => $totalPages,
|
||||
],
|
||||
array_merge( $listRequest['queryFilters'], [
|
||||
'sort' => $listRequest['sortColumn'],
|
||||
'dir' => $listRequest['sortDir'],
|
||||
'per_page' => $listRequest['perPage'],
|
||||
] ),
|
||||
$listRequest['perPageOptions'],
|
||||
$sortableColumns,
|
||||
'/admin/integrations/logs/',
|
||||
'Brak wpisow w logach.'
|
||||
);
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'integrations/logs', [
|
||||
'viewModel' => $viewModel,
|
||||
] );
|
||||
}
|
||||
|
||||
public function logs_clear(): void
|
||||
{
|
||||
$this->repository->clearLogs();
|
||||
\Shared\Helpers\Helpers::alert( 'Logi zostaly wyczyszczone.' );
|
||||
header( 'Location: /admin/integrations/logs/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function apilo_settings(): string
|
||||
{
|
||||
return \Shared\Tpl\Tpl::view( 'integrations/apilo-settings', [
|
||||
|
||||
Reference in New Issue
Block a user