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} ;
0 commit comments