[icinga-checkins] icinga.org: icinga-web/master: * cleaned js of status map

git at icinga.org git at icinga.org
Fri Oct 23 12:01:37 CEST 2009


Module: icinga-web
Branch: master
Commit: b83a8a0109c7b5c119583faabf7cfee866d8c2d3
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=b83a8a0109c7b5c119583faabf7cfee866d8c2d3

Author: Christian Doebler <christian.doebler at netways.de>
Date:   Thu Oct 22 16:32:30 2009 +0200

* cleaned js of status map
* added test style for nodes in status map
* added js cronkTrigger to generate cronks by using anchors or other tags
* added link to host cronk to status map

---

 app/config/icinga.xml                              |    1 +
 .../Cronks/models/System/StatusMapModel.class.php  |   19 +++++--
 .../Cronks/templates/System/StatusMapSuccess.php   |    1 +
 .../Cronks/templates/System/js/CronkTrigger.js     |   58 ++++++++++++++++++++
 .../Cronks/templates/System/js/JitStatusMap.js     |    7 ++-
 pub/styles/Icinga.css                              |    4 ++
 6 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/app/config/icinga.xml b/app/config/icinga.xml
index c66aeb4..ec96c1c 100644
--- a/app/config/icinga.xml
+++ b/app/config/icinga.xml
@@ -194,6 +194,7 @@
 	-->
 	<setting name="appkit.include_dynamic_javascript">
 		<parameter name="AppKit.Ext.grid.IcingaColumnRenderer">%core.module_dir%/Cronks/templates/System/ViewProc/js/IcingaColumnRenderer.js</parameter>
+		<parameter name="Cronks.CronkTrigger">%core.module_dir%/Cronks/templates/System/js/CronkTrigger.js</parameter>
 		<parameter name="Cronks.JitStatusMap">%core.module_dir%/Cronks/templates/System/js/JitStatusMap.js</parameter>
 		<parameter name="Cronks.JitExCanvas">%core.root_dir%/lib/jit/Extras/excanvas.js</parameter>
 	</setting>
diff --git a/app/modules/Cronks/models/System/StatusMapModel.class.php b/app/modules/Cronks/models/System/StatusMapModel.class.php
index 851e079..313c525 100644
--- a/app/modules/Cronks/models/System/StatusMapModel.class.php
+++ b/app/modules/Cronks/models/System/StatusMapModel.class.php
@@ -15,6 +15,10 @@ class Cronks_System_StatusMapModel extends ICINGACronksBaseModel
 		'HOST_IS_FLAPPING', 'HOST_SCHEDULED_DOWNTIME_DEPTH', 'HOST_STATUS_UPDATE_TIME'
 	);
 
+	private $scriptTemplate = '<a href="#" onclick="return CronkTrigger({objectId:%s,objectName:\'%s\',objectType:\'host\'});">%s</a>';
+	private $tableRowTemplate = '<tr><td>%s</td><td>%s</td></tr>';
+	private $tableTemplate = '<table>%s</table>';
+
 	/**
 	 * class constructor
 	 * @return	Cronks_System_StatusMapModel			class object
@@ -122,16 +126,23 @@ class Cronks_System_StatusMapModel extends ICINGACronksBaseModel
 	 */
 	private function getHostDataTable ($hostData) {
 		$hostTable = null;
+		$hostObjectId = false;
 		foreach ($hostData as $key => $value) {
 			if ($key == 'host_object_id') {
+				$hostObjectId = $value;
 				continue;
 			}
-			if ($key == 'host_current_state') {
-				$value = IcingaHostStateInfo::Create($value)->getCurrentStateAsText();
+			switch ($key) {
+				case 'host_current_state':
+					$value = IcingaHostStateInfo::Create($value)->getCurrentStateAsText();
+					break;
+				case 'host_name':
+					$value = sprintf($this->scriptTemplate, $hostObjectId, $value, $value);
+					break;
 			}
-			$hostTable .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $this->tm->_($key), $value);
+			$hostTable .= sprintf($this->tableRowTemplate, $this->tm->_($key), $value);
 		}
-		$hostTable = '<table>' . $hostTable . '</table>';
+		$hostTable = sprintf($this->tableTemplate, $hostTable);
 		return $hostTable;
 	}
 
