chg: [elements:widgets] Slightly refactored highlight panel and removed useless code

pull/93/head
Sami Mokaddem 2021-11-23 22:07:31 +01:00
parent bfd3a0c1e0
commit d136955160
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 13 additions and 68 deletions

View File

@ -48,7 +48,7 @@ $bookmarks = !empty($loggedUser->user_settings_by_name['ui.bookmarks']['value'])
echo $this->element('widgets/highlight-panel', [
'titleHtml' => $panelTitle,
'number' => $statisticForModel['created']['amount'],
'variation' => $statisticForModel['created']['variation'] ?? '',
'variation' => $statisticForModel['created']['variation'] ?? null,
'timeline' => $statisticForModel ?? []
]);
?>

View File

@ -1,22 +1,6 @@
<?php
$statisticsHtml = '';
$panelOptions = [
'condensed' => true,
'panelNoGrow' => true,
'allowConfiguration' => true,
'chartType' => 'line',
'chartOptions' => [
'chart' => [
'height' => '60px',
],
'stroke' => [
'width' => 2,
'curve' => 'smooth',
],
]
];
if (!empty($statistics['created'])) {
$statisticsHtml .= $this->element('genericElements/IndexTable/Statistics/index_statistic_timestamp', [
'timeline' => $statistics,

View File

@ -2,7 +2,7 @@
$seed = 's-' . mt_rand();
$variationIcon = '';
$variationClass = '';
if (!empty($variation)) {
if (!is_null($variation)) {
if ($variation == 0) {
$variationIcon = $this->FontAwesome->getClass('minus');
} elseif ($variation > 0) {
@ -36,36 +36,21 @@ if (!empty($timeline['modified']['timeline'])) {
}
$variationHtml = '';
if (!empty($variation)) {
if (!is_null($variation)) {
$variationHtml = sprintf(
'<div class="badge %s fw-bold"><span class="%s me-2 align-middle"></span>%s</div>',
$variationClass,
$variationIcon,
!empty($variation) ? h($variation) : ''
!is_null($variation) ? h($variation) : ''
);
}
$titleHtml = isset($title) ? h($title) : ($titleHtml ?? '');
$leftContent = sprintf(
'<div class="">%s</div><%s class="%s">%s <span class="fs-8 fw-light">%s%s</span></%s>%s',
'<div class="">%s</div><h2 class="my-2 text-nowrap">%s <span class="fs-8 fw-light">%s</span></h2>%s',
$titleHtml,
(!empty($condensed) ? 'h3' : 'h2'),
(!empty($condensed) ? 'my-1' : 'my-2'),
h($number ?? ''),
__('Past {0} days', $statistics_day_number),
empty($allowConfiguration) ? '' : $this->Bootstrap->button([
'variant' => 'link',
'icon' => 'cog',
'size' => 'xs',
'nodeType' => 'a',
'onclick' => '',
'class' => ['btn-statistics-days-configurator-' . $seed],
'params' => [
'data-bs-toggle' => 'popover',
'data-bs-title' => __('Set statistics spanning days'),
]
]),
(!empty($condensed) ? 'h3' : 'h2'),
$variationHtml
);
$rightContent = sprintf('<div class="">%s</div>', $this->element('charts/bar', [
@ -83,43 +68,19 @@ $rightContent = sprintf('<div class="">%s</div>', $this->element('charts/bar', [
!empty($chartOptions) ? $chartOptions : []
)
]));
$cardContent = sprintf('<div class="highlight-panel-container d-flex align-items-center justify-content-between %s" style="%s %s"><div class="number-container">%s</div><div class="chart-container w-50 %s">%s</div></div>', $panelClasses ?? '', (!empty($condensed) ? 'max-height: 100px' : ''), $panelStyle ?? '', $leftContent, (!empty($condensed) ? 'p-2' : ''), $rightContent);
$cardContent = sprintf(
'<div class="highlight-panel-container d-flex align-items-center justify-content-between %s" style="%s"><div class="number-container">%s</div><div class="chart-container w-50">%s</div></div>',
$panelClasses ?? '',
$panelStyle ?? '',
$leftContent,
$rightContent
);
echo $this->Bootstrap->card([
'variant' => 'secondary',
'bodyHTML' => $cardContent,
'bodyClass' => (!empty($condensed) ? 'py-1 px-2' : 'p-3'),
'bodyClass' => 'p-3',
'class' => ['shadow-sm', (empty($panelNoGrow) ? 'grow-on-hover' : '')]
]);
?>
<?php if (!empty($allowConfiguration)): ?>
<script>
$(document).ready(function() {
let popovers = new bootstrap.Popover(document.querySelector('.btn-statistics-days-configurator-<?= $seed ?>'), {
container: 'body',
html: true,
sanitize: false,
content: () => {
return '<div class="input-group flex-nowrap"> \
<span class="input-group-text" id="addon-wrapping-<?= $seed ?>"><?= __('Days') ?></span> \
<input type="number" min="1" class="form-control" placeholder="7" aria-label="<?= __('Days') ?>" aria-describedby="addon-wrapping-<?= $seed ?>" value="<?= h($statistics_day_number) ?>"> \
<button class="btn btn-primary" type="button" onclick="statisticsDaysRedirect(this)"><?= __('Get statistics') ?> </button> \
</div>'
}
})
})
function statisticsDaysRedirect(clicked) {
const endpoint = window.location.pathname
const search = window.location.search
let days = $(clicked).closest('.input-group').find('input').val()
days = days !== undefined ? days : 7
const searchParams = new URLSearchParams(window.location.search)
searchParams.set('statistics_days', days);
const url = endpoint + '?' + searchParams
window.location = url
}
</script>
<?php endif; ?>