diff --git a/assets/controllers/elements/datatables/datatables_controller.js b/assets/controllers/elements/datatables/datatables_controller.js index 441a3850..aee8af59 100644 --- a/assets/controllers/elements/datatables/datatables_controller.js +++ b/assets/controllers/elements/datatables/datatables_controller.js @@ -138,7 +138,12 @@ export default class extends Controller { } _rowCallback(row, data, index) { - //Empty by default but can be overridden by child classes + //Set the row class based on the optional $$rowClass column data, can be used to color the rows + + //Check if we have a level, then change color of this row + if (data.$$rowClass) { + $(row).addClass(data.$$rowClass); + } } _onSelectionChange(e, dt, items ) { diff --git a/assets/controllers/elements/datatables/log_controller.js b/assets/controllers/elements/datatables/log_controller.js index 753a7c23..8820edfb 100644 --- a/assets/controllers/elements/datatables/log_controller.js +++ b/assets/controllers/elements/datatables/log_controller.js @@ -23,29 +23,5 @@ import DatatablesController from "./datatables_controller.js"; * This is the datatables controller for log pages, it includes an mechanism to color lines based on their level. */ export default class extends DatatablesController { - _rowCallback(row, data, index) { - //Check if we have a level, then change color of this row - if (data.level) { - let style = ""; - switch (data.level) { - case "emergency": - case "alert": - case "critical": - case "error": - style = "table-danger"; - break; - case "warning": - style = "table-warning"; - break; - case "notice": - style = "table-info"; - break; - } - - if (style) { - $(row).addClass(style); - } - } - } } diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index 4805345a..9e402072 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -105,6 +105,28 @@ class LogDataTable implements DataTableTypeInterface $this->configureOptions($resolver); $options = $resolver->resolve($options); + //This special $$rowClass column is used to set the row class depending on the log level. The class gets set by the frontend controller + $dataTable->add('$$rowClass', TextColumn::class, [ + 'label' => '', + 'className' => 'no-colvis', + 'visible' => false, + 'render' => static function ($value, AbstractLogEntry $context) { + switch ($context->getLevel()) { + case AbstractLogEntry::LEVEL_EMERGENCY: + case AbstractLogEntry::LEVEL_ALERT: + case AbstractLogEntry::LEVEL_CRITICAL: + case AbstractLogEntry::LEVEL_ERROR: + return 'table-danger'; + case AbstractLogEntry::LEVEL_WARNING: + return 'table-warning'; + case AbstractLogEntry::LEVEL_NOTICE: + return 'table-info'; + default: + return ''; + } + }, + ]); + $dataTable->add('symbol', TextColumn::class, [ 'label' => '', 'className' => 'no-colvis',