diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index f697c27e..b05813ed 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -12,6 +12,8 @@ master (will be 1.6.0) ### User Interface * FIX: link startup log warning even for non-standard package names (#1633) +* FEATURE: allow to filter templates by usage (#1339) +* FEATURE: allow to show SQL used for template tables ### Import and Sync * FEATURE: new Property Modifier allows to extract specific Array values (#473) diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index fe483fae..059b371d 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -181,7 +181,6 @@ abstract class ObjectsController extends ActionController * Loads the TemplatesTable or the TemplateTreeRenderer * * Passing render=tree switches to the tree view. - * @throws \Icinga\Exception\ConfigurationError * @throws \Icinga\Exception\Http\HttpNotFoundException * @throws \Icinga\Security\SecurityException * @throws NotFoundError @@ -210,6 +209,8 @@ abstract class ObjectsController extends ActionController $table = TemplatesTable::create($shortType, $this->db()); $this->eventuallyFilterCommand($table); $table->renderTo($this); + (new AdditionalTableActions($this->getAuth(), $this->url(), $table)) + ->appendTo($this->actions()); } } @@ -223,7 +224,6 @@ abstract class ObjectsController extends ActionController } /** - * @throws \Icinga\Exception\ConfigurationError * @throws \Icinga\Exception\Http\HttpNotFoundException * @throws \Icinga\Security\SecurityException * @throws NotFoundError diff --git a/library/Director/Web/Table/TemplatesTable.php b/library/Director/Web/Table/TemplatesTable.php index 45bb235d..8f94ced0 100644 --- a/library/Director/Web/Table/TemplatesTable.php +++ b/library/Director/Web/Table/TemplatesTable.php @@ -16,7 +16,7 @@ use dipl\Web\Table\ZfQueryBasedTable; use dipl\Web\Url; use Zend_Db_Select as ZfSelect; -class TemplatesTable extends ZfQueryBasedTable +class TemplatesTable extends ZfQueryBasedTable implements FilterableByUsage { use MultiSelect; @@ -96,6 +96,24 @@ class TemplatesTable extends ZfQueryBasedTable return $this; } + public function showOnlyUsed() + { + $type = $this->getType(); + $this->getQuery()->where( + "(EXISTS (SELECT ${type}_id FROM icinga_${type}_inheritance" + . " WHERE parent_${type}_id = o.id))" + ); + } + + public function showOnlyUnUsed() + { + $type = $this->getType(); + $this->getQuery()->where( + "(NOT EXISTS (SELECT ${type}_id FROM icinga_${type}_inheritance" + . " WHERE parent_${type}_id = o.id))" + ); + } + protected function applyRestrictions(ZfSelect $query) { $auth = Auth::getInstance();