Basket: load by name

This commit is contained in:
Thomas Gelf 2018-10-09 14:09:11 +02:00
parent 5c3e220d4b
commit bea52a3091
4 changed files with 24 additions and 25 deletions

View File

@ -24,15 +24,15 @@ class BasketController extends ActionController
protected function basketTabs() protected function basketTabs()
{ {
$uuid = $this->params->get('uuid'); $name = $this->params->get('name');
return $this->tabs()->add('show', [ return $this->tabs()->add('show', [
'label' => $this->translate('Basket'), 'label' => $this->translate('Basket'),
'url' => 'director/basket', 'url' => 'director/basket',
'urlParams' => ['uuid' => $uuid] 'urlParams' => ['name' => $name]
])->add('snapshots', [ ])->add('snapshots', [
'label' => $this->translate('Snapshots'), 'label' => $this->translate('Snapshots'),
'url' => 'director/basket/snapshots', 'url' => 'director/basket/snapshots',
'urlParams' => ['uuid' => $uuid] 'urlParams' => ['name' => $name]
]); ]);
} }
@ -49,8 +49,7 @@ class BasketController extends ActionController
['class' => 'icon-left-big'] ['class' => 'icon-left-big']
) )
); );
$uuid = hex2bin($this->params->get('uuid')); $basket = $this->requireBasket();
$basket = Basket::load($uuid, $this->db());
$this->basketTabs()->activate('show'); $this->basketTabs()->activate('show');
$this->addTitle($basket->get('basket_name')); $this->addTitle($basket->get('basket_name'));
if ($basket->isEmpty()) { if ($basket->isEmpty()) {
@ -86,12 +85,11 @@ class BasketController extends ActionController
*/ */
public function snapshotsAction() public function snapshotsAction()
{ {
$uuid = $this->params->get('uuid'); $name = $this->params->get('name');
if ($uuid === null || $uuid === '') { if ($name === null || $name === '') {
$basket = null; $basket = null;
} else { } else {
$uuid = hex2bin($uuid); $basket = Basket::load($name, $this->db());
$basket = Basket::load($uuid, $this->db());
} }
if ($basket === null) { if ($basket === null) {
$this->addTitle($this->translate('Basket Snapshots')); $this->addTitle($this->translate('Basket Snapshots'));
@ -124,11 +122,9 @@ class BasketController extends ActionController
*/ */
public function snapshotAction() public function snapshotAction()
{ {
$hexUuid = $this->params->getRequired('uuid'); $basket = $this->requireBasket();
$binUuid = hex2bin($hexUuid);
$basket = Basket::load($binUuid, $this->db());
$snapshot = BasketSnapshot::load([ $snapshot = BasketSnapshot::load([
'basket_uuid' => $binUuid, 'basket_uuid' => $basket->get('uuid'),
'ts_create' => $this->params->getRequired('ts'), 'ts_create' => $this->params->getRequired('ts'),
], $this->db()); ], $this->db());
$snapSum = bin2hex($snapshot->get('content_checksum')); $snapSum = bin2hex($snapshot->get('content_checksum'));
@ -143,7 +139,7 @@ class BasketController extends ActionController
Link::create( Link::create(
$this->translate('Show Basket'), $this->translate('Show Basket'),
'director/basket', 'director/basket',
['uuid' => $hexUuid], ['name' => $basket->get('basket_name')],
['data-base-target' => '_next'] ['data-base-target' => '_next']
), ),
Link::create( Link::create(
@ -186,7 +182,7 @@ class BasketController extends ActionController
$table->setAttribute('data-base-target', '_next'); $table->setAttribute('data-base-target', '_next');
foreach ($objects as $key => $object) { foreach ($objects as $key => $object) {
$linkParams = [ $linkParams = [
'uuid' => $hexUuid, 'name' => $basket->get('basket_name'),
'checksum' => $this->params->get('checksum'), 'checksum' => $this->params->get('checksum'),
'ts' => $this->params->get('ts'), 'ts' => $this->params->get('ts'),
'type' => $type, 'type' => $type,
@ -238,10 +234,9 @@ class BasketController extends ActionController
*/ */
public function snapshotobjectAction() public function snapshotobjectAction()
{ {
$hexUuid = $this->params->getRequired('uuid'); $basket = $this->requireBasket();
$binUuid = hex2bin($hexUuid);
$snapshot = BasketSnapshot::load([ $snapshot = BasketSnapshot::load([
'basket_uuid' => $binUuid, 'basket_uuid' => $basket->get('uuid'),
'ts_create' => $this->params->getRequired('ts'), 'ts_create' => $this->params->getRequired('ts'),
], $this->db()); ], $this->db());
$snapshotUrl = $this->url()->without('type')->without('key')->setPath('director/basket/snapshot'); $snapshotUrl = $this->url()->without('type')->without('key')->setPath('director/basket/snapshot');
@ -256,7 +251,7 @@ class BasketController extends ActionController
$type, $type,
$key, $key,
Link::create( Link::create(
substr($hexUuid, 0, 7), substr(bin2hex( $snapshot->get('content_checksum')), 0, 7),
$snapshotUrl, $snapshotUrl,
null, null,
['data-base-target' => '_next'] ['data-base-target' => '_next']
@ -301,4 +296,9 @@ class BasketController extends ActionController
)->setHtmlRenderer('Inline') )->setHtmlRenderer('Inline')
); );
} }
protected function requireBasket()
{
return Basket::load($this->params->getRequired('name'), $this->db());
}
} }

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\DirectorObject\Automation;
use Icinga\Module\Director\Core\Json; use Icinga\Module\Director\Core\Json;
use Icinga\Module\Director\Data\Db\DbObject; use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Db;
/** /**
* Class Basket * Class Basket
@ -28,7 +29,7 @@ class Basket extends DbObject
protected $table = 'director_basket'; protected $table = 'director_basket';
protected $keyName = 'uuid'; protected $keyName = 'basket_name';
protected $chosenObjects = []; protected $chosenObjects = [];

View File

@ -31,8 +31,6 @@ class BasketSnapshotTable extends ZfQueryBasedTable
public function renderRow($row) public function renderRow($row)
{ {
$this->splitByDay($row->ts_create_seconds); $this->splitByDay($row->ts_create_seconds);
$hexUuid = bin2hex($row->uuid);
$link = $this->linkToSnapshot($this->renderSummary($row->summary), $row); $link = $this->linkToSnapshot($this->renderSummary($row->summary), $row);
if ($this->basket === null) { if ($this->basket === null) {
@ -41,7 +39,7 @@ class BasketSnapshotTable extends ZfQueryBasedTable
new Link( new Link(
Html::tag('strong', $row->basket_name), Html::tag('strong', $row->basket_name),
'director/basket', 'director/basket',
['uuid' => $hexUuid] ['name' => $row->basket_name]
), ),
Html::tag('br'), Html::tag('br'),
$link, $link,
@ -91,7 +89,7 @@ class BasketSnapshotTable extends ZfQueryBasedTable
return new Link($caption, 'director/basket/snapshot', [ return new Link($caption, 'director/basket/snapshot', [
'checksum' => bin2hex($row->content_checksum), 'checksum' => bin2hex($row->content_checksum),
'ts' => $row->ts_create, 'ts' => $row->ts_create,
'uuid' => bin2hex($row->uuid), 'name' => $row->basket_name,
]); ]);
} }

View File

@ -18,7 +18,7 @@ class BasketTable extends ZfQueryBasedTable
new Link( new Link(
$row->basket_name, $row->basket_name,
'director/basket', 'director/basket',
['uuid' => $hexUuid] ['name' => $row->basket_name]
), ),
$row->cnt_snapshots $row->cnt_snapshots
]); ]);