diff --git a/app/modules/Cronks/templates/System/StatusMapSuccess.php b/app/modules/Cronks/templates/System/StatusMapSuccess.php
index 14aae8a..b7f197d 100644
--- a/app/modules/Cronks/templates/System/StatusMapSuccess.php
+++ b/app/modules/Cronks/templates/System/StatusMapSuccess.php
@@ -22,5 +22,6 @@ if (Ext.isIE) {
 	AppKit.Ext.ScriptDynaLoader.loadScript("<?php echo $ro->gen('appkit.ext.dynamicScriptSource', array('script' => 'Cronks.JitExCanvas')) ?>");
 }
 
+AppKit.Ext.ScriptDynaLoader.loadScript("<?php echo $ro->gen('appkit.ext.dynamicScriptSource', array('script' => 'Cronks.CronkTrigger')) ?>");
 AppKit.Ext.ScriptDynaLoader.loadScript("<?php echo $ro->gen('appkit.ext.dynamicScriptSource', array('script' => 'Cronks.JitStatusMap')) ?>");
 </script>
\ No newline at end of file
diff --git a/app/modules/Cronks/templates/System/js/CronkTrigger.js b/app/modules/Cronks/templates/System/js/CronkTrigger.js
new file mode 100644
index 0000000..0c60cd2
--- /dev/null
+++ b/app/modules/Cronks/templates/System/js/CronkTrigger.js
@@ -0,0 +1,58 @@
+function CronkTrigger (config) {
+
+	var thisConfig = {};
+
+	function initConfig() {
+		thisConfig.objectId = false;
+		thisConfig.objectName = false;
+		thisConfig.objectType = false;
+		thisConfig.returnVal = false;		
+	};
+
+	function setConfig (config) {
+		if (config.objectId != undefined && config.objectType != undefined) {
+			thisConfig.objectId = config.objectId;
+			thisConfig.objectName = config.objectName;
+			thisConfig.objectType = config.objectType;
+			completeConfig();
+		}
+	};
+
+	function completeConfig () {
+		switch (thisConfig.objectType) {
+			case "host":
+				thisConfig.idPrefix = "servicesForHost";
+				thisConfig.titlePrefix = "Services for ";
+				thisConfig.targetTemplate = "icinga-service-template";
+				thisConfig.targetField = "host_object_id";
+				break;
+			default:
+				initConfig();
+				break;
+		}
+	};
+
+	function createCronk () {
+		if (thisConfig.objectId != false && thisConfig.objectType != false) {
+			var cronk = {
+				parentid: thisConfig.idPrefix + "subGridComponent",
+				title: thisConfig.titlePrefix + thisConfig.objectName,
+				crname: "gridProc",
+				closable: true,
+				params: {template: thisConfig.targetTemplate}
+			};
+
+			var filter = {};
+			filter["f[" + thisConfig.targetField + "-value]"] = thisConfig.objectId;
+			filter["f[" + thisConfig.targetField + "-operator]"] = 50;
+
+			AppKit.Ext.util.InterGridUtil.gridFilterLink(cronk, filter);
+		}
+	};
+
+	initConfig();
+	setConfig(config);
+	createCronk();
+	return thisConfig.returnVal;
+
+};
\ No newline at end of file
diff --git a/app/modules/Cronks/templates/System/js/JitStatusMap.js b/app/modules/Cronks/templates/System/js/JitStatusMap.js
index 1a831d2..e4d3a87 100644
--- a/app/modules/Cronks/templates/System/js/JitStatusMap.js
+++ b/app/modules/Cronks/templates/System/js/JitStatusMap.js
@@ -9,11 +9,12 @@ function jitAddEvent(obj, type, fn) {
 var JitLog = {
 	elem: false,
 	write: function(elementId, text) {
-		if (!this.elem) 
+		if (!this.elem) {
 			this.elem = document.getElementById(elementId);
-			this.elem.innerHTML = text;
-			this.elem.style.left = (500 - this.elem.offsetWidth / 2) + "px";
 		}
+		this.elem.innerHTML = text;
+		this.elem.style.left = (500 - this.elem.offsetWidth / 2) + "px";
+	}
 };
 
 function JitStatusMap (config) {
diff --git a/pub/styles/Icinga.css b/pub/styles/Icinga.css
index df8213b..12d1db2 100644
--- a/pub/styles/Icinga.css
+++ b/pub/styles/Icinga.css
@@ -106,6 +106,10 @@ div.icinga-status-up, div.hostchart-0 {
 	background-color: #00cc00;
 }
 
+div.statusmap-host-0 {
+	color: #00cc00;
+}
+
 div.icinga-status-down, div.hostchart-1 {
 	background-color: #cc0000;
 }





More information about the icinga-checkins mailing list