[icinga-checkins] icinga.org: icingaweb2-module-director/master: object: show pending changes, offer deployment

git at icinga.org git at icinga.org
Sat Feb 27 12:23:17 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: a41f1466799d7ab3d63295d423ed1432f3e9ecf3
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=a41f1466799d7ab3d63295d423ed1432f3e9ecf3

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sat Feb 27 12:23:00 2016 +0100

object: show pending changes, offer deployment

---

 .../views/scripts/object/deploymentLink.phtml      |   31 ++++++++++++++++++++
 application/views/scripts/object/form.phtml        |    1 +
 .../Director/Web/Controller/ObjectController.php   |   13 ++++++++
 3 files changed, 45 insertions(+)

diff --git a/application/views/scripts/object/deploymentLink.phtml b/application/views/scripts/object/deploymentLink.phtml
new file mode 100644
index 0000000..00a3c5d
--- /dev/null
+++ b/application/views/scripts/object/deploymentLink.phtml
@@ -0,0 +1,31 @@
+<?php
+
+if (! $this->undeployedChanges) {
+    return; 
+}
+
+if ($this->totalUndeployedChanges === 1) {
+    $msg = $this->translate('There has been a single change to this object, nothing else has been modified');
+} elseif ($this->totalUndeployedChanges === $this->undeployedChanges) {
+    $msg = sprintf(
+        $this->translate('There have been %d changes to this object, nothing else has been modified'),
+        $this->undeployedChanges
+    );
+} else {
+    $msg = sprintf(
+        $this->translate('There are %d pending changes, %d of them applied to this object'),
+        $this->totalUndeployedChanges,
+        $this->undeployedChanges
+    );
+}
+
+echo ' ' . $this->qlink(
+    $this->translate('Deploy'),
+    'director/config/deploy',
+    null,
+    array(
+        'title' => $msg,
+        'class' => 'icon-wrench state-critical'
+    )
+);
+
diff --git a/application/views/scripts/object/form.phtml b/application/views/scripts/object/form.phtml
index 1138286..e697c04 100644
--- a/application/views/scripts/object/form.phtml
+++ b/application/views/scripts/object/form.phtml
@@ -3,6 +3,7 @@
 <h1><?= $this->escape($this->title) ?></h1>
 <span>
 <?= $this->actionLinks ?>
+<?= $this->render('object/deploymentLink.phtml') ?>
 </span>
 </div>
 
diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php
index 867018f..b92d7de 100644
--- a/library/Director/Web/Controller/ObjectController.php
+++ b/library/Director/Web/Controller/ObjectController.php
@@ -225,6 +225,10 @@ abstract class ObjectController extends ActionController
                 $name,
                 $this->db()
             );
+
+            $this->view->undeployedChanges = $this->countUndeployedChanges();
+            $this->view->totalUndeployedChanges = $this->db()
+                ->countActivitiesSinceLastDeployedConfig();
         }
 
         return $this->object;
@@ -298,6 +302,15 @@ abstract class ObjectController extends ActionController
         }
     }
 
+    protected function countUndeployedChanges()
+    {
+        if ($this->object === null) {
+            return 0;
+        }
+
+        return $this->db()->countActivitiesSinceLastDeployedConfig($this->object);
+    }
+
     protected function requireObject()
     {
         if (! $this->object) {



More information about the icinga-checkins mailing list