StateItemTable: Add missing property $emptyStateMessage and getter/setter (#1183)

fixes https://github.com/Icinga/icingadb-web/issues/1182
This commit is contained in:
Sukhwinder Dhillon 2025-05-12 13:42:07 +02:00 committed by GitHub
parent 63379898ac
commit 101f046f72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,9 @@ use ipl\Html\Form;
use ipl\Html\Html;
use ipl\Html\HtmlElement;
use ipl\Html\HtmlString;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\I18n\Translation;
use ipl\Orm\Common\SortUtil;
use ipl\Orm\Query;
use ipl\Web\Control\SortControl;
@ -19,6 +22,8 @@ use ipl\Web\Widget\Icon;
/** @todo Figure out what this might (should) have in common with the new ItemTable implementation */
abstract class StateItemTable extends BaseHtmlElement
{
use Translation;
protected $baseAttributes = [
'class' => 'state-item-table'
];
@ -34,6 +39,9 @@ abstract class StateItemTable extends BaseHtmlElement
protected $tag = 'table';
/** @var ?ValidHtml Message to show if the list is empty */
protected $emptyStateMessage;
/**
* Create a new item table
*
@ -59,6 +67,38 @@ abstract class StateItemTable extends BaseHtmlElement
{
}
/**
* Get message to show if the list is empty
*
* @return ValidHtml
*/
public function getEmptyStateMessage(): ValidHtml
{
if ($this->emptyStateMessage === null) {
return new Text($this->translate('No items found.'));
}
return $this->emptyStateMessage;
}
/**
* Set message to show if the list is empty
*
* @param mixed $message If empty, the default message is used
*
* @return $this
*/
public function setEmptyStateMessage($message): self
{
if (empty($message)) {
$this->emptyStateMessage = null;
} else {
$this->emptyStateMessage = Html::wantHtml($message);
}
return $this;
}
/**
* Get the columns being rendered
*
@ -89,7 +129,7 @@ abstract class StateItemTable extends BaseHtmlElement
protected function getVisualLabel()
{
return new Icon('heartbeat', ['title' => t('Severity')]);
return new Icon('heartbeat', ['title' => $this->translate('Severity')]);
}
protected function assembleColumnHeader(BaseHtmlElement $header, string $name, $label): void
@ -186,8 +226,8 @@ abstract class StateItemTable extends BaseHtmlElement
null,
new HtmlElement(
'td',
Attributes::create(['colspan' => count($this->columns)]),
new EmptyStateBar(t('No items found.'))
Attributes::create(['colspan' => count($this->columns) + 1]),
new EmptyStateBar($this->getEmptyStateMessage())
)
));
}