Render metrics using item_list theme
This commit is contained in:
parent
91a6fccf85
commit
4ef19c79ce
|
@ -1,5 +1,4 @@
|
||||||
.metrics-container {
|
.metrics-container ul {
|
||||||
margin-top: .5em;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: row wrap;
|
flex-flow: row wrap;
|
||||||
gap: .25em .5em;
|
gap: .25em .5em;
|
||||||
|
@ -7,6 +6,5 @@
|
||||||
|
|
||||||
.metrics-container a.metric {
|
.metrics-container a.metric {
|
||||||
flex-basis: 20%;
|
flex-basis: 20%;
|
||||||
margin: 0;
|
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,55 +72,41 @@ class FarmMetricsBlock extends BlockBase implements ContainerFactoryPluginInterf
|
||||||
public function build() {
|
public function build() {
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
// Create a container for asset metrics.
|
// Create a list of asset metrics.
|
||||||
$assets_label = $this->entityTypeManager->getStorage('asset')->getEntityType()->getCollectionLabel();
|
$assets_label = $this->entityTypeManager->getStorage('asset')->getEntityType()->getCollectionLabel() . ' (' . $this->t('active') . ')';
|
||||||
$output['asset']['label'] = [
|
$output['asset'] = [
|
||||||
'#type' => 'html_tag',
|
'#theme' => 'item_list',
|
||||||
'#tag' => 'h6',
|
'#title' => Link::createFromRoute($assets_label, 'view.farm_asset.page')->toRenderable(),
|
||||||
'#value' => Link::createFromRoute($assets_label, 'view.farm_asset.page')->toString() . ' (' . $this->t('active') . ')',
|
'#items' => $this->getEntityMetrics('asset'),
|
||||||
];
|
'#empty' => $this->t('No assets found.'),
|
||||||
$output['asset']['metrics'] = [
|
'#wrapper_attributes' => [
|
||||||
'#type' => 'container',
|
|
||||||
'#attributes' => [
|
|
||||||
'class' => ['assets', 'metrics-container'],
|
'class' => ['assets', 'metrics-container'],
|
||||||
],
|
],
|
||||||
];
|
'#cache' => [
|
||||||
$metrics = $this->getEntityMetrics('asset');
|
'tags' => [
|
||||||
foreach ($metrics as $metric) {
|
'asset_list',
|
||||||
$output['asset']['metrics'][] = [
|
'config:asset_type_list',
|
||||||
'#markup' => $metric,
|
],
|
||||||
];
|
],
|
||||||
}
|
];
|
||||||
if (empty($metrics)) {
|
|
||||||
$output['asset']['metrics']['empty']['#markup'] = '<p>' . $this->t('No assets found.') . '</p>';
|
// Create a list of log metrics.
|
||||||
}
|
$logs_label = $this->entityTypeManager->getStorage('log')->getEntityType()->getCollectionLabel();
|
||||||
$output['#cache']['tags'][] = 'asset_list';
|
$output['log'] = [
|
||||||
$output['#cache']['tags'][] = 'config:asset_type_list';
|
'#theme' => 'item_list',
|
||||||
|
'#title' => Link::createFromRoute($logs_label, 'view.farm_log.page')->toRenderable(),
|
||||||
// Create a section for log metrics.
|
'#items' => $this->getEntityMetrics('log'),
|
||||||
$logs_label = $this->entityTypeManager->getStorage('log')->getEntityType()->getCollectionLabel();
|
'#empty' => $this->t('No logs found.'),
|
||||||
$output['log']['label'] = [
|
'#wrapper_attributes' => [
|
||||||
'#type' => 'html_tag',
|
'class' => ['logs', 'metrics-container'],
|
||||||
'#tag' => 'h6',
|
],
|
||||||
'#value' => Link::createFromRoute($logs_label, 'view.farm_log.page')->toString(),
|
'#cache' => [
|
||||||
];
|
'tags' => [
|
||||||
$output['log']['metrics'] = [
|
'log_list',
|
||||||
'#type' => 'container',
|
'config:log_type_list',
|
||||||
'#attributes' => [
|
],
|
||||||
'class' => ['logs', 'metrics-container'],
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$metrics = $this->getEntityMetrics('log');
|
|
||||||
foreach ($metrics as $metric) {
|
|
||||||
$output['log']['metrics'][] = [
|
|
||||||
'#markup' => $metric,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
if (empty($metrics)) {
|
|
||||||
$output['log']['metrics']['empty']['#markup'] = '<p>' . $this->t('No logs found.') . '</p>';
|
|
||||||
}
|
|
||||||
$output['#cache']['tags'][] = 'log_list';
|
|
||||||
$output['#cache']['tags'][] = 'config:log_type_list';
|
|
||||||
|
|
||||||
// Attach CSS.
|
// Attach CSS.
|
||||||
$output['#attached']['library'][] = 'farm_ui_metrics/metrics_block';
|
$output['#attached']['library'][] = 'farm_ui_metrics/metrics_block';
|
||||||
|
@ -157,7 +143,7 @@ class FarmMetricsBlock extends BlockBase implements ContainerFactoryPluginInterf
|
||||||
|
|
||||||
$count = $query->count()->execute();
|
$count = $query->count()->execute();
|
||||||
$route_name = "view.farm_$entity_type.page_type";
|
$route_name = "view.farm_$entity_type.page_type";
|
||||||
$metrics[] = Link::createFromRoute($bundle_info['label'] . ': ' . $count, $route_name, ['arg_0' => $bundle], ['attributes' => ['class' => ['metric', 'button', 'button--small']]])->toString();
|
$metrics[] = Link::createFromRoute($bundle_info['label'] . ': ' . $count, $route_name, ['arg_0' => $bundle], ['attributes' => ['class' => ['metric']]])->toRenderable();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $metrics;
|
return $metrics;
|
||||||
|
|
Loading…
Reference in New Issue