← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11560: (DV) Plugin updated. Supports uids only atm. Work in progress.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 11560 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-08-03 13:37:49 +0300
message:
  (DV) Plugin updated. Supports uids only atm. Work in progress.
added:
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.js
renamed:
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html => dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin.html
modified:
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/InitializeAction.java
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonInitialize.vm
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin.html


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/InitializeAction.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/InitializeAction.java	2013-06-26 12:18:21 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/InitializeAction.java	2013-08-02 12:12:32 +0000
@@ -86,8 +86,24 @@
     }
 
     // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+    
+    private String callback;
+    
+    public void setCallback( String callback )
+    {
+        this.callback = callback;
+    }
+
+    // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
+    
+    public String getCallback()
+    {
+        return callback;
+    }
 
     private String contextPath;
 

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html	2013-07-01 15:58:16 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html	2013-08-02 12:12:32 +0000
@@ -8,7 +8,6 @@
 
 	<link rel="stylesheet" type="text/css" href="../../dhis-web-commons/javascripts/ext/resources/css/ext-all-gray.css"/>
 	<link rel="stylesheet" type="text/css" href="css/style.css" />
-    <link href='http://fonts.googleapis.com/css?family=Cantarell' rel='stylesheet' type='text/css'>
 </head>
 
 <body>

=== renamed file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html' => 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin.html'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html	2012-06-16 21:17:34 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin.html	2013-08-03 10:23:34 +0000
@@ -1,173 +1,44 @@
+<!DOCTYPE html>
 <html>
 <head>
     <link rel="stylesheet" type="text/css" href="../../../dhis-web-commons/javascripts/ext/resources/css/ext-plugin-gray.css" />
-    <script type="text/javascript" src="../../../dhis-web-commons/javascripts/ext/ext-all.js"></script>
-    <script type="text/javascript" src="../../../dhis-web-commons/javascripts/plugin/plugin.js"></script>
+    
+    <script src="../../../dhis-web-commons/javascripts/ext/ext-all.js"></script>
+	<script src="scripts/core.js"></script>
+	<script src="scripts/plugin.js"></script>
 	
     <style type="text/css">
 		body {font-family: sans-serif; margin: 0 0 0 60px;}
 		
 		h1 {font-size: 20px; margin: 20px 0;}
 		
