chg: [inboxProcessor:dataChange] Further improved UI and readability

develop-unstable
Sami Mokaddem 2023-02-15 11:42:35 +01:00
parent 20eebd097d
commit a872379529
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 45 additions and 14 deletions

View File

@ -1,4 +1,7 @@
<?php <?php
$randomIdOld = Cake\Utility\Security::randomString(8);
$randomIdNew = Cake\Utility\Security::randomString(8);
if (!empty($data['summary'])) { if (!empty($data['summary'])) {
$changedSummary = h($data['summary']); $changedSummary = h($data['summary']);
} else if (!empty($data['summaryTemplate']) && !empty($data['summaryMessage'])) { } else if (!empty($data['summaryTemplate']) && !empty($data['summaryMessage'])) {
@ -37,6 +40,7 @@ foreach ($properties as $i => $property) {
$data['changed'][$property] ?? '', $data['changed'][$property] ?? '',
]; ];
} }
$emptyValueHTML = $this->Bootstrap->node('span', ['class' => ['text-muted', 'fw-light', 'fst-italic']], __('- empty -'));
$diffTable = $this->Bootstrap->table( $diffTable = $this->Bootstrap->table(
[ [
@ -54,25 +58,39 @@ $diffTable = $this->Bootstrap->table(
} }
], ],
[ [
'label' => __('New value'), 'label' => __('Old value'),
'formatter' => function ($field, $row) { 'formatter' => function ($field, $row) use ($randomIdOld, $emptyValueHTML) {
return $this->Bootstrap->alert([ $fieldText = is_array($field) ? json_encode($field, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT) : $field;
'text' => $field, $config = [
'variant' => 'success', 'text' => $fieldText,
'variant' => 'danger',
'dismissible' => false, 'dismissible' => false,
'class' => ['p-2', 'mb-0'], 'class' => ['p-2', 'mb-0', !empty($fieldText) && is_array($field) ? "json_container_{$randomIdOld}" : ''],
]); ];
if (empty($fieldText)) {
$config['html'] = $emptyValueHTML;
} else {
$config['text'] = $fieldText;
}
return $this->Bootstrap->alert($config);
} }
], ],
[ [
'label' => __('Old value'), 'label' => __('New value'),
'formatter' => function ($field, $row) { 'formatter' => function ($field, $row) use ($randomIdNew, $emptyValueHTML) {
return $this->Bootstrap->alert([ $fieldText = is_array($field) ? json_encode($field, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT) : $field;
'text' => $field, $config = [
'variant' => 'danger', 'text' => $fieldText,
'variant' => 'success',
'dismissible' => false, 'dismissible' => false,
'class' => ['p-2', 'mb-0'], 'class' => ['p-2', 'mb-0', !empty($fieldText) && is_array($field) ? "json_container_{$randomIdNew}" : ''],
]); ];
if (empty($fieldText)) {
$config['html'] = $emptyValueHTML;
} else {
$config['text'] = $fieldText;
}
return $this->Bootstrap->alert($config);
} }
], ],
], ],
@ -123,3 +141,16 @@ echo $this->Bootstrap->modal([
]); ]);
?> ?>
</div> </div>
<script type="text/javascript">
$(document).ready(function() {
const $containerOld = $('.json_container_<?= $randomIdOld; ?>')
const $containerNew = $('.json_container_<?= $randomIdNew; ?>')
if ($containerOld.length == 1) {
$containerOld.html(syntaxHighlightJson($containerOld.text()));
}
if ($containerNew.length == 1) {
$containerNew.html(syntaxHighlightJson($containerNew.text()));
}
});
</script>