mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-25 18:59:05 +02:00
ImportsourceController: completely refactor, get
...rid of view scripts
This commit is contained in:
parent
d5ccb1edb5
commit
a4d138354b
@ -2,184 +2,149 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Controllers;
|
namespace Icinga\Module\Director\Controllers;
|
||||||
|
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Module\Director\Forms\ImportRowModifierForm;
|
||||||
|
use Icinga\Module\Director\Forms\ImportSourceForm;
|
||||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||||
use Icinga\Module\Director\Objects\ImportSource;
|
use Icinga\Module\Director\Objects\ImportSource;
|
||||||
use Icinga\Module\Director\Import\Import;
|
use Icinga\Module\Director\Web\Table\ImportrunTable;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Module\Director\Web\Table\ImportsourceHookTable;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Module\Director\Web\Table\PropertymodifierTable;
|
||||||
|
use Icinga\Module\Director\Web\Tabs\ImportsourceTabs;
|
||||||
|
use Icinga\Module\Director\Web\Widget\ImportSourceDetails;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
|
||||||
class ImportsourceController extends ActionController
|
class ImportsourceController extends ActionController
|
||||||
{
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
$id = $this->params->get('source_id', $this->params->get('id'));
|
||||||
|
$tabs = $this->tabs(new ImportsourceTabs($id));
|
||||||
|
$action = $this->getRequest()->getActionName();
|
||||||
|
if ($tabs->has($action)) {
|
||||||
|
$tabs->activate($action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
$this->setAutorefreshInterval(10);
|
$source = ImportSource::load($this->params->getRequired('id'), $this->db());
|
||||||
$id = $this->params->get('id');
|
$this->addTitle(
|
||||||
$this->prepareTabs($id)->activate('show');
|
|
||||||
$source = $this->view->source = ImportSource::load($id, $this->db());
|
|
||||||
$this->view->title = sprintf(
|
|
||||||
$this->translate('Import source: %s'),
|
$this->translate('Import source: %s'),
|
||||||
$source->source_name
|
$source->get('source_name')
|
||||||
);
|
)->setAutorefreshInterval(10);
|
||||||
|
|
||||||
$this->view->checkForm = $this
|
$this->content()->add(new ImportSourceDetails($source));
|
||||||
->loadForm('ImportCheck')
|
|
||||||
->setImportSource($source)
|
|
||||||
->handleRequest();
|
|
||||||
|
|
||||||
$this->view->runForm = $this
|
|
||||||
->loadForm('ImportRun')
|
|
||||||
->setImportSource($source)
|
|
||||||
->handleRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAction()
|
public function addAction()
|
||||||
{
|
{
|
||||||
$this->editAction();
|
$this->addTitle($this->translate('Add import source'))
|
||||||
|
->content()->add(
|
||||||
|
ImportSourceForm::load()->setDb($this->db())
|
||||||
|
->setSuccessUrl('director/importsources')
|
||||||
|
->handleRequest()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function editAction()
|
public function editAction()
|
||||||
{
|
{
|
||||||
$id = $this->params->get('id');
|
$form = ImportSourceForm::load()->setDb($this->db())
|
||||||
|
->loadObject($this->params->getRequired('id'))
|
||||||
|
->setListUrl('director/importsources')
|
||||||
|
->handleRequest();
|
||||||
|
|
||||||
$form = $this->view->form = $this->loadForm('importSource')->setDb($this->db());
|
$this->content()->add($form);
|
||||||
|
|
||||||
if ($id) {
|
|
||||||
$form->loadObject($id)->setListUrl('director/list/importsource');
|
|
||||||
$this->prepareTabs($id)->activate('edit');
|
|
||||||
$this->view->title = $this->translate('Edit import source');
|
|
||||||
} else {
|
|
||||||
$form->setSuccessUrl('director/list/importsource');
|
|
||||||
$this->view->title = $this->translate('Add import source');
|
|
||||||
$this->prepareTabs()->activate('add');
|
|
||||||
}
|
|
||||||
|
|
||||||
$form->handleRequest();
|
|
||||||
$this->setViewScript('object/form');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function previewAction()
|
public function previewAction()
|
||||||
{
|
{
|
||||||
$id = $this->params->get('id');
|
$source = ImportSource::load($this->params->getRequired('id'), $this->db());
|
||||||
|
|
||||||
$source = ImportSource::load($id, $this->db());
|
$this->addTitle(
|
||||||
$this->prepareTabs($id)->activate('preview');
|
|
||||||
|
|
||||||
$this->view->title = sprintf(
|
|
||||||
$this->translate('Import source preview: "%s"'),
|
$this->translate('Import source preview: "%s"'),
|
||||||
$source->source_name
|
$source->get('source_name')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->view->table = $this->applyPaginationLimits(
|
(new ImportsourceHookTable())->setImportSource($source)->renderTo($this);
|
||||||
$this->loadTable('importsourceHook')
|
}
|
||||||
->setConnection($this->db())
|
|
||||||
->setImportSource($source)
|
protected function requireImportSourceAndAddModifierTable()
|
||||||
);
|
{
|
||||||
$this->setViewScript('list/table');
|
$source = ImportSource::load($this->params->getRequired('source_id'), $this->db());
|
||||||
|
PropertymodifierTable::load($source)->renderTo($this);
|
||||||
|
return $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function modifierAction()
|
public function modifierAction()
|
||||||
{
|
{
|
||||||
$this->view->stayHere = true;
|
$source = $this->requireImportSourceAndAddModifierTable();
|
||||||
$id = $this->params->get('source_id');
|
$this->addAddLink(
|
||||||
$this->prepareTabs($id)->activate('modifier');
|
|
||||||
|
|
||||||
$this->view->addLink = $this->view->qlink(
|
|
||||||
$this->translate('Add property modifier'),
|
$this->translate('Add property modifier'),
|
||||||
'director/importsource/addmodifier',
|
'director/importsource/addmodifier',
|
||||||
array('source_id' => $id),
|
['source_id' => $source->getId()],
|
||||||
array('class' => 'icon-plus')
|
'_self'
|
||||||
);
|
)->addTitle($this->translate('Property modifiers'));
|
||||||
|
|
||||||
$this->view->title = $this->translate('Property modifiers');
|
|
||||||
$this->view->table = $this->loadTable('propertymodifier')
|
|
||||||
->enforceFilter(Filter::where('source_id', $id))
|
|
||||||
->setConnection($this->db());
|
|
||||||
$this->setViewScript('list/table');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function historyAction()
|
public function historyAction()
|
||||||
{
|
{
|
||||||
$url = $this->getRequest()->getUrl();
|
$source = ImportSource::load($this->params->getRequired('id'), $this->db());
|
||||||
$id = $url->shift('id');
|
$this->addTitle($this->translate('Import run history'));
|
||||||
if ($url->shift('action') === 'remove') {
|
|
||||||
$this->view->form = $this->loadForm('removeImportrun');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->prepareTabs($id)->activate('history');
|
|
||||||
$this->view->title = $this->translate('Import run history');
|
|
||||||
|
|
||||||
// TODO: temporarily disabled, find a better place for stats:
|
// TODO: temporarily disabled, find a better place for stats:
|
||||||
// $this->view->stats = $this->db()->fetchImportStatistics();
|
// $this->view->stats = $this->db()->fetchImportStatistics();
|
||||||
$this->prepareTable('importrun');
|
ImportrunTable::load($source)->renderTo($this);
|
||||||
$this->view->table->enforceFilter(Filter::where('source_id', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function editmodifierAction()
|
|
||||||
{
|
|
||||||
$this->addmodifierAction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addmodifierAction()
|
public function addmodifierAction()
|
||||||
{
|
{
|
||||||
$this->view->stayHere = true;
|
$source = $this->requireImportSourceAndAddModifierTable();
|
||||||
$edit = false;
|
$this->addTitle(
|
||||||
|
$this->translate('%s: add Property Modifier'),
|
||||||
|
$source->get('source_name')
|
||||||
|
)->addBackToModifiersLink($source);
|
||||||
|
$this->tabs()->activate('modifier');
|
||||||
|
|
||||||
if ($id = $this->params->get('id')) {
|
$this->content()->prepend(
|
||||||
$edit = true;
|
ImportRowModifierForm::load()->setDb($this->db())
|
||||||
}
|
->setSource($source)
|
||||||
|
->setSuccessUrl(
|
||||||
$form = $this->view->form = $this->loadForm('importRowModifier')->setDb($this->db());
|
'director/importsource/modifier',
|
||||||
|
['source_id' => $source->getId()]
|
||||||
if ($edit) {
|
)->handleRequest()
|
||||||
$form->loadObject($id);
|
);
|
||||||
$source_id = $form->getObject()->source_id;
|
|
||||||
$form->setSource(ImportSource::load($source_id, $this->db()));
|
|
||||||
} elseif ($source_id = $this->params->get('source_id')) {
|
|
||||||
$form->setSource(ImportSource::load($source_id, $this->db()));
|
|
||||||
}
|
|
||||||
$form->setSuccessUrl('director/importsource/modifier', array('source_id' => $source_id));
|
|
||||||
|
|
||||||
$form->handleRequest();
|
|
||||||
|
|
||||||
$tabs = $this->prepareTabs($source_id)->activate('modifier');
|
|
||||||
|
|
||||||
$this->view->title = $this->translate('Modifier'); // add/edit
|
|
||||||
$this->view->table = $this->loadTable('propertymodifier')
|
|
||||||
->enforceFilter(Filter::where('source_id', $source_id))
|
|
||||||
->setConnection($this->db());
|
|
||||||
|
|
||||||
$this->setViewScript('list/table');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function prepareTabs($id = null)
|
public function editmodifierAction()
|
||||||
{
|
{
|
||||||
$tabs = $this->getTabs();
|
$source = $this->requireImportSourceAndAddModifierTable();
|
||||||
|
$this->addTitle(
|
||||||
|
$this->translate('%s: Property Modifier'),
|
||||||
|
$source->get('source_name')
|
||||||
|
)->addBackToModifiersLink($source);
|
||||||
|
$this->tabs()->activate('modifier');
|
||||||
|
|
||||||
if ($id) {
|
$this->content()->prepend(
|
||||||
$tabs->add('show', array(
|
ImportRowModifierForm::load()->setDb($this->db())
|
||||||
'url' => 'director/importsource' . '?id=' . $id,
|
->loadObject($this->params->getRequired('id'))
|
||||||
'label' => $this->translate('Import source'),
|
->setSource($source)
|
||||||
))->add('edit', array(
|
->handleRequest()
|
||||||
'url' => 'director/importsource/edit' . '?id=' . $id,
|
);
|
||||||
'label' => $this->translate('Modify'),
|
}
|
||||||
))->add('modifier', array(
|
|
||||||
'url' => 'director/importsource/modifier' . '?source_id=' . $id,
|
|
||||||
'label' => $this->translate('Modifiers'),
|
|
||||||
))->add('history', array(
|
|
||||||
'url' => 'director/importsource/history' . '?id=' . $id,
|
|
||||||
'label' => $this->translate('History'),
|
|
||||||
))->add('preview', array(
|
|
||||||
'url' => 'director/importsource/preview' . '?id=' . $id,
|
|
||||||
'label' => $this->translate('Preview'),
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$tabs->add('add', array(
|
|
||||||
'url' => 'director/importsource/add',
|
|
||||||
'label' => $this->translate('New import source'),
|
|
||||||
))->activate('add');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $tabs;
|
protected function addBackToModifiersLink(ImportSource $source)
|
||||||
|
{
|
||||||
|
$this->actions()->add(
|
||||||
|
Link::create(
|
||||||
|
$this->translate('back'),
|
||||||
|
'director/importsource/modifier',
|
||||||
|
['source_id' => $source->getId()],
|
||||||
|
['class' => 'icon-left-big']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<div class="controls">
|
|
||||||
<?= $this->tabs ?>
|
|
||||||
<h1><?= $this->escape($this->title) ?></h1>
|
|
||||||
<span class="action-links"<?php if (! $this->stayHere): ?> data-base-target="_next"<?php endif ?>>
|
|
||||||
<?= $this->addLink ?>
|
|
||||||
</span>
|
|
||||||
<?= $this->filterEditor ?>
|
|
||||||
<?= $this->table->getPaginator() ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="content"<?php if (! $this->stayHere): ?> data-base-target="_next"<?php endif ?>>
|
|
||||||
<?= $this->form ?>
|
|
||||||
<?php if ($table->count()): ?>
|
|
||||||
<?= $this->table->render() ?>
|
|
||||||
<?php endif ?>
|
|
||||||
</div>
|
|
@ -1,16 +0,0 @@
|
|||||||
<div class="controls">
|
|
||||||
<?= $this->tabs ?>
|
|
||||||
<h1><?= $this->escape($this->title) ?></h1>
|
|
||||||
<span class="action-links"<?php if (! $this->stayHere): ?> data-base-target="_next"<?php endif ?>>
|
|
||||||
<?= $this->addLink ?>
|
|
||||||
</span>
|
|
||||||
<?= $this->filterEditor ?>
|
|
||||||
<?= $this->table->getPaginator() ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="content"<?php if (! $this->stayHere): ?> data-base-target="_next"<?php endif ?>>
|
|
||||||
<?= $this->form ?>
|
|
||||||
<?php if ($table->count()): ?>
|
|
||||||
<?= $this->table->render() ?>
|
|
||||||
<?php endif ?>
|
|
||||||
</div>
|
|
@ -1,45 +0,0 @@
|
|||||||
<div class="controls">
|
|
||||||
<?= $this->tabs ?>
|
|
||||||
<h1><?= $this->escape($this->title) ?></h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="content">
|
|
||||||
<p><?= $this->escape($source->description) ?></p>
|
|
||||||
<?php if ($source->import_state === 'unknown'): ?>
|
|
||||||
<p><?= $this->translate(
|
|
||||||
"It's currently unknown whether we are in sync with this Import Source."
|
|
||||||
. ' You should either check for changes or trigger a new Import Run.'
|
|
||||||
) ?></p>
|
|
||||||
<?php elseif ($source->import_state === 'in-sync'): ?>
|
|
||||||
<p><?= sprintf(
|
|
||||||
$this->translate(
|
|
||||||
'This Import Source was last found to be in sync at %s.'
|
|
||||||
),
|
|
||||||
$source->last_attempt
|
|
||||||
) /*
|
|
||||||
TODO: check whether...
|
|
||||||
- there have been imports since then, differing from former ones
|
|
||||||
- there have been activities since then
|
|
||||||
*/ ?></p>
|
|
||||||
<?php elseif ($source->import_state === 'pending-changes'): ?>
|
|
||||||
<p class="warning"><?= $this->translate(
|
|
||||||
'There are pending changes for this Import Source. You should trigger a new'
|
|
||||||
. ' Import Run.'
|
|
||||||
) ?></p>
|
|
||||||
<?php elseif ($source->import_state === 'failing'): ?>
|
|
||||||
<p class="error"><?= sprintf(
|
|
||||||
$this->translate(
|
|
||||||
'This Import Source failed when last checked at %s: %s'
|
|
||||||
),
|
|
||||||
$source->last_attempt,
|
|
||||||
$source->last_error_message
|
|
||||||
) /*
|
|
||||||
TODO: check whether...
|
|
||||||
- there have been imports since then, differing from former ones
|
|
||||||
- there have been activities since then
|
|
||||||
*/ ?></p>
|
|
||||||
<?php endif ?>
|
|
||||||
<?= $this->checkForm ?>
|
|
||||||
<?= $this->runForm ?>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,38 +0,0 @@
|
|||||||
<div class="controls">
|
|
||||||
<?= $this->tabs ?>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$loc = localeconv();
|
|
||||||
$pt = $loc['thousands_sep'];
|
|
||||||
|
|
||||||
?><h1><?= $this->escape($this->title) ?></h1>
|
|
||||||
<table class="tinystats">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th>Rows</th>
|
|
||||||
<th>Props</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th>Imported</th>
|
|
||||||
<td><?= number_format($this->stats['imported_rows'], 0, null, $pt) ?></td>
|
|
||||||
<td><?= number_format($this->stats['imported_properties'], 0, null, $pt) ?></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>Unique</th>
|
|
||||||
<td><?= number_format($this->stats['unique_rows'], 0, null, $pt) ?></td>
|
|
||||||
<td><?= number_format($this->stats['unique_properties'], 0, null, $pt) ?></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<span class="action-links" data-base-target="_next">
|
|
||||||
<?= $this->addLink ?>
|
|
||||||
</span><br />
|
|
||||||
<?= $this->table->getPaginator() ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="content" data-base-target="_next">
|
|
||||||
<?= $this->table->render() ?>
|
|
||||||
</div>
|
|
Loading…
x
Reference in New Issue
Block a user