Rename migration list item classes
This commit is contained in:
parent
821a6812ae
commit
a167b6d21a
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
/* Icinga Web 2 | (c) 2023 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Widget\ItemList;
|
||||
|
||||
use Icinga\Application\Hook\Common\DbMigration;
|
||||
use ipl\Html\Attributes;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\Html;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\HtmlString;
|
||||
use ipl\Html\Text;
|
||||
use ipl\I18n\Translation;
|
||||
use ipl\Web\Common\BaseListItem;
|
||||
use ipl\Web\Widget\EmptyState;
|
||||
use ipl\Web\Widget\Icon;
|
||||
|
||||
class MigrationFileListItem extends BaseListItem
|
||||
{
|
||||
use Translation;
|
||||
|
||||
/** @var DbMigration Just for type hint */
|
||||
protected $item;
|
||||
|
||||
protected function assembleVisual(BaseHtmlElement $visual): void
|
||||
{
|
||||
if ($this->item->getLastState()) {
|
||||
$visual->getAttributes()->add('class', 'upgrade-failed');
|
||||
$visual->addHtml(new Icon('circle-xmark'));
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleTitle(BaseHtmlElement $title): void
|
||||
{
|
||||
$scriptPath = $this->item->getScriptPath();
|
||||
/** @var string $parentDirs */
|
||||
$parentDirs = substr($scriptPath, (int) strpos($scriptPath, 'schema'));
|
||||
$parentDirs = substr($parentDirs, 0, strrpos($parentDirs, '/') + 1);
|
||||
|
||||
$title->addHtml(
|
||||
new HtmlElement('span', null, Text::create($parentDirs)),
|
||||
new HtmlElement(
|
||||
'span',
|
||||
Attributes::create(['class' => 'version']),
|
||||
Text::create($this->item->getVersion() . '.sql')
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->item->getLastState()) {
|
||||
$title->addHtml(
|
||||
new HtmlElement(
|
||||
'span',
|
||||
Attributes::create(['class' => 'upgrade-failed']),
|
||||
Text::create($this->translate('Upgrade failed'))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleHeader(BaseHtmlElement $header): void
|
||||
{
|
||||
$header->addHtml($this->createTitle());
|
||||
}
|
||||
|
||||
protected function assembleCaption(BaseHtmlElement $caption): void
|
||||
{
|
||||
if ($this->item->getDescription()) {
|
||||
$caption->addHtml(Text::create($this->item->getDescription()));
|
||||
} else {
|
||||
$caption->addHtml(new EmptyState(Text::create($this->translate('No description provided.'))));
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleFooter(BaseHtmlElement $footer): void
|
||||
{
|
||||
if ($this->item->getLastState()) {
|
||||
$footer->addHtml(
|
||||
new HtmlElement(
|
||||
'section',
|
||||
Attributes::create(['class' => 'caption']),
|
||||
new HtmlElement('pre', null, new HtmlString(Html::escape($this->item->getLastState())))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleMain(BaseHtmlElement $main): void
|
||||
{
|
||||
$main->addHtml($this->createHeader(), $this->createCaption());
|
||||
}
|
||||
}
|
|
@ -69,10 +69,10 @@ class MigrationList extends BaseItemList
|
|||
protected function getItemClass(): string
|
||||
{
|
||||
if ($this->isMinimal()) {
|
||||
return MigrationListItemMinimal::class;
|
||||
return MigrationListItem::class;
|
||||
}
|
||||
|
||||
return MigrationListItem::class;
|
||||
return MigrationFileListItem::class;
|
||||
}
|
||||
|
||||
protected function assemble(): void
|
||||
|
@ -84,9 +84,9 @@ class MigrationList extends BaseItemList
|
|||
|
||||
/** @var MigrationHook $data */
|
||||
foreach ($this->data as $data) {
|
||||
/** @var MigrationListItem|MigrationListItemMinimal $item */
|
||||
/** @var MigrationFileListItem|MigrationListItem $item */
|
||||
$item = new $itemClass($data, $this);
|
||||
if ($item instanceof MigrationListItemMinimal && $this->migrationForm) {
|
||||
if ($item instanceof MigrationListItem && $this->migrationForm) {
|
||||
$migrateButton = $this->migrationForm->createElement(
|
||||
'submit',
|
||||
sprintf('migrate-%s', $data->getModuleName()),
|
||||
|
|
|
@ -5,81 +5,131 @@
|
|||
namespace Icinga\Web\Widget\ItemList;
|
||||
|
||||
use Icinga\Application\Hook\Common\DbMigration;
|
||||
use Icinga\Application\Hook\MigrationHook;
|
||||
use ipl\Html\Attributes;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\Contract\FormElement;
|
||||
use ipl\Html\FormattedString;
|
||||
use ipl\Html\Html;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\HtmlString;
|
||||
use ipl\Html\Text;
|
||||
use ipl\I18n\Translation;
|
||||
use ipl\Web\Common\BaseListItem;
|
||||
use ipl\Web\Url;
|
||||
use ipl\Web\Widget\EmptyState;
|
||||
use ipl\Web\Widget\Icon;
|
||||
use ipl\Web\Widget\Link;
|
||||
use LogicException;
|
||||
|
||||
class MigrationListItem extends BaseListItem
|
||||
{
|
||||
use Translation;
|
||||
|
||||
/** @var DbMigration Just for type hint */
|
||||
/** @var ?FormElement */
|
||||
protected $migrateButton;
|
||||
|
||||
/** @var MigrationHook Just for type hint */
|
||||
protected $item;
|
||||
|
||||
protected function assembleVisual(BaseHtmlElement $visual): void
|
||||
/**
|
||||
* Set a migration form of this list item
|
||||
*
|
||||
* @param FormElement $migrateButton
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMigrateButton(FormElement $migrateButton): self
|
||||
{
|
||||
if ($this->item->getLastState()) {
|
||||
$visual->getAttributes()->add('class', 'upgrade-failed');
|
||||
$visual->addHtml(new Icon('circle-xmark'));
|
||||
}
|
||||
$this->migrateButton = $migrateButton;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function assembleTitle(BaseHtmlElement $title): void
|
||||
{
|
||||
$scriptPath = $this->item->getScriptPath();
|
||||
/** @var string $parentDirs */
|
||||
$parentDirs = substr($scriptPath, (int) strpos($scriptPath, 'schema'));
|
||||
$parentDirs = substr($parentDirs, 0, strrpos($parentDirs, '/') + 1);
|
||||
|
||||
$title->addHtml(
|
||||
new HtmlElement('span', null, Text::create($parentDirs)),
|
||||
new HtmlElement(
|
||||
'span',
|
||||
Attributes::create(['class' => 'version']),
|
||||
Text::create($this->item->getVersion() . '.sql')
|
||||
FormattedString::create(
|
||||
t('%s ', '<name>'),
|
||||
HtmlElement::create('span', ['class' => 'subject'], $this->item->getName())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->item->getLastState()) {
|
||||
protected function assembleHeader(BaseHtmlElement $header): void
|
||||
{
|
||||
if ($this->migrateButton === null) {
|
||||
throw new LogicException('Please set the migrate submit button beforehand');
|
||||
}
|
||||
|
||||
$header->addHtml($this->createTitle());
|
||||
$header->addHtml($this->migrateButton);
|
||||
}
|
||||
|
||||
protected function assembleCaption(BaseHtmlElement $caption): void
|
||||
{
|
||||
$migrations = $this->item->getMigrations();
|
||||
/** @var DbMigration $migration */
|
||||
$migration = array_shift($migrations);
|
||||
if ($migration->getLastState()) {
|
||||
if ($migration->getDescription()) {
|
||||
$caption->addHtml(Text::create($migration->getDescription()));
|
||||
} else {
|
||||
$caption->addHtml(new EmptyState(Text::create($this->translate('No description provided.'))));
|
||||
}
|
||||
|
||||
$scriptPath = $migration->getScriptPath();
|
||||
/** @var string $parentDirs */
|
||||
$parentDirs = substr($scriptPath, (int) strpos($scriptPath, 'schema'));
|
||||
$parentDirs = substr($parentDirs, 0, strrpos($parentDirs, '/') + 1);
|
||||
|
||||
$title = new HtmlElement('div', Attributes::create(['class' => 'title']));
|
||||
$title->addHtml(
|
||||
new HtmlElement('span', null, Text::create($parentDirs)),
|
||||
new HtmlElement(
|
||||
'span',
|
||||
Attributes::create(['class' => 'version']),
|
||||
Text::create($migration->getVersion() . '.sql')
|
||||
),
|
||||
new HtmlElement(
|
||||
'span',
|
||||
Attributes::create(['class' => 'upgrade-failed']),
|
||||
Text::create($this->translate('Upgrade failed'))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleHeader(BaseHtmlElement $header): void
|
||||
{
|
||||
$header->addHtml($this->createTitle());
|
||||
}
|
||||
$error = new HtmlElement('div', Attributes::create([
|
||||
'class' => 'collapsible',
|
||||
'data-visible-height' => '58',
|
||||
]));
|
||||
$error->addHtml(new HtmlElement('pre', null, new HtmlString(Html::escape($migration->getLastState()))));
|
||||
|
||||
protected function assembleCaption(BaseHtmlElement $caption): void
|
||||
{
|
||||
if ($this->item->getDescription()) {
|
||||
$caption->addHtml(Text::create($this->item->getDescription()));
|
||||
} else {
|
||||
$caption->addHtml(new EmptyState(Text::create($this->translate('No description provided.'))));
|
||||
$errorSection = new HtmlElement('div', Attributes::create(['class' => 'errors-section',]));
|
||||
$errorSection->addHtml(
|
||||
new HtmlElement('header', null, new Icon('circle-xmark', ['class' => 'status-icon']), $title),
|
||||
$caption,
|
||||
$error
|
||||
);
|
||||
|
||||
$caption->prependWrapper($errorSection);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleFooter(BaseHtmlElement $footer): void
|
||||
{
|
||||
if ($this->item->getLastState()) {
|
||||
$footer->addHtml((new MigrationList($this->item->getLatestMigrations(3)))->setMinimal(false));
|
||||
if ($this->item->count() > 3) {
|
||||
$footer->addHtml(
|
||||
new HtmlElement(
|
||||
'section',
|
||||
Attributes::create(['class' => 'caption']),
|
||||
new HtmlElement('pre', null, new HtmlString(Html::escape($this->item->getLastState())))
|
||||
new Link(
|
||||
sprintf($this->translate('Show all %d migrations'), $this->item->count()),
|
||||
Url::fromPath(
|
||||
'migrations/migration',
|
||||
[MigrationHook::MIGRATION_PARAM => $this->item->getModuleName()]
|
||||
),
|
||||
[
|
||||
'data-base-target' => '_next',
|
||||
'class' => 'show-more'
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -87,6 +137,15 @@ class MigrationListItem extends BaseListItem
|
|||
|
||||
protected function assembleMain(BaseHtmlElement $main): void
|
||||
{
|
||||
$main->addHtml($this->createHeader(), $this->createCaption());
|
||||
$main->addHtml($this->createHeader());
|
||||
$caption = $this->createCaption();
|
||||
if (! $caption->isEmpty()) {
|
||||
$main->addHtml($caption);
|
||||
}
|
||||
|
||||
$footer = $this->createFooter();
|
||||
if ($footer) {
|
||||
$main->addHtml($footer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,151 +0,0 @@
|
|||
<?php
|
||||
|
||||
/* Icinga Web 2 | (c) 2023 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Widget\ItemList;
|
||||
|
||||
use Icinga\Application\Hook\Common\DbMigration;
|
||||
use Icinga\Application\Hook\MigrationHook;
|
||||
use ipl\Html\Attributes;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\Contract\FormElement;
|
||||
use ipl\Html\FormattedString;
|
||||
use ipl\Html\Html;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Html\HtmlString;
|
||||
use ipl\Html\Text;
|
||||
use ipl\I18n\Translation;
|
||||
use ipl\Web\Common\BaseListItem;
|
||||
use ipl\Web\Url;
|
||||
use ipl\Web\Widget\EmptyState;
|
||||
use ipl\Web\Widget\Icon;
|
||||
use ipl\Web\Widget\Link;
|
||||
use LogicException;
|
||||
|
||||
class MigrationListItemMinimal extends BaseListItem
|
||||
{
|
||||
use Translation;
|
||||
|
||||
/** @var ?FormElement */
|
||||
protected $migrateButton;
|
||||
|
||||
/** @var MigrationHook Just for type hint */
|
||||
protected $item;
|
||||
|
||||
/**
|
||||
* Set a migration form of this list item
|
||||
*
|
||||
* @param FormElement $migrateButton
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMigrateButton(FormElement $migrateButton): self
|
||||
{
|
||||
$this->migrateButton = $migrateButton;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function assembleTitle(BaseHtmlElement $title): void
|
||||
{
|
||||
$title->addHtml(
|
||||
FormattedString::create(
|
||||
t('%s ', '<name>'),
|
||||
HtmlElement::create('span', ['class' => 'subject'], $this->item->getName())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function assembleHeader(BaseHtmlElement $header): void
|
||||
{
|
||||
if ($this->migrateButton === null) {
|
||||
throw new LogicException('Please set the migrate submit button beforehand');
|
||||
}
|
||||
|
||||
$header->addHtml($this->createTitle());
|
||||
$header->addHtml($this->migrateButton);
|
||||
}
|
||||
|
||||
protected function assembleCaption(BaseHtmlElement $caption): void
|
||||
{
|
||||
$migrations = $this->item->getMigrations();
|
||||
/** @var DbMigration $migration */
|
||||
$migration = array_shift($migrations);
|
||||
if ($migration->getLastState()) {
|
||||
if ($migration->getDescription()) {
|
||||
$caption->addHtml(Text::create($migration->getDescription()));
|
||||
} else {
|
||||
$caption->addHtml(new EmptyState(Text::create($this->translate('No description provided.'))));
|
||||
}
|
||||
|
||||
$scriptPath = $migration->getScriptPath();
|
||||
/** @var string $parentDirs */
|
||||
$parentDirs = substr($scriptPath, (int) strpos($scriptPath, 'schema'));
|
||||
$parentDirs = substr($parentDirs, 0, strrpos($parentDirs, '/') + 1);
|
||||
|
||||
$title = new HtmlElement('div', Attributes::create(['class' => 'title']));
|
||||
$title->addHtml(
|
||||
new HtmlElement('span', null, Text::create($parentDirs)),
|
||||
new HtmlElement(
|
||||
'span',
|
||||
Attributes::create(['class' => 'version']),
|
||||
Text::create($migration->getVersion() . '.sql')
|
||||
),
|
||||
new HtmlElement(
|
||||
'span',
|
||||
Attributes::create(['class' => 'upgrade-failed']),
|
||||
Text::create($this->translate('Upgrade failed'))
|
||||
)
|
||||
);
|
||||
|
||||
$error = new HtmlElement('div', Attributes::create([
|
||||
'class' => 'collapsible',
|
||||
'data-visible-height' => '58',
|
||||
]));
|
||||
$error->addHtml(new HtmlElement('pre', null, new HtmlString(Html::escape($migration->getLastState()))));
|
||||
|
||||
$errorSection = new HtmlElement('div', Attributes::create(['class' => 'errors-section',]));
|
||||
$errorSection->addHtml(
|
||||
new HtmlElement('header', null, new Icon('circle-xmark', ['class' => 'status-icon']), $title),
|
||||
$caption,
|
||||
$error
|
||||
);
|
||||
|
||||
$caption->prependWrapper($errorSection);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleFooter(BaseHtmlElement $footer): void
|
||||
{
|
||||
$footer->addHtml((new MigrationList($this->item->getLatestMigrations(3)))->setMinimal(false));
|
||||
if ($this->item->count() > 3) {
|
||||
$footer->addHtml(
|
||||
new Link(
|
||||
sprintf($this->translate('Show all %d migrations'), $this->item->count()),
|
||||
Url::fromPath(
|
||||
'migrations/migration',
|
||||
[MigrationHook::MIGRATION_PARAM => $this->item->getModuleName()]
|
||||
),
|
||||
[
|
||||
'data-base-target' => '_next',
|
||||
'class' => 'show-more'
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assembleMain(BaseHtmlElement $main): void
|
||||
{
|
||||
$main->addHtml($this->createHeader());
|
||||
$caption = $this->createCaption();
|
||||
if (! $caption->isEmpty()) {
|
||||
$main->addHtml($caption);
|
||||
}
|
||||
|
||||
$footer = $this->createFooter();
|
||||
if ($footer) {
|
||||
$main->addHtml($footer);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue