[icinga-checkins] icinga.org: icinga-web/master: * Cleanup cronk code for status map

git at icinga.org git at icinga.org
Tue Nov 22 10:42:20 CET 2011


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Nov 22 10:41:05 2011 +0100

* Cleanup cronk code for status map
* Added auto refresh for status map (fixes #757)

---

 app/modules/Cronks/config/javascript.xml           |    3 +-
 .../Cronks/lib/js/Cronks/StatusMap/Cronk.js        |   49 ++++++++++++++++++
 .../StatusMap/RGraph.js}                           |   52 ++++++++++++++++++--
 .../Cronks/templates/System/StatusMapSuccess.php   |   31 ++++++++----
 4 files changed, 118 insertions(+), 17 deletions(-)

diff --git a/app/modules/Cronks/config/javascript.xml b/app/modules/Cronks/config/javascript.xml
index 64c7080..78c2630 100644
--- a/app/modules/Cronks/config/javascript.xml
+++ b/app/modules/Cronks/config/javascript.xml
@@ -49,7 +49,8 @@
 			<ae:parameter>%core.module_dir%/Cronks/lib/js/grid/IcingaGridFilterHandler.js</ae:parameter>
 			<ae:parameter>%core.module_dir%/Cronks/lib/js/grid/IcingaCommandHandler.js</ae:parameter>
 			<ae:parameter>%core.module_dir%/Cronks/lib/js/grid/renderer/StatusMapColumnRenderer.js</ae:parameter>
-			<ae:parameter>%core.module_dir%/Cronks/lib/js/JitStatusMap.js</ae:parameter>
+			<ae:parameter>%core.module_dir%/Cronks/lib/js/Cronks/StatusMap/RGraph.js</ae:parameter>
+            <ae:parameter>%core.module_dir%/Cronks/lib/js/Cronks/StatusMap/Cronk.js</ae:parameter>
 			<ae:parameter>%core.module_dir%/Cronks/lib/js/CronkTrigger.js</ae:parameter>
 			
 			<!-- Tackle view components -->
