From 6b4a3cbc0cb088cee2632c505966deee140c99ed Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 9 Jun 2023 10:33:22 +0200 Subject: [PATCH] Do not break overview page if existing `business-process` has invalid config - Add icon and config file name to broken `business-process` - Use font-awesome icon --- .../Web/Component/BpDashboardTile.php | 10 ++++------ .../Businessprocess/Web/Component/Dashboard.php | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/library/Businessprocess/Web/Component/BpDashboardTile.php b/library/Businessprocess/Web/Component/BpDashboardTile.php index 17d3a0c..9a4a0f6 100644 --- a/library/Businessprocess/Web/Component/BpDashboardTile.php +++ b/library/Businessprocess/Web/Component/BpDashboardTile.php @@ -3,10 +3,12 @@ namespace Icinga\Module\Businessprocess\Web\Component; use Icinga\Module\Businessprocess\BpConfig; -use Icinga\Web\Url; use ipl\Html\BaseHtmlElement; use ipl\Html\Html; use ipl\Html\Text; +use ipl\Web\Url; +use ipl\Web\Widget\Icon; +use ipl\Web\Widget\Link; class BpDashboardTile extends BaseHtmlElement { @@ -16,14 +18,10 @@ class BpDashboardTile extends BaseHtmlElement public function __construct(BpConfig $bp, $title, $description, $icon, $url, $urlParams = null, $attributes = null) { - if (! isset($attributes['href'])) { - $attributes['href'] = Url::fromPath($url, $urlParams ?: []); - } - $this->add(Html::tag( 'div', ['class' => 'bp-link', 'data-base-target' => '_main'], - Html::tag('a', $attributes, Html::tag('i', ['class' => 'icon icon-' . $icon])) + (new Link(new Icon($icon), Url::fromPath($url, $urlParams ?: []), $attributes)) ->add(Html::tag('span', ['class' => 'header'], $title)) ->add($description) )); diff --git a/library/Businessprocess/Web/Component/Dashboard.php b/library/Businessprocess/Web/Component/Dashboard.php index 3423b2f..e78c46c 100644 --- a/library/Businessprocess/Web/Component/Dashboard.php +++ b/library/Businessprocess/Web/Component/Dashboard.php @@ -2,8 +2,10 @@ namespace Icinga\Module\Businessprocess\Web\Component; +use Exception; use Icinga\Application\Modules\Module; use Icinga\Authentication\Auth; +use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; use Icinga\Module\Businessprocess\State\IcingaDbState; use Icinga\Module\Businessprocess\State\MonitoringState; @@ -92,7 +94,20 @@ class Dashboard extends BaseHtmlElement $title = $name; } - $bp = $storage->loadProcess($name); + try { + $bp = $storage->loadProcess($name); + } catch (Exception $e) { + $this->add(new BpDashboardTile( + new BpConfig(), + $title, + sprintf(t('File %s has invalid config'), $name . '.conf'), + 'file-circle-xmark', + 'businessprocess/process/show', + ['config' => $name] + )); + + continue; + } if (Module::exists('icingadb') && (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())