dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25409
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12601: (PT) Plugin fixes.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 12601 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-10-13 14:47:53 +0200
message:
(PT) Plugin fixes.
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css
dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/plugin.html
dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js
dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js
--
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-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js 2013-10-10 11:49:54 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js 2013-10-13 12:41:41 +0000
@@ -2,14 +2,14 @@
// ext config
Ext.Ajax.method = 'GET';
-
- // pt
+
+ // pt
PT = {
core: {
instances: []
- },
- i18n: {},
- isDebug: false,
+ },
+ i18n: {},
+ isDebug: false,
isSessionStorage: 'sessionStorage' in window && window['sessionStorage'] !== null
};
@@ -767,7 +767,7 @@
layout.showTotals = Ext.isBoolean(config.totals) ? config.totals : (Ext.isBoolean(config.showTotals) ? config.showTotals : true);
layout.showSubTotals = Ext.isBoolean(config.subtotals) ? config.subtotals : (Ext.isBoolean(config.showSubTotals) ? config.showSubTotals : true);
layout.hideEmptyRows = Ext.isBoolean(config.hideEmptyRows) ? config.hideEmptyRows : false;
-
+
layout.showHierarchy = Ext.isBoolean(config.showHierarchy) ? config.showHierarchy : false;
layout.displayDensity = Ext.isString(config.displayDensity) && !Ext.isEmpty(config.displayDensity) ? config.displayDensity : 'normal';
@@ -799,7 +799,7 @@
};
api.response = {};
-
+
api.response.Header = function(config) {
var header = {};
@@ -883,43 +883,43 @@
}();
};
}());
-
+
// service
(function() {
service.layout = {};
-
+
service.layout.getObjectNameDimensionMap = function(dimensionArray) {
var map = {};
-
- if (Ext.isArray(dimensionArray) && dimensionArray.length) {
+
+ if (Ext.isArray(dimensionArray) && dimensionArray.length) {
for (var i = 0, dim; i < dimensionArray.length; i++) {
dim = api.layout.Dimension(dimensionArray[i]);
-
+
if (dim) {
map[dim.dimension] = dim;
}
}
}
-
+
return map;
- };
-
+ };
+
service.layout.getObjectNameDimensionItemsMap = function(dimensionArray) {
var map = {};
-
- if (Ext.isArray(dimensionArray) && dimensionArray.length) {
+
+ if (Ext.isArray(dimensionArray) && dimensionArray.length) {
for (var i = 0, dim; i < dimensionArray.length; i++) {
dim = api.layout.Dimension(dimensionArray[i]);
-
+
if (dim) {
map[dim.dimension] = dim.items;
}
}
}
-
+
return map;
};
-
+
service.response = {};
}());
@@ -1169,7 +1169,7 @@
paramString += '&filter=' + dim.dimensionName + ':' + dim.ids.join(';');
}
}
-
+
if (xLayout.showHierarchy) {
paramString += '&hierarchyMeta=true';
}
@@ -1207,26 +1207,26 @@
isHierarchy = function(id, response) {
return layout.showHierarchy && Ext.isObject(response.metaData.ouHierarchy) && response.metaData.ouHierarchy.hasOwnProperty(id);
- };
-
+ };
+
getItemName = function(id, response, isHtml) {
var metaData = response.metaData,
name = '';
-
+
if (isHierarchy(id, response)) {
var a = Ext.clean(metaData.ouHierarchy[id].split('/'));
a.shift();
-
+
for (var i = 0; i < a.length; i++) {
name += (isHtml ? '<span class="text-weak">' : '') + metaData.names[a[i]] + (isHtml ? '</span>' : '') + ' / ';
}
}
-
+
name += metaData.names[id];
-
+
return name;
};
-
+
getSyncronizedXLayout = function(xLayout, response) {
var removeDimensionFromXLayout,
getHeaderNames,
@@ -1341,10 +1341,10 @@
responseOu = response.metaData[ou];
userOugc = [];
-
+
for (var j = 0, id; j < responseOu.length; j++) {
id = responseOu[j];
-
+
if (!Ext.Array.contains(userOuOuc, id)) {
userOugc.push({
id: id,
@@ -1361,7 +1361,7 @@
else if (isLevel || isGroup) {
for (var j = 0, responseOu = response.metaData[ou], id; j < responseOu.length; j++) {
id = responseOu[j];
-
+
dim.items.push({
id: id,
name: getItemName(id, response)
@@ -2436,9 +2436,9 @@
};
afterLoad = function(layout, xLayout, xResponse) {
-
+
if (pt.isPlugin) {
-
+
// Resize render elements
var baseEl = Ext.get(pt.init.el),
baseElBorderW = parseInt(baseEl.getStyle('border-left-width')) + parseInt(baseEl.getStyle('border-right-width')),
@@ -2457,7 +2457,7 @@
setMouseHandlers();
engine.setSessionStorage('table', layout);
}
-
+
if (updateGui) {
pt.viewport.setGui(layout, xLayout, updateGui, isFavorite);
}
@@ -2479,7 +2479,7 @@
console.log("xResponse", xResponse);
console.log("xLayout", xLayout);
}
- };
+ };
initialize = function() {
var url,
@@ -2547,7 +2547,7 @@
// Update viewport
pt.viewport.centerRegion.removeAll(true);
pt.viewport.centerRegion.update(html);
-
+
afterLoad(layout, xLayout, xResponse);
}
});
@@ -2775,7 +2775,67 @@
// plugin
PT.plugin = {};
- PT.plugin.getTable = function(config) {
+ var init = {},
+ configs = [],
+ isInitialized = false,
+ getInit,
+ execute;
+
+ getInit = function(config) {
+ var requests = [],
+ callbacks = 0,
+ fn;
+
+ init.user = {};
+
+ fn = function() {
+ if (++callbacks === requests.length) {
+ for (var i = 0; i < configs.length; i++) {
+ execute(configs[i]);
+ }
+ }
+ };
+
+ requests.push({
+ url: config.url + '/api/system/info',
+ success: function(r) {
+ init.contextPath = r.contextPath;
+ fn();
+ }
+ });
+
+ requests.push({
+ url: config.url + '/api/organisationUnits.json?userOnly=true&viewClass=detailed&links=false',
+ success: function(r) {
+ var ou = r.organisationUnits[0];
+ init.user.ou = ou.id;
+ init.user.ouc = Ext.Array.pluck(ou.children, 'id');
+ fn();
+ }
+ });
+
+ requests.push({
+ url: config.url + '/api/mapLegendSets.json?viewClass=detailed&links=false&paging=false',
+ success: function(r) {
+ init.legendSets = r.mapLegendSets;
+ fn();
+ }
+ });
+
+ requests.push({
+ url: config.url + '/api/dimensions.json?links=false&paging=false',
+ success: function(r) {
+ init.dimensions = r.dimensions;
+ fn();
+ }
+ });
+
+ for (var i = 0; i < requests.length; i++) {
+ Ext.data.JsonP.request(requests[i]);
+ }
+ };
+
+ execute = function(config) {
var validateConfig,
extendInstance,
createViewport,
@@ -2835,36 +2895,41 @@
};
initialize = function() {
-
if (!validateConfig(config)) {
return;
}
- Ext.data.JsonP.request({
- url: config.url + '/dhis-web-pivot/initialize.action',
- success: function(r) {
- PT.i18n = r.i18n;
-
- pt = PT.core.getInstance(r);
- extendInstance(pt);
-
- pt.viewport = createViewport();
- pt.isPlugin = true;
-
- if (config.uid) {
- pt.engine.loadTable(config.uid, pt);
- }
- else {
- layout = pt.api.layout.Layout(config);
-
- if (!layout) {
- return;
- }
-
- pt.engine.createTable(layout, pt);
- }
+ pt = PT.core.getInstance(Ext.clone(init));
+ extendInstance(pt);
+
+ pt.viewport = createViewport();
+ pt.isPlugin = true;
+
+ if (config.uid) {
+ pt.engine.loadTable(config.uid, pt);
+ }
+ else {
+ layout = pt.api.layout.Layout(config);
+
+ if (!layout) {
+ return;
}
- });
+
+ pt.engine.createTable(layout, pt);
+ }
}();
};
+
+ PT.plugin.getTable = function(config) {
+ configs.push(config);
+
+ if (!isInitialized) {
+ isInitialized = true;
+ getInit(config);
+ }
+ };
+
+ DHIS = Ext.isObject(DHIS) ? DHIS : {};
+
+ DHIS.getTable = PT.plugin.getTable;
});
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css 2013-10-08 14:06:23 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css 2013-10-13 12:41:41 +0000
@@ -784,6 +784,7 @@
.gis-textfield input.x-form-text {
border-radius: 1px;
+ height: 24px;
}
=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/plugin.html'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/plugin.html 2013-10-10 11:15:21 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/plugin.html 2013-10-13 12:41:41 +0000
@@ -1,32 +1,36 @@
<!DOCTYPE html>
<html>
<head>
-
+
<link rel="stylesheet" type="text/css" href="http://localhost:8080/dhis-web-commons/javascripts/ext/resources/css/ext-plugin-gray.css" />
<script src="http://localhost:8080/dhis-web-commons/javascripts/ext/ext-all.js"></script>
+<!--
<script src="http://localhost:8080/dhis-web-commons/javascripts/plugin/table.js"></script>
-
+-->
+ <script src="http://localhost:8080/dhis-web-pivot/app/scripts/core.js"></script>
+ <script src="http://localhost:8080/dhis-web-pivot/app/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;}
-
+
#table1, #table2 {margin-bottom:40px;}
</style>
-
+
<script>
Ext.onReady(function() {
var url = 'http://localhost:8080';
-
+
PT.plugin.getTable({
url: url,
el: 'table1',
uid: 'C0rhAq1oklh'
});
-
+
PT.plugin.getTable({
url: url,
- el: 'table2',
+ el: 'table2',
columns: [
{dimension: 'de', items: [{id: 'Uvn6LCg7dVU'}, {id: 'OdiHJayrsKo'}, {id: 'sB79w2hiLp8'}]},
{dimension: 'pe', items: [{id: 'LAST_3_MONTHS'}]}
@@ -44,7 +48,7 @@
<body>
<h1>TABLE BY UID</h1>
<div id="table1"></div>
-
+
<h1>TABLE BY CONFIG</h1>
<div id="table2"></div>
</body>
=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js 2013-10-09 10:35:27 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js 2013-10-13 12:41:41 +0000
@@ -460,13 +460,15 @@
// init
(function() {
// sort and extend dynamic dimensions
- init.dimensions = util.array.sortObjectsByString(init.dimensions);
+ if (init.dimensions) {
+ init.dimensions = util.array.sortObjectsByString(init.dimensions);
- for (var i = 0, dim; i < init.dimensions.length; i++) {
- dim = init.dimensions[i];
- dim.dimensionName = dim.id;
- dim.objectName = conf.finals.dimension.dimension.objectName;
- conf.finals.dimension.objectNameMap[dim.id] = dim;
+ for (var i = 0, dim; i < init.dimensions.length; i++) {
+ dim = init.dimensions[i];
+ dim.dimensionName = dim.id;
+ dim.objectName = conf.finals.dimension.dimension.objectName;
+ conf.finals.dimension.objectNameMap[dim.id] = dim;
+ }
}
// legend set map
@@ -1812,13 +1814,13 @@
getTdHtml = function(config) {
var bgColor,
- legends,
+ mapLegends,
colSpan,
rowSpan,
htmlValue,
displayDensity,
fontSize,
- isLegendSet = Ext.isObject(legendSet) && Ext.isArray(legendSet.legends) && legendSet.legends.length,
+ isLegendSet = Ext.isObject(legendSet) && Ext.isArray(legendSet.mapLegends) && legendSet.mapLegends.length,
isNumeric = Ext.isObject(config) && Ext.isString(config.type) && config.type.substr(0,5) === 'value' && !config.empty,
isValue = Ext.isObject(config) && Ext.isString(config.type) && config.type === 'value' && !config.empty,
cls = '',
@@ -1830,13 +1832,13 @@
// Background color from legend set
if (isNumeric && isLegendSet) {
- legends = legendSet.legends;
+ legends = legendSet.mapLegends;
- for (var i = 0, value; i < legends.length; i++) {
+ for (var i = 0, value; i < mapLegends.length; i++) {
value = parseFloat(config.value);
- if (Ext.Number.constrain(value, legends[i].sv, legends[i].ev) === value) {
- bgColor = legends[i].color;
+ if (Ext.Number.constrain(value, mapLegends[i].sv, mapLegends[i].ev) === value) {
+ bgColor = mapLegends[i].color;
}
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js 2013-10-04 10:54:50 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js 2013-10-13 12:41:41 +0000
@@ -35,7 +35,67 @@
// plugin
PT.plugin = {};
- PT.plugin.getTable = function(config) {
+ var init = {},
+ configs = [],
+ isInitialized = false,
+ getInit,
+ execute;
+
+ getInit = function(config) {
+ var requests = [],
+ callbacks = 0,
+ fn;
+
+ init.user = {};
+
+ fn = function() {
+ if (++callbacks === requests.length) {
+ for (var i = 0; i < configs.length; i++) {
+ execute(configs[i]);
+ }
+ }
+ };
+
+ requests.push({
+ url: config.url + '/api/system/info',
+ success: function(r) {
+ init.contextPath = r.contextPath;
+ fn();
+ }
+ });
+
+ requests.push({
+ url: config.url + '/api/organisationUnits.json?userOnly=true&viewClass=detailed&links=false',
+ success: function(r) {
+ var ou = r.organisationUnits[0];
+ init.user.ou = ou.id;
+ init.user.ouc = Ext.Array.pluck(ou.children, 'id');
+ fn();
+ }
+ });
+
+ requests.push({
+ url: config.url + '/api/mapLegendSets.json?viewClass=detailed&links=false&paging=false',
+ success: function(r) {
+ init.legendSets = r.mapLegendSets;
+ fn();
+ }
+ });
+
+ requests.push({
+ url: config.url + '/api/dimensions.json?links=false&paging=false',
+ success: function(r) {
+ init.dimensions = r.dimensions;
+ fn();
+ }
+ });
+
+ for (var i = 0; i < requests.length; i++) {
+ Ext.data.JsonP.request(requests[i]);
+ }
+ };
+
+ execute = function(config) {
var validateConfig,
extendInstance,
createViewport,
@@ -95,36 +155,41 @@
};
initialize = function() {
-
if (!validateConfig(config)) {
return;
}
- Ext.data.JsonP.request({
- url: config.url + '/dhis-web-pivot/initialize.action',
- success: function(r) {
- PT.i18n = r.i18n;
-
- pt = PT.core.getInstance(r);
- extendInstance(pt);
-
- pt.viewport = createViewport();
- pt.isPlugin = true;
-
- if (config.uid) {
- pt.engine.loadTable(config.uid, pt);
- }
- else {
- layout = pt.api.layout.Layout(config);
-
- if (!layout) {
- return;
- }
-
- pt.engine.createTable(layout, pt);
- }
+ pt = PT.core.getInstance(Ext.clone(init));
+ extendInstance(pt);
+
+ pt.viewport = createViewport();
+ pt.isPlugin = true;
+
+ if (config.uid) {
+ pt.engine.loadTable(config.uid, pt);
+ }
+ else {
+ layout = pt.api.layout.Layout(config);
+
+ if (!layout) {
+ return;
}
- });
+
+ pt.engine.createTable(layout, pt);
+ }
}();
};
+
+ PT.plugin.getTable = function(config) {
+ configs.push(config);
+
+ if (!isInitialized) {
+ isInitialized = true;
+ getInit(config);
+ }
+ };
+
+ DHIS = Ext.isObject(DHIS) ? DHIS : {};
+
+ DHIS.getTable = PT.plugin.getTable;
});