From b77f71f22a3f668d52ee47e526c479eea40a16d4 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 24 Jun 2016 08:40:18 +0200 Subject: [PATCH] SyncruleController: add summary tab, reordered --- .../controllers/SyncruleController.php | 99 ++++++++++++------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/application/controllers/SyncruleController.php b/application/controllers/SyncruleController.php index c0e33ea7..a149d563 100644 --- a/application/controllers/SyncruleController.php +++ b/application/controllers/SyncruleController.php @@ -12,14 +12,49 @@ use Icinga\Web\Url; class SyncruleController extends ActionController { + public function indexAction() + { + $id = $this->params->get('id'); + $this->prepareRuleTabs($id)->activate('show'); + $rule = $this->view->rule = SyncRule::load($id, $this->db()); + $this->view->title = sprintf( + $this->translate('Sync rule: %s'), + $rule->rule_name + ); + + if ($lastRunId = $rule->getLastSyncRunId()) { + $this->loadSyncRun($lastRunId); + + } else { + $this->view->run = null; + } + } + public function addAction() { - $this->indexAction(); + $this->editAction(); } public function editAction() { - $this->indexAction(); + $form = $this->view->form = $this->loadForm('syncRule') + ->setSuccessUrl('director/list/syncrule') + ->setDb($this->db()); + + if ($id = $this->params->get('id')) { + $this->prepareRuleTabs($id)->activate('edit'); + $form->loadObject($id); + $this->view->title = sprintf( + $this->translate('Sync rule: %s'), + $form->getObject()->rule_name + ); + } else { + $this->view->title = $this->translate('Add sync rule'); + $this->prepareRuleTabs()->activate('add'); + } + + $form->handleRequest(); + $this->setViewScript('object/form'); } public function runAction() @@ -44,28 +79,6 @@ class SyncruleController extends ActionController } } - public function indexAction() - { - $form = $this->view->form = $this->loadForm('syncRule') - ->setSuccessUrl('director/list/syncrule') - ->setDb($this->db()); - - if ($id = $this->params->get('id')) { - $this->prepareRuleTabs($id)->activate('edit'); - $form->loadObject($id); - $this->view->title = sprintf( - $this->translate('Sync rule: %s'), - $form->getObject()->rule_name - ); - } else { - $this->view->title = $this->translate('Add sync rule'); - $this->prepareRuleTabs()->activate('add'); - } - - $form->handleRequest(); - $this->setViewScript('object/form'); - } - public function propertyAction() { $this->view->stayHere = true; @@ -164,35 +177,49 @@ class SyncruleController extends ActionController ->setConnection($this->db()); if ($runId = $this->params->get('run_id')) { - $this->view->run = SyncRun::load($runId, $db); - if ($this->view->run->last_former_activity !== null) { - $this->view->formerId = $db->fetchActivityLogIdByChecksum( - $this->view->run->last_former_activity - ); + $this->loadSyncRun($runId); + } + } - $this->view->lastId = $db->fetchActivityLogIdByChecksum( - $this->view->run->last_related_activity - ); - } + protected function loadSyncRun($id) + { + $db = $this->db(); + $this->view->run = SyncRun::load($id, $db); + if ($this->view->run->last_former_activity !== null) { + $this->view->formerId = $db->fetchActivityLogIdByChecksum( + $this->view->run->last_former_activity + ); + + $this->view->lastId = $db->fetchActivityLogIdByChecksum( + $this->view->run->last_related_activity + ); } } protected function prepareRuleTabs($ruleId = null) { if ($ruleId) { - return $this->getTabs()->add('edit', array( - 'url' => 'director/syncrule/edit', + $tabs = $this->getTabs()->add('show', array( + 'url' => 'director/syncrule', 'urlParams' => array('id' => $ruleId), 'label' => $this->translate('Sync rule'), + ))->add('edit', array( + 'url' => 'director/syncrule/edit', + 'urlParams' => array('id' => $ruleId), + 'label' => $this->translate('Modify'), ))->add('property', array( 'label' => $this->translate('Properties'), 'url' => 'director/syncrule/property', 'urlParams' => array('rule_id' => $ruleId) - ))->add('history', array( + )); + + $tabs->add('history', array( 'label' => $this->translate('History'), 'url' => 'director/syncrule/history', 'urlParams' => array('id' => $ruleId) )); + + return $tabs; } else { return $this->getTabs()->add('add', array( 'url' => 'director/syncrule/add',