Don't fail to render the whole dashboard in case of a broken dashlet

This commit is contained in:
Alexander A. Klimov 2018-01-17 13:48:14 +01:00
parent 705f3a49d9
commit 5f441f3ad1
1 changed files with 32 additions and 6 deletions

View File

@ -69,6 +69,19 @@ class Dashlet extends UserWidget
</div>
EOD;
/**
* The template string used for rendering this widget in case of an error
*
* @var string
*/
private $errorTemplate = <<<'EOD'
<div class="container">
<h1 title="{TOOLTIP}">{TITLE}</h1>
<p class="error-message">{ERROR_MESSAGE}</p>
</div>
EOD;
/**
* Create a new dashlet displaying the given url in the provided pane
*
@ -80,12 +93,6 @@ EOD;
{
$this->title = $title;
$this->pane = $pane;
if (! $url) {
throw new IcingaException(
'Cannot create dashboard dashlet "%s" without valid URL',
$title
);
}
$this->url = $url;
}
@ -207,6 +214,25 @@ EOD;
}
$view = $this->view();
if (! $this->url) {
$searchTokens = array(
'{TOOLTIP}',
'{TITLE}',
'{ERROR_MESSAGE}'
);
$replaceTokens = array(
sprintf($view->translate('Show %s', 'dashboard.dashlet.tooltip'), $view->escape($this->getTitle())),
$view->escape($this->getTitle()),
$view->escape(
sprintf($view->translate('Cannot create dashboard dashlet "%s" without valid URL'), $this->title)
)
);
return str_replace($searchTokens, $replaceTokens, $this->errorTemplate);
}
$url = $this->getUrl();
$url->setParam('view', 'compact');
$iframeUrl = clone $url;