From 829e471ac1231ee0a8b2849b4cc16923faa8be0f Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 15 Nov 2021 11:51:08 +0100 Subject: [PATCH] chg: [element:widget] Added support of condensed UI for highlight-panel This could be later on refactored to be formed from smaller views --- templates/element/widgets/highlight-panel.php | 123 +++++++++++++----- 1 file changed, 91 insertions(+), 32 deletions(-) diff --git a/templates/element/widgets/highlight-panel.php b/templates/element/widgets/highlight-panel.php index 4cbe290..062588f 100644 --- a/templates/element/widgets/highlight-panel.php +++ b/templates/element/widgets/highlight-panel.php @@ -1,64 +1,123 @@ FontAwesome->getClass('minus'); -} elseif ($variation > 0) { - $variationIcon = 'trends-arrow-up-white fs-6'; - $variationClass = 'bg-success'; -} else { - $variationIcon = 'trends-arrow-up-white fs-6 fa-rotate-180 fa-flip-vertical'; - $variationClass = 'bg-danger'; +if (!empty($variation)) { + if ($variation == 0) { + $variationIcon = $this->FontAwesome->getClass('minus'); + } elseif ($variation > 0) { + $variationIcon = 'trends-arrow-up-white fs-6'; + $variationClass = 'bg-success'; + } else { + $variationIcon = 'trends-arrow-up-white fs-6 fa-rotate-180 fa-flip-vertical'; + $variationClass = 'bg-danger'; + } } $series = []; +$statistics_day_number = ''; if (!empty($timeline['created']['timeline'])) { - $series[0]['name'] = __('Created'); - $series[0]['type'] = 'column'; + $statistics_day_number = $timeline['created']['days']; + $i = count($series); + $series[$i]['name'] = __('Created'); + $series[$i]['type'] = !empty($chartType) ? $chartType : 'column'; foreach ($timeline['created']['timeline'] as $entry) { - $series[0]['data'][] = $entry['count']; + $series[$i]['data'][] = ['x' => $entry['time'], 'y' => $entry['count']]; } } if (!empty($timeline['modified']['timeline'])) { - $series[1]['name'] = __('Modified'); - $series[1]['type'] = 'line'; + $statistics_day_number = empty($statistics_day_number) ? $timeline['modified']['days'] : $statistics_day_number; + $i = count($series); + $series[$i]['name'] = __('Modified'); + $series[$i]['type'] = !empty($chartType) ? $chartType : 'line'; foreach ($timeline['modified']['timeline'] as $entry) { - $series[1]['data'][] = $entry['count']; + $series[$i]['data'][] = ['x' => $entry['time'], 'y' => $entry['count']]; } } -$variationHtml = sprintf( - '
%s
', - $variationClass, - $variationIcon, - !empty($variation) ? h($variation) : '' -); +$variationHtml = ''; +if (!empty($variation)) { + $variationHtml = sprintf( + '
%s
', + $variationClass, + $variationIcon, + !empty($variation) ? h($variation) : '' + ); +} $titleHtml = isset($title) ? h($title) : ($titleHtml ?? ''); -$leftContent = sprintf('
%s

%s

%s', +$leftContent = sprintf( + '
%s
<%s class="%s">%s %s%s%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('
%s
', $this->element('charts/bar', [ 'series' => $series, - 'chartOptions' => [ - // 'colors' => ['var(--bs-light)', 'var(--bs-primary)'], - 'stroke' => [ - 'width' => [0, 2] + 'chartOptions' => array_merge( + [ + 'chart' => [ + 'height' => '90px', + ], + 'stroke' => [ + 'width' => [0, 2], + 'curve' => 'smooth', + ], ], - ] + !empty($chartOptions) ? $chartOptions : [] + ) ])); - -$cardContent = sprintf('
%s
%s
', $leftContent, $rightContent); +$cardContent = sprintf('
%s
%s
', $panelClasses ?? '', (!empty($condensed) ? 'max-height: 100px' : ''), $panelStyle ?? '', $leftContent, (!empty($condensed) ? 'p-2' : ''), $rightContent); echo $this->Bootstrap->card([ 'variant' => 'secondary', 'bodyHTML' => $cardContent, - 'bodyClass' => 'p-3', - 'class' => 'grow-on-hover shadow-sm' + 'bodyClass' => (!empty($condensed) ? 'py-1 px-2' : 'p-3'), + 'class' => ['shadow-sm', (empty($panelNoGrow) ? 'grow-on-hover' : '')] ]); ?> + + + + \ No newline at end of file