AutomationObjectActionBar: add for Importsourc

This commit is contained in:
Thomas Gelf 2018-07-15 16:02:29 +02:00
parent 85d748b295
commit ac1ba20ab7
3 changed files with 85 additions and 43 deletions

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Forms\ImportRowModifierForm;
use Icinga\Module\Director\Forms\ImportSourceForm;
use Icinga\Module\Director\Web\ActionBar\AutomationObjectActionBar;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Objects\ImportSource;
use Icinga\Module\Director\Web\Form\CloneImportSourceForm;
@ -34,6 +35,13 @@ class ImportsourceController extends ActionController
}
}
protected function addMainActions()
{
$this->actions(new AutomationObjectActionBar(
$this->getRequest()
));
}
/**
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\IcingaException
@ -42,6 +50,7 @@ class ImportsourceController extends ActionController
*/
public function indexAction()
{
$this->addMainActions();
$source = ImportSource::load($this->params->getRequired('id'), $this->db());
if ($this->params->get('format') === 'json') {
$this->sendJson($this->getResponse(), $source->export());
@ -51,17 +60,6 @@ class ImportsourceController extends ActionController
$this->translate('Import source: %s'),
$source->get('source_name')
)->setAutorefreshInterval(10);
$this->actions()->add(
Link::create(
$this->translate('Download JSON'),
$this->url()->with('format', 'json'),
null,
[
'data-base-target' => '_blank',
]
)
);
$this->content()->add(new ImportSourceDetails($source));
}
@ -84,19 +82,13 @@ class ImportsourceController extends ActionController
*/
public function editAction()
{
$this->addMainActions();
$this->tabs()->activateMainWithPostfix($this->translate('Modify'));
$id = $this->params->getRequired('id');
$form = ImportSourceForm::load()->setDb($this->db())
->loadObject($id)
->setListUrl('director/importsources')
->handleRequest();
$this->actions()->add(
Link::create(
$this->translate('Clone'),
'director/importsource/clone',
['id' => $id],
['class' => 'icon-paste']
)
);
$this->addTitle(
$this->translate('Import source: %s'),
$form->getObject()->get('source_name')
@ -107,34 +99,16 @@ class ImportsourceController extends ActionController
/**
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\Http\HttpNotFoundException
* @throws \Icinga\Exception\MissingParameterException
* @throws \Icinga\Exception\NotFoundError
* @throws \Icinga\Exception\ProgrammingError
*/
public function cloneAction()
{
$this->addMainActions();
$this->tabs()->activateMainWithPostfix($this->translate('Clone'));
$id = $this->params->getRequired('id');
$source = ImportSource::load($id, $this->db());
$this->tabs()->add('show', [
'url' => 'director/importsource',
'urlParams' => ['id' => $id],
'label' => $this->translate('Import Source'),
])->add('clone', [
'url' => 'director/importsource/clone',
'urlParams' => ['id' => $id],
'label' => $this->translate('Clone'),
])->activate('clone');
$this->addTitle('Clone: %s', $source->get('source_name'));
$this->actions()->add(
Link::create(
$this->translate('Modify'),
'director/importsource/edit',
['id' => $source->get('id')],
['class' => 'icon-paste']
)
);
$form = new CloneImportSourceForm($source);
$this->content()->add($form);
$form->handleRequest($this->getRequest());

View File

@ -0,0 +1,62 @@
<?php
namespace Icinga\Module\Director\Web\ActionBar;
use dipl\Html\Link;
use dipl\Translation\TranslationHelper;
use dipl\Web\Widget\ActionBar;
use Icinga\Web\Request;
class AutomationObjectActionBar extends ActionBar
{
use TranslationHelper;
/** @var Request */
protected $request;
protected $label;
public function __construct(Request $request)
{
$this->request = $request;
}
protected function assemble()
{
$request = $this->request;
$action = $request->getActionName();
$controller = $request->getControllerName();
$params = ['id' => $request->getParam('id')];
$links = [
'index' => Link::create(
$this->translate('Overview'),
"director/$controller",
$params,
['class' => 'icon-info']
),
'edit' => Link::create(
$this->translate('Modify'),
"director/$controller/edit",
$params,
['class' => 'icon-edit']
),
'clone' => Link::create(
$this->translate('Clone'),
"director/$controller/clone",
$params,
['class' => 'icon-paste']
),
'export' => Link::create(
$this->translate('Download JSON'),
$this->request->getUrl()->with('format', 'json'),
null,
[
'data-base-target' => '_blank',
]
)
];
unset($links[$action]);
$this->add($links);
}
}

View File

@ -17,6 +17,16 @@ class ImportsourceTabs extends Tabs
$this->assemble();
}
public function activateMainWithPostfix($postfix)
{
$mainTab = 'index';
$tab = $this->get($mainTab);
$tab->setLabel($tab->getLabel() . ": $postfix");
$this->activate($mainTab);
return $this;
}
protected function assemble()
{
if ($id = $this->id) {
@ -25,10 +35,6 @@ class ImportsourceTabs extends Tabs
'url' => 'director/importsource',
'urlParams' => $params,
'label' => $this->translate('Import source'),
])->add('edit', [
'url' => 'director/importsource/edit',
'urlParams' => $params,
'label' => $this->translate('Modify'),
])->add('modifier', [
'url' => 'director/importsource/modifier',
'urlParams' => ['source_id' => $id],