chg: [genericElements:index_table] Added support of statistic for current view - WiP
parent
829e471ac1
commit
25f0f07251
|
@ -97,6 +97,10 @@ class CRUDComponent extends Component
|
|||
}
|
||||
$this->Controller->set('meta_templates', $metaTemplates);
|
||||
}
|
||||
if ($this->Table->hasBehavior('Timestamp')) {
|
||||
$modelStatistics = $this->Table->getStatisticsForModel($this->Table, !is_numeric($this->request->getQuery('statistics_days')) ? 7 : $this->request->getQuery('statistics_days'));
|
||||
$this->Controller->set('modelStatistics', $modelStatistics);
|
||||
}
|
||||
$this->Controller->set('model', $this->Table);
|
||||
$this->Controller->set('data', $data);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use Cake\Utility\Text;
|
|||
* ),
|
||||
* 'title' => optional title,
|
||||
* 'description' => optional description,
|
||||
* 'index_statistics' => optional statistics to be displayed for the index,
|
||||
* 'primary_id_path' => path to each primary ID (extracted and passed as $primary to fields)
|
||||
* ));
|
||||
*
|
||||
|
@ -52,6 +53,46 @@ if (!empty($data['title'])) {
|
|||
]
|
||||
);
|
||||
}
|
||||
|
||||
$statisticsHtml = '';
|
||||
if (!empty($modelStatistics)) {
|
||||
$panelOptions = [
|
||||
'condensed' => true,
|
||||
'panelNoGrow' => true,
|
||||
'allowConfiguration' => true,
|
||||
'chartType' => 'line',
|
||||
'chartOptions' => [
|
||||
'chart' => [
|
||||
'height' => '60px',
|
||||
],
|
||||
'stroke' => [
|
||||
'width' => 2,
|
||||
'curve' => 'smooth',
|
||||
],
|
||||
'colors' => ['#0fd291'],
|
||||
]
|
||||
];
|
||||
if (!empty($modelStatistics['created'])) {
|
||||
$statCreated = $this->element('widgets/highlight-panel', array_merge($panelOptions, [
|
||||
'titleHtml' => __('New {0}', $model->getAlias()),
|
||||
'number' => $modelStatistics['created']['variation'] ?? '',
|
||||
'timeline' => ['created' => $modelStatistics['created']],
|
||||
]));
|
||||
$statisticsHtml .= sprintf('<div class="col-sm-6 col-md-5 col-lg-4 col-xl-3 mb-1">%s</div>', $statCreated);
|
||||
}
|
||||
if (!empty($modelStatistics['modified'])) {
|
||||
$statModified = $this->element('widgets/highlight-panel', array_merge($panelOptions, [
|
||||
'titleHtml' => __('Updated {0}', $model->getAlias()),
|
||||
'number' => $modelStatistics['modified']['variation'] ?? '',
|
||||
'timeline' => ['modified' => $modelStatistics['modified']]
|
||||
]));
|
||||
$statisticsHtml .= sprintf('<div class="col-sm-6 col-md-5 col-lg-4 col-xl-3 mb-1">%s</div>', $statModified);
|
||||
}
|
||||
$statisticsHtml = sprintf('<div class="row gx-2">%s</div>', $statisticsHtml);
|
||||
}
|
||||
|
||||
echo sprintf('<div class="index-statistic-container">%s</div>', $statisticsHtml);
|
||||
|
||||
echo '<div class="panel">';
|
||||
if (!empty($data['html'])) {
|
||||
echo sprintf('<div>%s</div>', $data['html']);
|
||||
|
@ -172,6 +213,7 @@ echo '</div>';
|
|||
return new bootstrap.Tooltip(tooltipTriggerEl)
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue