Skip to content

Commit

Permalink
BaseItemTable: Introduce layout modes
Browse files Browse the repository at this point in the history
This elevates the layout `table-layout`, previously
introduced exclusively for host and service group
tables, to the standard layout used for item tables.

fixes #814
  • Loading branch information
nilmerg committed Aug 11, 2023
1 parent 987a0a3 commit dd803f6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
12 changes: 12 additions & 0 deletions library/Icingadb/Common/BaseItemTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,22 @@ protected function init()
{
}

/**
* Get the table layout to use
*
* @return string
*/
protected function getLayout(): string
{
return 'table-layout';
}

abstract protected function getItemClass(): string;

protected function assemble()
{
$this->addAttributes(['class' => $this->getLayout()]);

$itemClass = $this->getItemClass();

foreach ($this->data as $data) {
Expand Down
17 changes: 10 additions & 7 deletions library/Icingadb/Widget/ItemTable/HostgroupTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ protected function init()
$this->setDetailUrl(Url::fromPath('icingadb/hostgroup'));
}

protected function getItemClass(): string
protected function getLayout(): string
{
if ($this->getViewMode() === 'grid') {
$this->addAttributes(['class' => 'group-grid']);
return HostgroupGridCell::class;
}
return $this->getViewMode() === 'grid'
? 'group-grid'
: parent::getLayout();
}

$this->addAttributes(['class' => 'table-layout']);
return HostgroupTableRow::class;
protected function getItemClass(): string
{
return $this->getViewMode() === 'grid'
? HostgroupGridCell::class
: HostgroupTableRow::class;
}
}
17 changes: 10 additions & 7 deletions library/Icingadb/Widget/ItemTable/ServicegroupTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ protected function init()
$this->setDetailUrl(Url::fromPath('icingadb/servicegroup'));
}

protected function getItemClass(): string
protected function getLayout(): string
{
if ($this->getViewMode() === 'grid') {
$this->addAttributes(['class' => 'group-grid']);
return ServicegroupGridCell::class;
}
return $this->getViewMode() === 'grid'
? 'group-grid'
: parent::getLayout();
}

$this->addAttributes(['class' => 'table-layout']);
return ServicegroupTableRow::class;
protected function getItemClass(): string
{
return $this->getViewMode() === 'grid'
? ServicegroupGridCell::class
: ServicegroupTableRow::class;
}
}
8 changes: 4 additions & 4 deletions public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ div.show-more {
&.servicegroup-table {
--columns: 1;
}
}

&.user-table, // TODO: make them lists.....
&.usergroup-table {
--columns: 0;
&.user-table, // TODO: make them lists.....
&.usergroup-table {
--columns: 0;
}
}
}

Expand Down

0 comments on commit dd803f6

Please sign in to comment.