From 0f3f2f05df72095c7a9453a86560fe0c38589ec3 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 20 Aug 2017 16:03:49 +0200 Subject: [PATCH] PropertymodifierTable: allow to manually switch... ...execution order (priority) --- .../controllers/ImportsourceController.php | 4 +- .../Web/Table/PropertymodifierTable.php | 57 +++++++++++++++---- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/application/controllers/ImportsourceController.php b/application/controllers/ImportsourceController.php index fb111d0e..17514771 100644 --- a/application/controllers/ImportsourceController.php +++ b/application/controllers/ImportsourceController.php @@ -73,7 +73,9 @@ class ImportsourceController extends ActionController protected function requireImportSourceAndAddModifierTable() { $source = ImportSource::load($this->params->getRequired('source_id'), $this->db()); - PropertymodifierTable::load($source)->renderTo($this); + PropertymodifierTable::load($source, $this->url()) + ->handleSortPriorityActions($this->getRequest(), $this->getResponse()) + ->renderTo($this); return $source; } diff --git a/library/Director/Web/Table/PropertymodifierTable.php b/library/Director/Web/Table/PropertymodifierTable.php index 5d324482..c5b955f2 100644 --- a/library/Director/Web/Table/PropertymodifierTable.php +++ b/library/Director/Web/Table/PropertymodifierTable.php @@ -2,22 +2,46 @@ namespace Icinga\Module\Director\Web\Table; +use Exception; +use Icinga\Module\Director\Hook\ImportSourceHook; use Icinga\Module\Director\Objects\ImportSource; use ipl\Html\Link; +use ipl\Web\Table\Extension\ZfSortablePriority; use ipl\Web\Table\ZfQueryBasedTable; +use ipl\Web\Url; class PropertymodifierTable extends ZfQueryBasedTable { + use ZfSortablePriority; + + protected $searchColumns = [ + 'property_name', + 'target_property', + ]; + /** @var ImportSource */ protected $source; - public static function load(ImportSource $source) + /** @var Url */ + protected $url; + + protected $keyColumn = 'id'; + + protected $priorityColumn = 'priority'; + + public static function load(ImportSource $source, Url $url) { $table = new static($source->getConnection()); $table->source = $source; + $table->url = $url; return $table; } + public function render() + { + return $this->renderWithSortableForm(); + } + protected function assemble() { $this->attributes()->set('data-base-target', '_self'); @@ -42,26 +66,39 @@ class PropertymodifierTable extends ZfQueryBasedTable if ($row->target_property !== null) { $caption .= ' -> ' . $row->target_property; } - if ($row->description !== null) { + if ($row->description === null) { + $class = $row->provider_class; + try { + /** @var ImportSourceHook $hook */ + $hook = new $class; + $caption .= ': ' . $hook->getName(); + } catch (Exception $e) { + $caption = [ + $caption, + ': ', + $this::tag('span', ['class' => 'error'], $e->getMessage()) + ]; + } + } else { $caption .= ': ' . $row->description; } - return $this::row([ - Link::create( - $caption, - 'director/importsource/editmodifier', - [ + return $this->addSortPriorityButtons( + $this::row([ + Link::create($caption, 'director/importsource/editmodifier', [ 'id' => $row->id, 'source_id' => $row->source_id, - ] - ) - ]); + ]), + ]), + $row + ); } public function getColumnsToBeRendered() { return [ $this->translate('Property'), + $this->getSortPriorityTitle() ]; }