-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
MigrationList
controller & widget
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* Icinga Web 2 | (c) 2023 Icinga GmbH | GPLv2+ */ | ||
|
||
namespace Icinga\Controllers; | ||
|
||
use Icinga\Application\Hook\MigrationHook; | ||
use Icinga\Web\View\MigrationList; | ||
use ipl\Html\HtmlElement; | ||
use ipl\Html\HtmlString; | ||
use ipl\Web\Compat\CompatController; | ||
|
||
class MigrationListController extends CompatController | ||
{ | ||
public function indexAction() | ||
{ | ||
$migrations = MigrationHook::getPendingMigrations()->select(); | ||
$this->setupSortControl( | ||
[ | ||
'name' => $this->translate('Name'), | ||
'state' => $this->translate('State') | ||
], | ||
$migrations, | ||
['name' => 'DESC'] | ||
); | ||
$this->setupLimitControl(); | ||
$this->setupPaginationControl($migrations); | ||
$this->setupFilterControl($migrations, [ | ||
'name' => $this->translate('Name'), | ||
'state' => $this->translate('State'), | ||
], ['name']); | ||
|
||
$this->addControl(HtmlString::create((string) $this->view->paginator)); | ||
$this->addControl(HtmlElement::create('div', ['class' => 'sort-controls-container'], [ | ||
HtmlString::create((string) $this->view->limiter), | ||
HtmlString::create((string) $this->view->sortBox) | ||
])); | ||
$this->addControl(HtmlString::create((string) $this->view->filterEditor)); | ||
|
||
$this->addTitleTab($this->translate('Migrations')); | ||
$this->getTabs()->disableLegacyExtensions(); | ||
$this->setAutorefreshInterval(10); | ||
$this->addContent(new MigrationList($migrations)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Icinga\Web\View; | ||
|
||
use Icinga\Authentication\Auth; | ||
use ipl\Html\FormattedString; | ||
use ipl\Html\HtmlElement; | ||
use ipl\Html\Table; | ||
use ipl\Html\Text; | ||
use ipl\Web\Common\BaseTarget; | ||
use ipl\Web\Widget\Link; | ||
use Traversable; | ||
|
||
class MigrationList extends Table | ||
{ | ||
use BaseTarget; | ||
|
||
protected $defaultAttributes = ['class' => ['app-health', 'common-table', 'table-row-selectable']]; | ||
|
||
/** @var Traversable */ | ||
protected $migrations = []; | ||
|
||
public function __construct(Traversable $migrations) | ||
{ | ||
$this->migrations = $migrations; | ||
} | ||
|
||
protected function assemble() | ||
{ | ||
if (empty($this->migrations)) { | ||
$this->addHtml(HtmlElement::create('pre', null, Text::create(t('There are no pending migrations')))); | ||
|
||
return; | ||
} | ||
|
||
$hasPermission = Auth::getInstance()->hasPermission('application/migrations'); | ||
foreach ($this->migrations as $migration) { | ||
$attributes = [ | ||
'data-icinga-modal' => true, | ||
'data-no-icinga-ajax' => true | ||
]; | ||
|
||
$name = HtmlElement::create('span', null, $migration->name); | ||
$this->addHtml( | ||
Table::tr([ | ||
Table::th(HtmlElement::create('span', ['class' => ['ball', 'ball-size-xl', $migration->state]])), | ||
Table::td([ | ||
new HtmlElement( | ||
'header', | ||
null, | ||
FormattedString::create( | ||
t( | ||
'%s has %s %s %s migrations', | ||
'<name> has <count-migrations> <migration-type> <state-text> migrations' | ||
), | ||
$migration->url && $hasPermission | ||
? new Link($name, $migration->url, $attributes) | ||
: $name, | ||
HtmlElement::create('span', null, $migration->pending ?: ""), | ||
HtmlElement::create('strong', null, $migration->stateText), | ||
$migration->db | ||
? HtmlElement::create('span', null, 'DB') | ||
: HtmlElement::create('span', null, 'PHP-Code') | ||
) | ||
), | ||
HtmlElement::create('section', null, $migration->description) | ||
]) | ||
], $attributes) | ||
); | ||
} | ||
} | ||
} |