Skip to content

Commit 13b3a09

Browse files
LPT now retrieves pivot data by itself, pivot filters support
1 parent a17c0b5 commit 13b3a09

File tree

3 files changed

+89
-12
lines changed

3 files changed

+89
-12
lines changed

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
MDX2JSONSource: "http://localhost:57772/SAMPLES", // MDX2JSON server address
9191
basicMDX: typeof req === "object" ? req.basicMDX : req
9292
}
93+
//, DrillDownExpression; "<spec>" - drillDown expression split by "^"
9394
//, showSummary: true // show summary by columns
9495
//, formatNumbers: "#,###.##"
9596
//, drillDownTarget: "<dashboard name>" - undocumented, deepSee only

source/js/DataSource.js

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,31 @@
44
* Must implement methods.
55
*
66
* @param {Object} config
7+
* @param {Object} globalConfig
78
* @constructor
89
*/
9-
var DataSource = function (config) {
10+
var DataSource = function (config, globalConfig) {
1011

1112
this.SOURCE_URL = config.MDX2JSONSource ||
1213
location.host + ":" + location.port + "/" + (location.pathname.split("/") || [])[1];
1314

1415
this.BASIC_MDX = config.basicMDX;
1516

17+
this.GLOBAL_CONFIG = globalConfig;
18+
19+
/**
20+
* Name of data source pivot.
21+
*
22+
* @type {string}
23+
*/
24+
this.DATA_SOURCE_PIVOT = config["pivot"] || "";
25+
1626
this.ACTION = config.action || "MDX";
1727

1828
this.FILTERS = [];
1929

30+
this.BASIC_FILTERS = [];
31+
2032
};
2133

2234
/**
@@ -71,7 +83,6 @@ DataSource.prototype._convert = function (data) {
7183
dataArray: data["Data"],
7284
info: data["Info"]
7385
};
74-
//console.log(o);
7586
return o;
7687
} catch (e) {
7788
console.error("Error while parsing data:", e);
@@ -103,17 +114,49 @@ DataSource.prototype.getCurrentData = function (callback) {
103114
var _ = this,
104115
__ = this._convert,
105116
mdx = this.BASIC_MDX,
106-
mdxParser = new MDXParser();
117+
mdxParser = new MDXParser(),
118+
ready = {
119+
state: 0,
120+
data: {},
121+
pivotData: {}
122+
};
107123

108-
for (var i in this.FILTERS) {
109-
mdx = mdxParser.applyFilter(mdx, this.FILTERS[i]);
110-
}
124+
var setupPivotOptions = function () {
125+
126+
var data = ready.pivotData;
127+
128+
if (data["rowAxisOptions"]) {
129+
if (data["rowAxisOptions"]["drilldownSpec"]) {
130+
_.GLOBAL_CONFIG["DrillDownExpression"] =
131+
_.GLOBAL_CONFIG["DrillDownExpression"]
132+
|| data["rowAxisOptions"]["drilldownSpec"].split("^");
133+
}
134+
if (data["rowAxisOptions"]["levelFormat"]
135+
|| data["columnAxisOptions"]
136+
&& data["columnAxisOptions"]["levelFormat"]) {
137+
_.GLOBAL_CONFIG["formatNumbers"] =
138+
_.GLOBAL_CONFIG["formatNumbers"]
139+
|| data["columnAxisOptions"]["levelFormat"]
140+
|| data["rowAxisOptions"]["levelFormat"];
141+
}
142+
}
143+
144+
if (data["filters"] && data["filters"].length > 0) {
145+
for (var i in data["filters"]) {
146+
if (data["filters"][i]["spec"]) {
147+
_.BASIC_FILTERS.push(data["filters"][i]["spec"]);
148+
}
149+
}
150+
}
151+
152+
};
153+
154+
var handleDataReady = function () {
111155

112-
console.log("Request MDX: " + mdx);
156+
var data = ready.data;
157+
158+
console.log("Retrieved data:", ready);
113159

114-
this._post(this.SOURCE_URL + "/" + this.ACTION, {
115-
MDX: mdx
116-
}, function (data) {
117160
(data.Info || {}).action = _.ACTION;
118161
if (_.ACTION === "MDXDrillthrough") {
119162
callback((function (data) {
@@ -159,6 +202,39 @@ DataSource.prototype.getCurrentData = function (callback) {
159202
console.error("Not implemented URL action: " + _.ACTION);
160203
callback({ error: "Not implemented URL action: " + data || true });
161204
}
162-
});
205+
206+
};
207+
208+
var requestData = function () {
209+
210+
var filters = _.BASIC_FILTERS.concat(_.FILTERS);
211+
212+
for (var i in filters) {
213+
mdx = mdxParser.applyFilter(mdx, filters[i]);
214+
}
215+
216+
console.log("Requesting MDX: " + mdx);
217+
218+
_._post(_.SOURCE_URL + "/" + _.ACTION, {
219+
MDX: mdx
220+
}, function (data) {
221+
ready.data = data;
222+
ready.state++;
223+
handleDataReady();
224+
});
225+
};
226+
227+
if (this.DATA_SOURCE_PIVOT) {
228+
this._post(this.SOURCE_URL + "/DataSource", {
229+
DataSource: this.DATA_SOURCE_PIVOT
230+
}, function (data) {
231+
ready.pivotData = data;
232+
ready.state++;
233+
setupPivotOptions();
234+
requestData();
235+
});
236+
} else {
237+
requestData();
238+
}
163239

164240
};

source/js/LightPivotTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ LightPivotTable.prototype.pushDataSource = function (config) {
8686
var newDataSource;
8787

8888
this.DRILL_LEVEL++;
89-
this._dataSourcesStack.push(newDataSource = new DataSource(config));
89+
this._dataSourcesStack.push(newDataSource = new DataSource(config, this.CONFIG));
9090
this.dataSource = newDataSource;
9191

9292
return newDataSource;

0 commit comments

Comments
 (0)