-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcubes.min.js
1 lines (1 loc) · 12.9 KB
/
cubes.min.js
1
(function(){var c={};c.map=function(g,h){var d=[];for(var e=0;e<g.length;e++){d.push(h(g[e]))}return d};c.filter=function(g,h){var d=[];for(var e=0;e<g.length;e++){if(h(g[e])){d.push(g[e])}}return d};c.find=function(e,g){var d;if(Object.prototype.toString.call(e)==="[object Array]"){for(d=0;d<e.length;d++){if(g(e[d])){return e[d]}}}else{for(d in e){if(g(e[d])){return e[d]}}}return null};c.indexOf=function(e,g){var d;if(Object.prototype.toString.call(e)==="[object Array]"){for(d=0;d<e.length;d++){if(g(e[d])){return d}}}else{for(d in e){if(g(e[d])){return d}}}return -1};c.isObject=function(d){return Object.prototype.toString.call(d)==="[object Object]"};c.isString=function(d){return Object.prototype.toString.call(d)==="[object String]"};var a=this;var b={};b.Server=function(d){if(d){this.ajaxRequest=d}else{this.ajaxRequest=$.ajax}this._cube_list=[];this._cubes={}};b.Server.prototype.ajaxRequest=function(d){throw"Must implement ajaxRequest for server to process jquery-style $.ajax settings object"};b.Server.prototype.query=function(h,d,f,j,e,g){var i={dataType:"json",type:"GET"};if(d.hasOwnProperty("name")){cube_name=d.name}else{cube_name=d}i.url=this.url+"cube/"+cube_name+"/"+h;i.data=f;if(f&&f.cut){i.data.cut=i.data.cut.toString()}if(f&&f.drilldown){i.data.drilldown=i.data.drilldown.toString()}i.success=function(k){j(k)};i.error=function(k){if(e){e(k)}};i.complete=function(k){if(g){g(k)}};return this.ajaxRequest(i)};b.Server.prototype.connect=function(g,h,d){var e=this;e.url=e._normalize_url(g);var f={dataType:"json",type:"GET"};f.url=e.url+"version";f.success=function(k,i,j){e.server_version=k.server_version;e.api_version=k.api_version;e.load_cube_list(h,d)};f.error=function(k,i,j){if(d){d(k)}};this.ajaxRequest(f)};b.Server.prototype._normalize_url=function(d){if(d[d.length-1]!="/"){return d+"/"}return d};b.Server.prototype.load_cube_list=function(g,d){var e=this;var f={dataType:"json",type:"GET"};f.url=e.url+"cubes";f.success=function(j,h,i){e._cube_list=j;if(g){g(e._cube_list)}};f.error=function(j,h,i){if(d){d(j)}};return this.ajaxRequest(f)};b.Server.prototype.get_cube=function(g,h,d){var e=this;if((g in this._cubes)&&h){h(this._cubes[g]);return null}var f={dataType:"json",type:"GET"};f.url=e.url+"cube/"+encodeURI(g)+"/model";f.success=function(l,j,k){var i=new b.Cube(l);e._cubes[g]=i;if(h){h(i)}};f.error=function(k,i,j){if(d){d(k)}};return this.ajaxRequest(f)};b.Cube=function(e){var d,f;this.name=e.name;!e.label||(this.label=e.label);!e.description||(this.description=e.description);!e.key||(this.key=e.key);!e.info||(this.info=e.info);!e.category||(this.category=e.category);!e.features||(this.features=e.features);this.measures=c.map(e.measures||[],function(g){return new b.Measure(g)});this.aggregates=c.map(e.aggregates||[],function(g){return new b.MeasureAggregate(g)});this.details=c.map(e.details||[],function(g){return new b.Attribute(g)});this.dimensions=c.map(e.dimensions||[],function(g){return new b.Dimension(g)})};b.Cube.prototype.dimension=function(d){if(c.isObject(d)){return d}return c.find(this.dimensions,function(e){return e.name===d})};b.Dimension=function(f){var g=this;var e;g.name=f.name;!f.label||(g.label=f.label);!f.description||(g.description=f.description);!f.default_hierarchy_name||(g.default_hierarchy_name=f.default_hierarchy_name);!f.info||(g.info=f.info);!f.role||(g.role=f.role);!f.cardinality||(g.cardinality=f.cardinality);g.levels=[];if(f.levels){for(e in f.levels){var h=new b.Level(g.name,f.levels[e]);g.levels.push(h)}}this.hierarchies={};if(f.hierarchies){for(e in f.hierarchies){var d=new b.Hierarchy(f.hierarchies[e],this);g.hierarchies[d.name]=d}}if(!g.default_hierarchy_name&&f.hierarchies&&f.hierarchies.length>0){g.default_hierarchy_name=f.hierarchies[0].name}};b.Dimension.prototype.hierarchy=function(d){if(c.isObject(d)){return d}if(!d){return this.hierarchies[this.default_hierarchy_name]}return this.hierarchies[d]};b.Dimension.prototype.level=function(d){if(c.isObject(d)){return d}return c.find(this.levels,function(e){return e.name==d})};b.Dimension.prototype.toString=function(d){return this.name};b.Dimension.prototype.display_label=function(){return this.label||this.name};b.Dimension.prototype.hierarchy=function(d){if(c.isObject(d)){return d}else{if(d!=null){return this.hierarchies[d]}else{return this.hierarchies[this.default_hierarchy_name]}}};b.Hierarchy=function(e,d){this.parse(e,d)};b.Hierarchy.prototype.parse=function(h,g){var f=this;var e;f.name=h.name;!h.label||(f.label=h.label);!h.description||(f.description=h.description);!h.info||(f.info=h.info);var d=h.levels||[];f.levels=c.map(d,function(i){return g.level(i)})};b.Hierarchy.prototype.toString=function(){return b.HIERARCHY_PREFIX_CHAR+this.name};b.Hierarchy.prototype.display_label=function(){return this.label||this.name};b.Level=function(d,e){this.parse(d,e)};b.Level.prototype.parse=function(f,g){var h=this;var e;h.dimension_name=f;h.name=g.name;!g.label||(h.label=g.label);!g.description||(h.description=g.description);!g.info||(h.info=g.info);h._key=g.key;h._label_attribute=g.label_attribute;h._order_attribute=g.order_attribute;!g.role||(h.role=g.role);!g.cardinality||(h.cardinality=g.cardinality);h.attributes=[];if(g.attributes){for(e in g.attributes){var d=new b.Attribute(g.attributes[e]);h.attributes.push(d)}}};b.Level.prototype.key=function(){var d=this._key;the_attr=c.find(this.attributes,function(e){return e.name===d});return the_attr||this.attributes[0]};b.Level.prototype.label_attribute=function(){var e=null;if(this._label_attribute){var d=this._label_attribute;e=c.find(this.attributes,function(f){return f.name===d})}return e||this.key()};b.Level.prototype.order_attribute=function(){var d=null;if(this._order_attribute){d=c.find(this.attributes,function(e){e.name===this.__order_attribute})}return d||this.key()};b.Level.prototype.toString=function(){return this.name};b.Level.prototype.display_name=function(){return this.label||this.name};b.Level.prototype.full_name=function(){return this.dimension_name+b.ATTRIBUTE_STRING_SEPARATOR_CHAR+this.name};b.Level.prototype.full_name_for_drilldown=function(){return this.dimension_name+b.DIMENSION_STRING_SEPARATOR_CHAR+this.name};b.Attribute=function(d){this.ref=d.ref;this.name=d.name;this.label=d.label;this.order=d.order;this.info=(d.info||{});this.description=d.description;this.format=d.format;this.missing_value=d.missing_value;this.locales=d.locales};b.Measure=function(d){this.ref=d.ref;this.name=d.name;this.label=d.label;this.order=d.order;this.info=(d.info||{});this.description=d.description;this.format=d.format;this.missing_value=d.missing_value;if(d.aggregates){this.aggregates=d.aggregates}};b.MeasureAggregate=function(d){this.ref=d.ref;this.name=d.name;this.label=d.label;this.order=d.order;this.locales=d.locales;this.info=(d.info||{});this.description=d.description;this.format=d.format;this.missing_value=d.missing_value;this["function"]=d["function"];this.measure=d.measure};b.Browser=function(e,d){this.cube=d;this.server=e};b.Browser.prototype.full_cube=function(d){return new b.Cell(this.cube)};b.Browser.prototype.aggregate=function(d,f){if(!d){d={}}var e={};if(d.cut){e.cut=d.cut.toString()}if(d.measure){e.measure=d.measure.toString()}if(d.drilldown){e.drilldown=d.drilldown.toString()}if(d.split){e.split=d.split.toString()}if(d.order){e.order=d.order.toString()}if(d.page){e.page=d.page}if(d.pagesize){e.pagesize=d.pagesize}this.server.query("aggregate",this.cube,d,f)};b.Drilldown=function(e,d,f){if(!c.isObject(e)){throw"Drilldown requires a Dimension object as first argument"}this.dimension=e;this.hierarchy=e.hierarchy(d);this.level=e.level(f)||this.hierarchy.levels[0];if(!this.hierarchy){throw"Drilldown cannot recognize hierarchy "+d+" for dimension "+e}if(!this.level){throw"Drilldown cannot recognize level "+f+" for dimension "+e}};b.Drilldown.prototype.toString=function(){return""+this.dimension+this.hierarchy+b.DIMENSION_STRING_SEPARATOR_CHAR+this.level};b.Drilldown.prototype.keysInResultCell=function(){var d=this;var e=false;var f=c.filter(d.hierarchy.levels,function(g){return(g.key()===d.level.key()&&(e=true))||(!e)});return c.map(f,function(g){return g.key().ref})};b.Drilldown.prototype.labelsInResultCell=function(){var d=this;var e=false;var f=c.filter(d.hierarchy.levels,function(g){return(g.key()===d.level.key()&&(e=true))||(!e)});return c.map(f,function(g){return g.label_attribute().ref})};b.Cell=function(e,d){this.cube=e;this.cuts=c.map((d||[]),function(f){return f})};b.Cell.prototype.slice=function(h){var e=[];var g=false;for(var f=0;f<this.cuts.length;f++){var j=this.cuts[f];if(j.dimension==h.dimension){e.push(h);g=true}else{e.push(j)}}if(!g){e.push(h)}var d=new b.Cell(this.cube,e);return d};b.Cell.prototype.toString=function(){return c.map(this.cuts||[],function(d){return d.toString()}).join(b.CUT_STRING_SEPARATOR_CHAR)};b.Cell.prototype.cut_for_dimension=function(d){return c.find(this.cuts,function(e){return e.dimension.name==d})};b.PointCut=function(f,d,e,g){this.type="point";this.dimension=f;this.hierarchy=f.hierarchy(d);this.path=e;this.invert=!!g};b.PointCut.prototype.toString=function(){var d=b.string_from_path(this.path);return(this.invert?b.CUT_INVERSION_CHAR:"")+this.dimension+(this.hierarchy||"")+b.DIMENSION_STRING_SEPARATOR_CHAR+d};b.SetCut=function(e,d,g,f){this.type="set";this.dimension=e;this.hierarchy=e.hierarchy(d);this.paths=g;this.invert=!!f};b.SetCut.prototype.toString=function(){var d=c.map(this.paths,b.string_from_path).join(b.SET_CUT_SEPARATOR_CHAR);return(this.invert?b.CUT_INVERSION_CHAR:"")+this.dimension+(this.hierarchy||"")+b.DIMENSION_STRING_SEPARATOR_CHAR+d};b.RangeCut=function(g,e,d,f,h){this.type="range";this.dimension=g;this.hierarchy=g.hierarchy(e);if(d===null&&f===null){throw"Either from_path or to_path must be defined for RangeCut"}this.from_path=d;this.to_path=f;this.invert=!!h};b.RangeCut.prototype.toString=function(){var d=b.string_from_path(this.from_path)+b.RANGE_CUT_SEPARATOR_CHAR+b.string_from_path(this.to_path);return(this.invert?b.CUT_INVERSION_CHAR:"")+this.dimension+(this.hierarchy||"")+b.DIMENSION_STRING_SEPARATOR_CHAR+d};b.CUT_INVERSION_CHAR="!";b.CUT_STRING_SEPARATOR_CHAR="|";b.DIMENSION_STRING_SEPARATOR_CHAR=":";b.ATTRIBUTE_STRING_SEPARATOR_CHAR=".";b.HIERARCHY_PREFIX_CHAR="@";b.PATH_STRING_SEPARATOR_CHAR=",";b.RANGE_CUT_SEPARATOR_CHAR="-";b.SET_CUT_SEPARATOR_CHAR=";";b.CUT_STRING_SEPARATOR=/\|/g;b.DIMENSION_STRING_SEPARATOR=/:/g;b.PATH_STRING_SEPARATOR=/,/g;b.RANGE_CUT_SEPARATOR=/-/g;b.SET_CUT_SEPARATOR=/;/g;b.PATH_PART_ESCAPE_PATTERN=/([\\!|:;,-])/g;b.PATH_PART_UNESCAPE_PATTERN=/\\([\\!|:;,-])/g;b.CUT_PARSE_REGEXP=new RegExp("^("+b.CUT_INVERSION_CHAR+"?)(\\w+)(?:"+b.HIERARCHY_PREFIX_CHAR+"(\\w+))?"+b.DIMENSION_STRING_SEPARATOR_CHAR+"(.*)$");b.DRILLDOWN_PARSE_REGEXP=new RegExp("^(\\w+)(?:"+b.HIERARCHY_PREFIX_CHAR+"(\\w+))?(?:"+b.DIMENSION_STRING_SEPARATOR_CHAR+"(\\w+))?$");b.NULL_PART_STRING="__null__";b.SPLIT_DIMENSION_STRING="__within_split__";b._split_with_negative_lookbehind=function(d,g,h){var f=d;var e;var i=[];while((e=g.exec(f))!=null){if(f.substr(e.index-h.length,h.length)!=h){i.push(f.substring(0,e.index));f=f.substring(Math.min(e.index+e[0].length,f.length),f.length)}else{}}i.push(f);return i};b._escape_path_part=function(d){if(d==null){return b.NULL_PART_STRING}return d.toString().replace(b.PATH_PART_ESCAPE_PATTERN,function(f,e){return"\\"+e})};b._unescape_path_part=function(d){if(d===b.NULL_PART_STRING){return null}return d.replace(b.PATH_PART_UNESCAPE_PATTERN,function(f,e){return e})};b.string_from_path=function(e){var d=c.map(e||[],function(f){return b._escape_path_part(f)}).join(b.PATH_STRING_SEPARATOR_CHAR);return d};b.path_from_string=function(d){var f=b._split_with_negative_lookbehind(d,b.PATH_STRING_SEPARATOR,"\\");var e=c.map(f||[],function(g){return b._unescape_path_part(g)});return e};b.cut_from_string=function(m,i){var h=b.CUT_PARSE_REGEXP.exec(i);if(!h){return null}var d=!!(h[1]),g=h[2],j=h[3]||null,k=h[4];var f=m.dimension(g);var n=b._split_with_negative_lookbehind(k,b.SET_CUT_SEPARATOR,"\\");if(n.length>1){return new b.SetCut(f,j,c.map(n,function(o){return b.path_from_string(o)}),d)}n=b._split_with_negative_lookbehind(k,b.RANGE_CUT_SEPARATOR,"\\");if(n.length==2){var e=n[0]?b.path_from_string(n[0]):null;var l=n[1]?b.path_from_string(n[1]):null;return new b.RangeCut(f,j,e,l,d)}return new b.PointCut(f,j,b.path_from_string(k),d)};b.cuts_from_string=function(f,d){var e=b._split_with_negative_lookbehind(d,b.CUT_STRING_SEPARATOR,"\\");return c.map(e||[],function(g){return b.cut_from_string(f,g)})};b.cell_from_string=function(e,d){return new b.Cell(e,b.cuts_from_string(e,d))};b.drilldown_from_string=function(i,g){var f=b.DRILLDOWN_PARSE_REGEXP.exec(g);if(!f){return null}var d=f[1],e=f[2]||null,j=f[3]||null;var h=i.dimension(d);if(!h){return null}return new b.Drilldown(h,e,j)};b.drilldowns_from_string=function(f,d){var e=b._split_with_negative_lookbehind(d,b.CUT_STRING_SEPARATOR,"\\");return c.map(e||[],function(g){return b.drilldown_from_string(f,g)})};b.drilldowns_to_string=function(d){return c.map(d,function(e){return e.toString()}).join(b.CUT_STRING_SEPARATOR_CHAR)};a.cubes=b}).call(this);