-		#chart1, #chart2, #chart3, #table1, #table2 {width: 1000px; margin-bottom: 50px;}
-		
-		#chart1, #chart2, #chart3 {height: 400px; border: 2px solid #d1d1d1; border-radius: 3px;}
-		
-		table {border-collapse: collapse;}
-		
-		table th, td {text-align: left; border: 1px solid #ccc;}
-		
-		table .val {text-align: center;}
+		#chart1, #chart2 {width: 1000px; margin-bottom: 50px; height: 300px; border: 2px solid #d1d1d1; border-radius: 1px;}
     </style>
     
-	<script type="text/javascript">
-		Ext.onReady( function() {
-			var url = '../../../'; // http://apps.dhis2.org/dev/
-		
-			DHIS.getChart({
-				uid: 'UlfTKWZWV4u',
-				callbackName: 'chart1',
+	<script>
+		Ext.onReady(function() {
+			var url = 'http://localhost:8080';
+			
+			DV.plugin.getChart({
+				url: url,
 				el: 'chart1',
-				url: url
+				uid: 'j1gNXBgwKVm'
 			});
 			
-			DHIS.getChart({
-				type: 'stackedcolumn',
-				indicators: ['Uvn6LCg7dVU'],
-				periods: 'last12Months',
-				category: 'period',
-				filter: 'organisationunit',
-				organisationunits: ['ImspTQPwCqd'],
-				orgUnitIsParent: false,
-				showData: true,
-				trendLine: true,
-				hideLegend: false,
-				hideSubtitle: false,
-				userOrganisationUnit: false,
-				userOrganisationUnitChildren: true,
-				targetLineValue: 80,
-				targetLineLabel: null,
-				baseLineValue: null,
-				baseLineLabel: null,
-				domainAxisLabel: null,
-				rangeAxisLabel: null,
-				callbackName: 'chart2',
+			DV.plugin.getChart({
+				url: url,
 				el: 'chart2',
-				url: url
-			});
-			
-			DHIS.getChart({
-				type: 'stackedcolumn',
-				indicators: ['Uvn6LCg7dVU'],
-				periods: 'thisYear',
-				category: 'organisationunit',
-				filter: 'period',
-				organisationunits: ['ImspTQPwCqd'],
-				orgUnitIsParent: true,
-				skipAnimation: true,
-				showData: true,
-				trendLine: true,
-				hideLegend: false,
-				hideSubtitle: false,
-				targetLineValue: 80,
-				targetLineLabel: null,				
-				baseLineValue: 20,
-				baseLineLabel: null,
-				callbackName: 'chart3',
-				el: 'chart3',
-				url: url
-			});
-			
-			DHIS.getTable({
-				indicators: ['Uvn6LCg7dVU'],
-				periods: ['last12Months'],
-				orgunits: ['ImspTQPwCqd'],
-				crosstab: ['periods'],
-				orgUnitIsParent: true,
-				hiddenCols: [0],
-				useExtGrid: false,
-				callbackName: 'table1',
-				el: 'table1',
-				url: url
-			});
-			
-			DHIS.getTable({
-				indicators: ['OdiHJayrsKo'],
-				periods: ['last12Months'],
-				orgunits: ['ImspTQPwCqd'],
-				crosstab: ['periods'],
-				orgUnitIsParent: true,
-				hiddenCols: [0],
-				useExtGrid: true,
-				el: 'table2',
-				url: url
-			});
-			
-			var url1 = DHIS.getUrl({
-				indicators: ['OdiHJayrsKo'],
-				periods: ['last12Months'],
-				orgunits: ['ImspTQPwCqd'],
-				crosstab: ['periods'],
-				orgUnitIsParent: true,
-				format: 'pdf',
-				url: url
-			});
-			
-			Ext.get('url1').update(url1);
+				uid: 'LW0O27b7TdD'
+			});
 		});
 	</script>
-	
-	<!--
-	CONFIG              	TYPE            DEFAULT             DESCRIPTION
-
-	uid                 	string                              (Optional) A chart uid. If provided, only 'el' and 'url' are required.
-		
-	type                			string          'column'            (Optional) Chart types: 'column', 'stackedcolumn', 'bar', 'stackedbar', 'line', 'area', 'pie'
-	indicators          			[integer]                           (Required*) Indicator uids. Required if no data elements are provided.
-	dataelements        			[integer]                           (Required*) Data element uids. Required if no indicators are provided.
-	periods             			[string]        'last12Months'      (Optional) Relative period names.
-	organisationunits   			[integer]                           (Required) Organisation unit uids.
-	series              			string          'data'              (Optional) Series: 'data', 'period' or 'organisationunit'.
-	category            			string          'period'            (Optional) Category: 'indicator', 'dataelement', 'period' or 'organisationunit'.
-	filter              			string          'organisationunit'  (Optional) Filter: 'indicator', 'dataelement', 'period' or 'organisationunit'.
-	orgUnitIsParent					boolean			false				(Optional) If true, the children of the provided orgunit are displayed.
-	showData						boolean			false				(Optional) If true, the exact data are displayed on the chart.
-	trendLine						boolean			false				(Optional) If true, trend line(s) are added.
-	hideLegend						boolean			false				(Optional) If true, the legend is not visible.
-	hideSubtitle					boolean			false				(Optional) If true, the subtitle is not visible.
-	userOrganisationUnit			boolean			false				(Optional) If true, the provided orgunits are replaced by the user orgunit.
-	userOrganisationUnitChildren	boolean			false				(Optional) If true, the provided orgunits are replaced by the user orgunit children.
-	targetLineValue					integer								(Optional) The value of the target line.
-	targetLineLabel					string								(Optional) The legend name of the target line. Requires targetLineValue, otherwise ignored.
-	baseLineValue					integer								(Optional) The value of the base line.
-	baseLineLabel					string								(Optional) The legend name of the base line. Requires baseLineValue, otherwise ignored.
-	domainAxisLabel					string								(Optional) Domain axis (usually the x axis) label.
-	rangeAxisLabel					string								(Optional) Range axis (usually the y axis) label.
-	legendPosition      			string          'top'               (Optional) Positions: 'top', 'right', 'bottom' or 'left'.
-	el                  			string                              (Required) The element id to render the chart.
-	width               			integer         <el width>          (Optional) Chart width. Default is the element width.
-	height              			integer         <el height>         (Optional) Chart height. Default is the element height.
-	url                 			string                              (Required) The base url of the DHIS instance.
-	-->
 </head>
 
 <body>
-    <h1>My chart 1</h1>
+    <h1>CHART 1</h1>
 	<div id="chart1"></div>
 	
-    <h1>My chart 2</h1>
+    <h1>CHART 2</h1>
 	<div id="chart2"></div>
-	
-    <h1>My chart 3</h1>
-	<div id="chart3"></div>
-	
-	<h1>My table 1</h1>
-	<div id="table1"></div>
-		
-	<h1>My table 2</h1>
-	<div id="table2"></div>
-	
-	<h1>My URL</h1>
-	<div id="url1"></div>
 </body>
 </html>

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2013-07-24 10:23:02 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2013-08-03 09:41:28 +0000
@@ -532,12 +532,6 @@
 			}
 		};
 
-		util.str = {
-			replaceAll: function(str, find, replace) {
-				return str.replace(new RegExp(find, 'g'), replace);
-			}
-		};
-
 		return util;
 	};
 

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js	2013-07-24 10:23:02 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js	2013-08-03 10:00:57 +0000
@@ -1,3 +1,13 @@
+if (!('DV' in window)) {
+	DV = {};
+}
+
+if(!('i18n' in DV)) {
+	DV.i18n = {};
+}
+
+DV.debug = false;
+
 DV.core = {
 	instances: []
 };
@@ -366,15 +376,15 @@
 
 	util.mask = {
 		showMask: function(cmp, str) {
-			if (DV.mask) {
-				DV.mask.destroy();
+			if (dv.mask) {
+				dv.mask.destroy();
 			}
-			DV.mask = new Ext.LoadMask(cmp, {msg: str});
-			DV.mask.show();
+			dv.mask = new Ext.LoadMask(cmp, {msg: str});
+			dv.mask.show();
 		},
 		hideMask: function() {
-			if (DV.mask) {
-				DV.mask.hide();
+			if (dv.mask) {
+				dv.mask.hide();
 			}
 		}
 	};
@@ -401,6 +411,12 @@
 		}
 	};
 
+	util.str = {
+		replaceAll: function(str, find, replace) {
+			return str.replace(new RegExp(find, 'g'), replace);
+		}
+	};
+	
 	util.value = {
 		jsonfy: function(values) {
 			var a = [];
@@ -1044,14 +1060,15 @@
 
 					return Ext.Array.max(sums);
 				};
-
-
-console.log("data", data);
-console.log("rangeFields", store.rangeFields);
-console.log("domainFields", store.domainFields);
-console.log("trendLineFields", store.trendLineFields);
-console.log("targetLineFields", store.targetLineFields);
-console.log("baseLineFields", store.baseLineFields);
+				
+				if (DV.debug) {
+					console.log("data", data);
+					console.log("rangeFields", store.rangeFields);
+					console.log("domainFields", store.domainFields);
+					console.log("trendLineFields", store.trendLineFields);
+					console.log("targetLineFields", store.targetLineFields);
+					console.log("baseLineFields", store.baseLineFields);
+				}
 
 				return store;
 			};
@@ -1789,7 +1806,7 @@
 					return;
 				}
 
-				dv.util.mask.showMask(dv.viewport);
+				dv.util.mask.showMask(dv.viewport.centerRegion);
 
 				Ext.Ajax.request({
 					method: 'GET',
@@ -1844,42 +1861,71 @@
 						dv.layout = layout;
 						dv.xLayout = xLayout;
 						dv.xResponse = xResponse;
-
-console.log("xResponse", xResponse);
-console.log("xLayout", xLayout);
-console.log("layout", layout);
+						
+						if (DV.debug) {
+							console.log("xResponse", xResponse);
+							console.log("xLayout", xLayout);
+							console.log("layout", layout);
+						}
 					}
 				});
 
 			}();
 		},
 
