2021-11-17 17:04:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$statisticsHtml = '';
|
|
|
|
if (empty($timeline['created']) && empty($timeline['modified'])) {
|
|
|
|
return $statisticsHtml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$seed = 'timeline-' . mt_rand();
|
|
|
|
$title = __('Activity');
|
|
|
|
$statistics_day_number = $timeline['created']['days'];
|
|
|
|
$subTitle = __('Past {0} days', $statistics_day_number);
|
|
|
|
|
|
|
|
$series = [];
|
|
|
|
if (!empty($timeline['created']['timeline'])) {
|
|
|
|
$series[0]['name'] = __('Created');
|
|
|
|
foreach ($timeline['created']['timeline'] as $entry) {
|
|
|
|
$series[0]['data'][] = ['x' => $entry['time'], 'y' => $entry['count']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($timeline['modified']['timeline'])) {
|
|
|
|
$series[1]['name'] = __('Modified');
|
|
|
|
foreach ($timeline['modified']['timeline'] as $entry) {
|
|
|
|
$series[1]['data'][] = ['x' => $entry['time'], 'y' => $entry['count']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$panelControlHtml = sprintf(
|
|
|
|
'<div class="text-nowrap">
|
|
|
|
%s <span class="fs-8 fw-light">%s</span>%s
|
|
|
|
</div>',
|
|
|
|
$title,
|
|
|
|
$subTitle,
|
|
|
|
$this->Bootstrap->button([
|
|
|
|
'variant' => 'link',
|
|
|
|
'icon' => 'cog',
|
|
|
|
'size' => 'xs',
|
|
|
|
'nodeType' => 'a',
|
|
|
|
'onclick' => '',
|
|
|
|
'class' => ['btn-statistics-days-configurator-' . $seed,],
|
2022-11-24 12:50:11 +01:00
|
|
|
'attrs' => [
|
2021-11-17 17:04:39 +01:00
|
|
|
'data-bs-toggle' => 'popover',
|
|
|
|
]
|
|
|
|
])
|
|
|
|
);
|
2022-01-20 13:44:19 +01:00
|
|
|
$createdNumber = empty($timeline['created']) ? '' : sprintf(
|
|
|
|
'<div class="lh-1 d-flex align-items-center" title="%s">%s<span class="ms-1"> %s</span></div>',
|
2021-11-17 17:04:39 +01:00
|
|
|
__('{0} Created', $timeline['created']['variation']),
|
2022-11-24 12:50:11 +01:00
|
|
|
$this->Bootstrap->icon('plus', ['class' => ['fa-fw'], 'attrs' => ['style' => 'font-size: 60%;']]),
|
2022-01-20 13:44:19 +01:00
|
|
|
$timeline['created']['variation']
|
|
|
|
);
|
|
|
|
$modifiedNumber = empty($timeline['modified']) ? '' : sprintf(
|
|
|
|
'<div class="lh-1 d-flex align-items-center" title="%s">%s<span class="ms-1"> %s</span></div>',
|
2021-11-17 17:04:39 +01:00
|
|
|
__('{0} Modified', $timeline['modified']['variation']),
|
2022-11-24 12:50:11 +01:00
|
|
|
$this->Bootstrap->icon('edit', ['class' => ['fa-fw'], 'attrs' => ['style' => 'font-size: 60%;']]),
|
2021-11-17 17:04:39 +01:00
|
|
|
$timeline['modified']['variation']
|
|
|
|
);
|
2022-01-20 13:44:19 +01:00
|
|
|
$activityNumbers = sprintf('<div class="my-1 fs-5">%s%s</div>', $createdNumber, $modifiedNumber);
|
2021-11-17 17:04:39 +01:00
|
|
|
|
|
|
|
$leftContent = sprintf(
|
|
|
|
'%s%s',
|
|
|
|
$panelControlHtml,
|
|
|
|
$activityNumbers
|
|
|
|
);
|
|
|
|
$rightContent = sprintf('<div class="">%s</div>', $this->element('charts/bar', [
|
|
|
|
'series' => $series,
|
|
|
|
'chartOptions' => array_merge(
|
|
|
|
[
|
|
|
|
'chart' => [
|
|
|
|
'height' => 60,
|
|
|
|
],
|
|
|
|
'stroke' => [
|
|
|
|
'width' => 2,
|
|
|
|
'curve' => 'smooth',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
!empty($chartOptions) ? $chartOptions : []
|
|
|
|
)
|
|
|
|
]));
|
|
|
|
$cardContent = sprintf(
|
|
|
|
'<div class="highlight-panel-container d-flex align-items-center justify-content-between" style="max-height: 100px">
|
|
|
|
<div class="number-container">%s</div>
|
|
|
|
<div class="chart-container p-2" style="width: 60%%;">%s</div>
|
|
|
|
</div>',
|
|
|
|
$leftContent,
|
|
|
|
$rightContent
|
|
|
|
);
|
|
|
|
|
|
|
|
$card = $this->Bootstrap->card([
|
2022-11-24 12:50:11 +01:00
|
|
|
'bodyVariant' => 'secondary',
|
2021-11-17 17:04:39 +01:00
|
|
|
'bodyHTML' => $cardContent,
|
|
|
|
'bodyClass' => 'py-1 px-2',
|
|
|
|
'class' => ['shadow-sm', 'h-100']
|
|
|
|
]);
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
2022-10-21 15:36:08 +02:00
|
|
|
<div class="col-sm-6 col-md-5 col-lg-4 col-xl-3 mb-1" style="min-height: 90px;"><?= $card ?></div>
|
2021-11-17 17:04:39 +01:00
|
|
|
|
|
|
|
<script>
|
|
|
|
$(document).ready(function() {
|
|
|
|
let popovers = new bootstrap.Popover(document.querySelector('.btn-statistics-days-configurator-<?= $seed ?>'), {
|
|
|
|
container: 'body',
|
|
|
|
html: true,
|
|
|
|
sanitize: false,
|
2021-11-23 13:49:34 +01:00
|
|
|
title: () => {
|
|
|
|
return '<div class="d-flex align-items-center justify-content-between"> \
|
|
|
|
<?= __('Set spanning window') ?> \
|
|
|
|
<button type = "button" class="btn-xs btn-close" aria-label="Close"></button> \
|
|
|
|
</div>'
|
|
|
|
},
|
2021-11-17 17:04:39 +01:00
|
|
|
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>'
|
|
|
|
}
|
|
|
|
})
|
2021-11-23 13:49:34 +01:00
|
|
|
document.querySelector('.btn-statistics-days-configurator-<?= $seed ?>').addEventListener('shown.bs.popover', function(evt) {
|
|
|
|
const popover = bootstrap.Popover.getInstance(this)
|
|
|
|
const popoverEl = popover.getTipElement()
|
|
|
|
const popoverBtnCloseEl = popoverEl.querySelector('.popover-header button.btn-close')
|
|
|
|
popoverBtnCloseEl.addEventListener('click', function() {
|
|
|
|
popover.hide()
|
|
|
|
})
|
|
|
|
})
|
2021-11-17 17:04:39 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
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>
|