diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index 9a9320f..13f74da 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -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); } diff --git a/templates/element/genericElements/IndexTable/index_table.php b/templates/element/genericElements/IndexTable/index_table.php index 78958e3..4fc7a42 100644 --- a/templates/element/genericElements/IndexTable/index_table.php +++ b/templates/element/genericElements/IndexTable/index_table.php @@ -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('