-		loadChart: function(id) {
+		loadChart: function(id, isJsonP) {
+			var url = dv.baseUrl + '/api/charts/' + id,
+				params = '?viewClass=dimensional&links=false',
+				method = 'GET',
+				success,
+				failure;
+			
 			if (!Ext.isString(id)) {
 				alert('Invalid id');
 				return;
 			}
-
-			Ext.Ajax.request({
-				url: dv.baseUrl + '/api/charts/' + id + '.json?viewClass=dimensional&links=false',
-				method: 'GET',
-				failure: function(r) {
-					dv.util.mask.hideMask();
-					alert(r.responseText);
-				},
-				success: function(r) {
-					var layoutConfig = Ext.decode(r.responseText),
-						layout = dv.api.layout.Layout(layoutConfig);
-
-					if (layout) {
-						dv.favorite = Ext.clone(layout);
-						dv.favorite.id = layoutConfig.id;
-						dv.favorite.name = layoutConfig.name;
-
-						dv.viewport.setFavorite(layout);
-					}
+			
+			success = function(layoutConfig) {
+				var layout = dv.api.layout.Layout(layoutConfig);
+
+				if (layout) {
+					dv.favorite = Ext.clone(layout);
+					dv.favorite.id = layoutConfig.id;
+					dv.favorite.name = layoutConfig.name;
+
+					dv.viewport.setFavorite(layout);
 				}
-			});
+			};
+			
+			failure = function(responseText) {
+				dv.util.mask.hideMask();
+				alert(responseText);
+			};
+				
+			if (isJsonP) {
+				Ext.data.JsonP.request({
+					url: url + '.jsonp' + params,
+					method: method,
+					failure: function(r) {
+						failure(r);
+					},
+					success: function(r) {
+						success(r);
+					}
+				});
+			}
+			else {
+				Ext.Ajax.request({
+					url: url + '.json' + params,
+					method: method,
+					failure: function(r) {
+						failure(r.responseText);
+					},
+					success: function(r) {
+						success(Ext.decode(r.responseText));
+					}
+				});
+			}
 		},
 
         analytical2layout: function(analytical) {

=== added file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.js	2013-08-03 09:55:27 +0000
@@ -0,0 +1,94 @@
+DV.plugin = {};
+DV.plugin.init = {};
+
+Ext.onReady(function() {
+	Ext.Ajax.method = 'GET';
+
+	document.body.oncontextmenu = function() {
+		return false;
+	};
+	
+	DV.plugin.getChart = function(config) {
+		var validateConfig,
+			afterRender,
+			createViewport,
+			dv,
+			initialize;
+			
+		validateConfig = function(config) {
+			if (!Ext.isObject(config)) {
+				console.log('Invalid chart configuration');
+				return;
+			}
+			
+			if (!Ext.isString(config.el)) {
+				console.log('No element provided');
+				return;
+			}
+			
+			if (!Ext.isString(config.uid)) {
+				console.log('No chart uid provided');
+				return;
+			}
+			
+			return true;
+		};
+			
+		afterRender = function() {};
+			
+		createViewport = function() {
+			var el = Ext.get(dv.el),
+				setFavorite,
+				centerRegion,
+				width,
+				height;
+				
+			width = el.getWidth() - parseInt(el.getStyle('border-left-width')) - parseInt(el.getStyle('border-right-width'));
+			height = el.getHeight() - parseInt(el.getStyle('border-top-width')) - parseInt(el.getStyle('border-bottom-width'));				
+				
+			setFavorite = function(layout) {
+				dv.util.chart.createChart(layout, dv);
+			};
+			
+			centerRegion = Ext.create('Ext.panel.Panel', {
+				renderTo: el,
+				bodyStyle: 'border: 0 none',
+				width: config.width || width,
+				height: config.height || height,
+				layout: 'fit',
+				listeners: {
+					afterrender: function() {
+						afterRender();
+					}
+				}
+			});
+			
+			return {
+				setFavorite: setFavorite,
+				centerRegion: centerRegion
+			};
+		};
+		
+		initialize = function() {
+			if (!validateConfig(config)) {
+				return;
+			}
+			
+			dv = DV.core.getInstance({
+				baseUrl: config.url,
+				el: config.el
+			});
+			
+			dv.viewport = createViewport();
+
+			Ext.data.JsonP.request({
+				url: dv.baseUrl + '/dhis-web-visualizer/initialize.action',
+				success: function(r) {
+					dv.init = r;
+					
+					dv.util.chart.loadChart(config.uid, true);	
+				}
+			});
+		}();
+	};
+});

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonInitialize.vm'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonInitialize.vm	2013-06-26 12:18:21 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonInitialize.vm	2013-08-02 12:12:32 +0000
@@ -1,4 +1,8 @@
-#set($oucSize = $currentUser.getOrganisationUnit().getSortedChildren().size()){
+#set($oucSize = $currentUser.getOrganisationUnit().getSortedChildren().size())
+#if($callback)$!{callback}
+(
+#end
+{
 "contextPath":"$!{contextPath}",
 "user":{"id":"$!currentUser.uid","name":"$currentUser.name","isAdmin":true,
 "ou":{"id":"$currentUser.getOrganisationUnit().uid","name":"$currentUser.getOrganisationUnit().name"},
@@ -6,4 +10,7 @@
 "rootNodes":[#foreach($node in $rootNodes){"id": "$!{node.uid}","text": "$!encoder.jsonEncode( ${node.name} )","level": 1,"hasChildrenWithCoordinates": $!{node.hasChildrenWithCoordinates()},"expanded": true}#if($velocityCount<$rootNodes.size()),#end#end],
 "dimensions":[#foreach($dim in $dimensions){"id":"$!{dim.uid}","name":"$!encoder.jsonEncode($!{dim.name})"}#if($velocityCount<$dimensions.size()),#end#end],
 "organisationUnitLevels":[#foreach($level in $levels){"id":"$!{level.uid}","name":"$!encoder.jsonEncode($!{level.name})","level":"$!{level.level}"}#if($velocityCount<$levels.size()),#end#end]
-}
\ No newline at end of file
+}
+#if($callback)
+)
+#end
\ No newline at end of file