diff --git a/application/controllers/ImportsourceController.php b/application/controllers/ImportsourceController.php
index 8924bbd2..e826eac0 100644
--- a/application/controllers/ImportsourceController.php
+++ b/application/controllers/ImportsourceController.php
@@ -11,14 +11,50 @@ use Icinga\Web\Url;
class ImportsourceController extends ActionController
{
+ public function indexAction()
+ {
+ $id = $this->params->get('id');
+ $this->prepareTabs($id)->activate('show');
+ $source = $this->view->source = ImportSource::load($id, $this->db());
+ $this->view->title = sprintf(
+ $this->translate('Import source: %s'),
+ $source->source_name
+ );
+
+ $this->view->checkForm = $this
+ ->loadForm('ImportCheck')
+ ->setImportSource($source)
+ ->handleRequest();
+
+ $this->view->runForm = $this
+ ->loadForm('ImportRun')
+ ->setImportSource($source)
+ ->handleRequest();
+ }
+
public function addAction()
{
- $this->indexAction();
+ $this->editAction();
}
public function editAction()
{
- $this->indexAction();
+ $id = $this->params->get('id');
+
+ $form = $this->view->form = $this->loadForm('importSource')->setDb($this->db());
+
+ 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 runAction()
@@ -80,26 +116,6 @@ class ImportsourceController extends ActionController
$this->setViewScript('list/table');
}
- public function indexAction()
- {
- $id = $this->params->get('id');
-
- $form = $this->view->form = $this->loadForm('importSource')->setDb($this->db());
-
- 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 historyAction()
{
$url = $this->getRequest()->getUrl();
@@ -157,9 +173,12 @@ class ImportsourceController extends ActionController
$tabs = $this->getTabs();
if ($id) {
- $tabs->add('edit', array(
- 'url' => 'director/importsource/edit' . '?id=' . $id,
+ $tabs->add('show', array(
+ 'url' => 'director/importsource' . '?id=' . $id,
'label' => $this->translate('Import source'),
+ ))->add('edit', array(
+ 'url' => 'director/importsource/edit' . '?id=' . $id,
+ 'label' => $this->translate('Modify'),
))->add('modifier', array(
'url' => 'director/importsource/modifier' . '?source_id=' . $id,
'label' => $this->translate('Modifiers'),
diff --git a/application/forms/ImportCheckForm.php b/application/forms/ImportCheckForm.php
new file mode 100644
index 00000000..2b00941c
--- /dev/null
+++ b/application/forms/ImportCheckForm.php
@@ -0,0 +1,53 @@
+source = $source;
+ return $this;
+ }
+
+ public function setup()
+ {
+ $this->submitLabel = false;
+ $this->addElement('submit', 'submit', array(
+ 'label' => $this->translate('Check for changes'),
+ 'decorators' => array('ViewHelper')
+ ));
+ }
+
+ public function onSuccess()
+ {
+ $source = $this->source;
+ if ($source->checkForChanges()) {
+ $this->setSuccessMessage(
+ $this->translate('This Import Source provides modified data')
+ );
+
+ } else {
+ $this->setSuccessMessage(
+ $this->translate(
+ 'Nothing to do, data provided by this Import Source'
+ . " didn't change since the last import run"
+ )
+ );
+ }
+
+ if ($source->import_state === 'failing') {
+ $this->addError($this->translate('Checking this Import Source failed'));
+ } else {
+ parent::onSuccess();
+ }
+ }
+}
diff --git a/application/forms/ImportRunForm.php b/application/forms/ImportRunForm.php
new file mode 100644
index 00000000..b3e53a38
--- /dev/null
+++ b/application/forms/ImportRunForm.php
@@ -0,0 +1,53 @@
+source = $source;
+ return $this;
+ }
+
+ public function setup()
+ {
+ $this->submitLabel = false;
+ $this->addElement('submit', 'submit', array(
+ 'label' => $this->translate('Trigger Import Run'),
+ 'decorators' => array('ViewHelper')
+ ));
+ }
+
+ public function onSuccess()
+ {
+ $source = $this->source;
+ if ($source->runImport()) {
+ $this->setSuccessMessage(
+ $this->translate('Imported new data from this Import Source')
+ );
+
+ } else {
+ $this->setSuccessMessage(
+ $this->translate(
+ 'Nothing to do, data provided by this Import Source'
+ . " didn't change since the last import run"
+ )
+ );
+ }
+
+ if ($source->import_state === 'failing') {
+ $this->addError($this->translate('Triggering this Import Source failed'));
+ } else {
+ parent::onSuccess();
+ }
+ }
+}
diff --git a/application/views/scripts/importsource/index.phtml b/application/views/scripts/importsource/index.phtml
new file mode 100644
index 00000000..2e596f06
--- /dev/null
+++ b/application/views/scripts/importsource/index.phtml
@@ -0,0 +1,44 @@
+
+import_state === 'unknown'): ?>
+
= $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.'
+) ?>
+import_state === 'in-sync'): ?>
+
= sprintf(
+ $this->translate(
+ 'This Import Source was last found to by 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
+*/ ?>
+import_state === 'pending-changes'): ?>
+
= $this->translate(
+ 'There are pending changes for this Import Source. You should trigger a new'
+ . ' Import Run.'
+) ?>
+import_state === 'failing'): ?>
+
= 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
+*/ ?>
+
+= $this->checkForm ?>
+= $this->runForm ?>
+
+