Skip to content

Commit

Permalink
Don't render apply all button when there is no result set
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jul 26, 2023
1 parent 3b05583 commit 438f7aa
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions library/Icinga/Web/Widget/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Icinga\Web\Widget;

use Generator;
use Icinga\Data\Filter\Filter;
use Icinga\Data\SimpleQuery;
use Icinga\Forms\MigrationForm;
use Icinga\Web\Widget\ItemList\MigrationList;
use ipl\Html\BaseHtmlElement;
Expand All @@ -18,19 +20,25 @@ class Migrations extends BaseHtmlElement

protected $defaultAttributes = ['class' => 'migrations'];

/** @var Generator */
/** @var Traversable */
protected $moduleMigrations;

/** @var Generator */
/** @var Traversable */
protected $systemMigrations;

/** @var callable */
protected $formCallback;

public function __construct(Traversable $migrations, callable $formCallback)
public function __construct(SimpleQuery $migrations, callable $formCallback)
{
$this->moduleMigrations = $this->yieldModuleMigrations($migrations);
$this->systemMigrations = $this->yieldSystemMigrations($migrations);
$modulesQuery = clone $migrations;
$modulesQuery->addFilter(Filter::where('isModule', true));

$systemQuery = clone $migrations;
$systemQuery->addFilter(Filter::where('isModule', false));

$this->moduleMigrations = $modulesQuery;
$this->systemMigrations = $systemQuery;
$this->formCallback = $formCallback;
}

Expand All @@ -44,33 +52,15 @@ protected function assemble()
call_user_func_array($this->formCallback, [$migrationForm]);

$header = HtmlElement::create('div', ['class' => 'modules-header']);
$header->addHtml(
HtmlElement::create('h2', ['class' => 'migration-list-header'], Text::create(t('Modules'))),
$migrationForm
);
$header->addHtml(HtmlElement::create('h2', ['class' => 'migration-list-header'], Text::create(t('Modules'))));
if ($this->moduleMigrations->hasResult()) {
$header->addHtml($migrationForm);
}

$moduleListControl = HtmlElement::create('div', ['class' => 'migration-list-control']);
$moduleListControl->addHtml($header, new MigrationList($this->moduleMigrations, $this->formCallback));

$this->addHtml($frameWorkListControl);
$this->addHtml($moduleListControl);
}

protected function yieldSystemMigrations(Traversable $migrations): Generator
{
foreach ($migrations as $migration) {
if (! $migration->isModule) {
yield $migration;
}
}
}

protected function yieldModuleMigrations(Traversable $migrations): Generator
{
foreach ($migrations as $migration) {
if ($migration->isModule) {
yield $migration;
}
}
}
}

0 comments on commit 438f7aa

Please sign in to comment.