diff --git a/app/modules/Cronks/lib/js/Cronks/StatusMap/Cronk.js b/app/modules/Cronks/lib/js/Cronks/StatusMap/Cronk.js
new file mode 100644
index 0000000..95709d9
--- /dev/null
+++ b/app/modules/Cronks/lib/js/Cronks/StatusMap/Cronk.js
@@ -0,0 +1,49 @@
+Ext.ns('Icinga.Cronks.StatusMap');
+
+Icinga.Cronks.StatusMap.Cronk = Ext.extend(Ext.Panel, {
+	
+	url : null,
+	rgraph : null,
+	refreshTime : 300,
+	
+	constructor : function(config) {
+		Icinga.Cronks.StatusMap.Cronk.superclass.constructor.call(this, config);
+	},
+	
+	initComponent : function() {		
+		this.tbar = [{
+            xtype: 'button',
+            iconCls: 'icinga-icon-application-edit',
+            text: _('Settings'),
+            menu: [{
+                text: _('Autorefresh'),
+                xtype: 'menucheckitem',
+                checkHandler: function(item, state) {
+                	var tr = AppKit.getTr();
+                	if (state === true) {
+                		tr.start(this.refreshTask);
+                	} else if (state === false) {
+                		tr.stop(this.refreshTask);
+                	}
+                },
+                scope:this
+            }]
+        }];
+		
+		Icinga.Cronks.StatusMap.Cronk.superclass.initComponent.call(this);
+		
+		this.rgraph = new Icinga.Cronks.StatusMap.RGraph({
+			url : this.url,
+			parentId : this.getId()
+		});
+		
+		this.refreshTask = {
+            run :  this.rgraph.reloadTree.createDelegate(this.rgraph),
+            interval : (this.refreshTime * 1000)
+        };
+	},
+	
+	getRGraph : function() {
+		return this.rgraph;
+	}
+});
\ No newline at end of file
diff --git a/app/modules/Cronks/lib/js/JitStatusMap.js b/app/modules/Cronks/lib/js/Cronks/StatusMap/RGraph.js
similarity index 82%
rename from app/modules/Cronks/lib/js/JitStatusMap.js
rename to app/modules/Cronks/lib/js/Cronks/StatusMap/RGraph.js
index 3be2f20..ad3c525 100755
--- a/app/modules/Cronks/lib/js/JitStatusMap.js
+++ b/app/modules/Cronks/lib/js/Cronks/StatusMap/RGraph.js
@@ -1,3 +1,5 @@
+Ext.ns('Icinga.Cronks.StatusMap');
+
 function jitAddEvent(obj, type, fn) {
 	if (obj.addEventListener) {
 		obj.addEventListener(type, fn, false);
@@ -18,7 +20,7 @@ var JitLog = {
 	}
 };
 
-function JitStatusMap (config) {
+Icinga.Cronks.StatusMap.RGraph = function (config) {
 
 	this.cmp = false;
 
@@ -63,6 +65,7 @@ function JitStatusMap (config) {
 		}
 
 		var w = infovis.offsetWidth, h = infovis.offsetHeight;
+		
 		rgraph = new $jit.RGraph({
 			Node: {
 				overridable: true,
@@ -186,7 +189,20 @@ function JitStatusMap (config) {
 			}
 		}, this);
 		return node;
-	}
+	};
+	
+	this.findNodeById = function(misc, oid) {
+		var node = null;
+        Ext.each(misc, function(item) {
+            if (item.id == oid) {
+                node = item;
+                return false;
+            } else if (Ext.isDefined(item.children) && item.children.length > 0) {
+                node = this.findNodeById(item.children, oid);
+            }
+        }, this);
+        return node;
+    };
 	
 	this.init = function (config) {
 		this.setConfig(config);
@@ -221,7 +237,7 @@ function JitStatusMap (config) {
 	}
 
 	this.createContainer = function () {
-		var container = new Ext.Container({
+		this.container = new Ext.Container({
 			id: this.elementIds.jitContainer,
 			autoEl: 'div', 
 			layout: 'column',
@@ -254,7 +270,7 @@ function JitStatusMap (config) {
 			}]
 		});
 	
-		this.cmp.add(container);
+		this.cmp.add(this.container);
 		this.cmp.doLayout();
 	}
 
@@ -263,9 +279,35 @@ function JitStatusMap (config) {
 		this.mask.show();			
 	}
 
+    this.reloadTree = function() {
+        this.showMask();
+        
+        var root = rgraph.root;
+        var node = this.findNodeById(this.jitJson, root);
+        
+        Ext.Ajax.request({
+            url : this.config.url,
+            params : this.config.params,
+            method : this.config.method,
+            success : function (response, o) {
+                this.jitJson = Ext.decode(response.responseText);
+                rgraph.loadJSON(this.jitJson);
+                rgraph.refresh();
+                this.centerNodeByObjectId(node.data.object_id);
+                this.mask.hide();
+                this.mask.disable();
+            },
+            failure : this.getMapDataFail,
+            callback : this.getMapDataDefault,
+            scope: this,
+            timeout : this.config.timeout,
+            disableCaching : this.config.disableCaching
+        });
+    };
+
 	this.getMapData = function () {
 		this.showMask();
-		var ajax = Ext.Ajax.request({
+		Ext.Ajax.request({
 			url : this.config.url,
 			params : this.config.params,
 			method : this.config.method,
diff --git a/app/modules/Cronks/templates/System/StatusMapSuccess.php b/app/modules/Cronks/templates/System/StatusMapSuccess.php
index b2086dd..6db7f20 100755
--- a/app/modules/Cronks/templates/System/StatusMapSuccess.php
+++ b/app/modules/Cronks/templates/System/StatusMapSuccess.php
@@ -1,13 +1,22 @@
 <script type="text/javascript">
-Cronk.util.initEnvironment("<?php echo $parentid = $rd->getParameter('parentid'); ?>", function() {
-	var map = new JitStatusMap({
-		url: "<?php echo $ro->gen('modules.cronks.statusMap.json'); ?>",
-		parentId: this.parentid
-	});
-	
-	// Link some object to the cronk registry object
-	// this.getRegistryEntry().params.jitStatusmap = map;
-	
-	this.registry.local.statusmap = map;
+Cronk.util.initEnvironment(<?php CronksRequestUtil::echoJsonString($rd); ?>, function() {
+    
+    var statusmap = new Icinga.Cronks.StatusMap.Cronk({
+    	url: "<?php echo $ro->gen('modules.cronks.statusMap.json'); ?>",
+    	refreshTime : "<?php echo $us->getPrefVal('org.icinga.status.refreshTime', 60); ?>"
+    });
+
+//    var map = new Icinga.Cronks.StatusMap.RGraph({
+//        url: "<?php echo $ro->gen('modules.cronks.statusMap.json'); ?>",
+//        parentId: panel.getId()
+//    });
+
+    // Link some object to the cronk registry object
+    // this.getRegistryEntry().params.jitStatusmap = map;
+    this.registry.local.statusmap = statusmap.getRGraph();
+
+    this.getParent().removeAll();
+    this.add(statusmap);
+    this.doLayout();
 });
-</script>
+</script>
\ No newline at end of file





More information about the icinga-checkins mailing list