Change default subpanel insight injection

This commit is contained in:
Clemente Raposo 2021-02-11 18:38:40 +00:00 committed by Dillon-Brown
parent 1235fdfed1
commit 34e4a90e00
3 changed files with 124 additions and 54 deletions

View file

@ -26,6 +26,11 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv
public function getData(array $query): Statistic
{
$subpanel = $query['key'];
if ($subpanel === 'default' && isset($query['params']['subpanel'])) {
$subpanel = $query['params']['subpanel'];
}
[$module, $id] = $this->extractContext($query);
if (empty($module) || empty($id)) {
return $this->getEmptyResponse(self::KEY);
@ -35,14 +40,17 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv
$this->startLegacyApp();
$queries = $this->getQueries($module, $id, $subpanel);
$parts = $queries[0];
$parts['select'] = 'SELECT COUNT(*) as value';
$dbQuery = $this->joinQueryParts($parts);
$result = $this->fetchRow($dbQuery);
$statistic = $this->buildSingleValueResponse(self::KEY, 'int', $result);
$this->addMetadata($statistic, ['tooltip_title_key' => 'LBL_DEFAULT_TOTAL']);
$this->close();
return $statistic;
}
}

View file

@ -125,42 +125,7 @@ class SubPanelDefinitionHandler extends LegacyHandler implements SubPanelDefinit
$tabs[$key]['headerModule'] = $headerModule;
$tabs[$key]['top_buttons'] = $this->mapButtons($subpanel, $tab);
if (empty($tabs[$key]['insightWidget'])) {
$tabs[$key]['insightWidget'] = [
'type' => 'statistics',
'options' => [
'insightWidget' => [
'rows' => [
[
'cols' => [
[
'icon' => $tab['module'],
],
]
],
[
'cols' => [
[
'labelKey' => $tabs[$key]['title_key'],
'class' => 'sub-panel-banner-button-title text-truncate',
'bold' => true,
]
]
],
[
'cols' => [
[
'statistic' => $tabs[$key]['module'],
'class' => 'sub-panel-banner-button-stats',
'bold' => true,
],
]
],
]
]
]
];
}
$tabs[$key]['insightWidget'] = $this->mapInsightWidget($subpanel, $tabs, $key, $tab);
if (empty($columnSubpanel)) {
continue;
@ -183,31 +148,24 @@ class SubPanelDefinitionHandler extends LegacyHandler implements SubPanelDefinit
$vardefModule = $tab['module'];
if (empty($tab['header_definition_from_subpanel']) || empty($tab['collection_list'])) {
$vardefModule = $this->moduleNameMapper->toFrontEnd($vardefModule);
return $vardefModule;
return $this->moduleNameMapper->toFrontEnd($vardefModule);
}
$headerModule = $tab['header_definition_from_subpanel'];
$vardefModule = $tab['collection_list'][$headerModule]['module'] ?? '';
if ($vardefModule) {
$vardefModule = $this->moduleNameMapper->toFrontEnd($vardefModule);
return $vardefModule;
return $this->moduleNameMapper->toFrontEnd($vardefModule);
}
$vardefModule = reset($tab['collection_list'])['module'] ?? '';
if ($vardefModule) {
$vardefModule = $this->moduleNameMapper->toFrontEnd($vardefModule);
return $vardefModule;
return $this->moduleNameMapper->toFrontEnd($vardefModule);
}
$vardefModule = $tab['module'];
$vardefModule = $this->moduleNameMapper->toFrontEnd($vardefModule);
return $vardefModule;
return $this->moduleNameMapper->toFrontEnd($vardefModule);
}
/**
@ -365,8 +323,117 @@ class SubPanelDefinitionHandler extends LegacyHandler implements SubPanelDefinit
$column['link'] = true;
}
$column = $this->addFieldDefinition($vardefs, strtolower($key), $column, $this->defaultDefinition);
return $this->addFieldDefinition($vardefs, strtolower($key), $column, $this->defaultDefinition);
}
return $column;
/**
* @param $subpanel
* @param array $tabs
* @param $key
* @param $tab
* @return array
*/
protected function mapInsightWidget($subpanel, array $tabs, $key, $tab): array
{
if (!empty($subpanel->panel_definition['insightWidget'])) {
$widgetConfig = [
'type' => 'statistics',
'options' => [
'insightWidget' => $subpanel->panel_definition['insightWidget']
]
];
$this->replaceVariables($tabs, $key, $widgetConfig, $widgetRows);
return $widgetConfig;
}
if (empty($tabs[$key]['insightWidget'])) {
return $this->getDefaultWidgetConfig($tabs, $key, $tab);
}
return [];
}
/**
* @param array $tabs
* @param $key
* @param $tab
* @return array
*/
protected function getDefaultWidgetConfig(array $tabs, $key, $tab): array
{
return [
'type' => 'statistics',
'options' => [
'insightWidget' => [
'rows' => [
[
'cols' => [
[
'icon' => $tab['module'],
],
]
],
[
'cols' => [
[
'labelKey' => $tabs[$key]['title_key'],
'class' => 'sub-panel-banner-button-title',
'bold' => true,
]
]
],
[
'cols' => [
[
'statistic' => $tabs[$key]['module'],
'class' => 'sub-panel-banner-button-stats',
'bold' => true,
],
]
],
]
]
]
];
}
/**
* @param string $titleKey
* @param $col
* @param array $widgetRows
* @param $rowKey
* @param $colKey
*/
protected function replaceLabelKey(string $titleKey, $col, array &$widgetRows, $rowKey, $colKey): void
{
$labelKey = $col['labelKey'] ?? '';
if ($labelKey !== '') {
$labelKey = str_replace('{{title_key}}', $titleKey, $labelKey);
$widgetRows[$rowKey]['cols'][$colKey]['labelKey'] = $labelKey;
}
}
/**
* @param array $tabs
* @param $key
* @param array $widgetConfig
* @param $widgetRows
*/
protected function replaceVariables(array $tabs, $key, array &$widgetConfig, &$widgetRows): void
{
$widgetRows = $widgetConfig['options']['insightWidget']['rows'] ?? [];
foreach ($widgetRows as $rowKey => $row) {
$cols = $row['cols'] ?? [];
foreach ($cols as $colKey => $col) {
$this->replaceLabelKey($tabs[$key]['title_key'], $col, $widgetRows, $rowKey, $colKey);
}
}
if (isset($widgetConfig['options']['insightWidget']['rows'])) {
$widgetConfig['options']['insightWidget']['rows'] = $widgetRows;
}
}
}

View file

@ -36,11 +36,6 @@ class StatisticsItemResolver implements QueryItemResolverInterface
return null;
}
if (empty($context['args']['query']['key'])) {
return $this->registry->get('default')->getData($query);
}
[$module] = $this->extractContext($query);
$key = $context['args']['query']['key'] ?? 'default';