← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20971: PT noext.

 

------------------------------------------------------------
revno: 20971
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-11-06 13:50:52 +0100
message:
  PT noext.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core2.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-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js	2015-11-05 15:39:35 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js	2015-11-06 12:50:52 +0000
@@ -667,7 +667,7 @@
             };
         })();
 
-        // Axis
+        // Axis (array)
         (function() {
             var Axis = NS.Api.Axis = function(config) {
                 var t = [];
@@ -1041,15 +1041,46 @@
             };
         })();
 
-        // ResponseRow
+        // ResponseRow (array)
         (function() {
             var ResponseRow = NS.Api.ResponseRow = function(row) {
                 var t = NS.arrayFrom(row);
 
+                t.getAt = function(index) {
+                    return this[index];
+                };
+
+                t.setIdCombination = function(idCombination) {
+                    this.idCombination = idCombination;
+                };
+
+                // uninitialized
+                t.idCombination;
+
                 return t;
             };
         })();
 
+        // ResponseRowIdCombination
+        (function() {
+            var ResponseRowIdCombination = NS.Api.ResponseRowIdCombination = function(config) {
+                var t = this;
+
+                config = NS.isArray(config) ? config : (NS.isString(config) ? config.split('-') : null);
+
+                // constructor
+                t.ids = config || [];
+            };
+
+            ResponseRowIdCombination.prototype.add = function(id) {
+                this.ids.push(id);
+            };
+
+            ResponseRowIdCombination.prototype.get = function() {
+                return this.ids.join('-');
+            };
+        })();
+
         // Response
         (function() {
             var Response = NS.Api.Response = function(config) {
@@ -1080,7 +1111,7 @@
                 }();
 
                 // uninitialized
-                t.idValueMap = {};
+                t.idValueMap;
 
                 // ResponseHeader: index
                 t.headers.forEach(function(header, index) {
@@ -1118,6 +1149,17 @@
 
             // dep 1
 
+            Response.prototype.getHeaderIndexOrder = function(dimensionNames) {
+                var t = this,
+                    headerIndexOrder = [];
+
+                dimensionNames.forEach(function(name) {
+                    headerIndexOrder.push(t.getHeaderIndexByName(name));
+                });
+
+                return headerIndexOrder;
+            };
+
             Response.prototype.getItemName = function(id, isHierarchy, isHtml) {
                 return this.getHierarchyNameById(id, isHierarchy) + this.getNameById(id);
             };
@@ -1128,9 +1170,60 @@
 
             // dep 2
 
-            Response.prototype.getValueIndex = function() {
+            Response.prototype.getValueHeaderIndex = function() {
                 return this.getValueHeader().getIndex();
             };
+
+            // dep 3
+
+            Response.prototype.getIdValueMap = function(layout) {
+                if (this.idValueMap) {
+                    return this.idValueMap;
+                }
+
+                var t = this,
+                    headerIndexOrder = response.getHeaderIndexOrder(layout.getDimensionNames(true)),
+                    idValueMap = {},
+                    idCombination;
+
+                this.rows.forEach(function(row) {
+                    idCombination = new NS.Api.ResponseRowIdCombination();
+
+                    headerIndexOrder.forEach(function(index) {
+                        idCombination.add(row.getAt(index));
+                    });
+
+                    row.setIdCombination(idCombination);
+
+                    idValueMap[idCombination.get()] = row.getAt(t.getValueHeaderIndex());
+                });
+
+                return this.idValueMap = idValueMap;
+            };
+
+            // dep 4
+
+            Response.prototype.getValue = function(param, layout) {
+                var id = param instanceof NS.Api.ResponseRowIdCombination ? param.get() : param;
+
+                return this.getIdValueMap(layout)[param];
+            };
+
+            // dep 5
+
+            Response.prototype.getValues = function(paramArray, layout) {
+                var t = this,
+                    values = [],
+                    id;
+
+                paramArray = NS.arrayFrom(paramArray);
+
+                paramArray.forEach(function(param) {
+                    values.push(t.getValue(param, layout));
+                });
+
+                return values;
+            };
         })();
 
         //todo TableAxis