您的位置:首页 > 产品设计 > UI/UE

saiku前端query.js

2016-05-30 10:49 567 查看
/*
*   Copyright 2012 OSBI Ltd
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0 *
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*/

/**
* Workspace query
*/
var Query = Backbone.Model.extend({

formatter: Settings.CELLSET_FORMATTER,
properties: null,
//初始化
<span style="font-size:18px;color:#ff0000;">initialize:</span> function(args, options) {
// Save cube
_.extend(this, options);

// Bind `this`运行查询,维度移动改变等查询方法
_.bindAll(this, <span style="font-size:18px;">"<span style="color:#ff0000;">run</span>", "<span style="color:#ff0000;">move_dimension</span>", "<span style="color:#ff0000;">reflect_properties</span>"</span>);

<span style="font-size:18px;"> <span style="color:#ff0000;">// Generate a unique query id 交互编号ID,查询ID
this.uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,</span></span><span style="color:#ff0000;"> </span>
function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}).toUpperCase();

<span style="font-size:18px;color:#ff0000;">// Initialize properties, action handler, and result handler查询参数设置和返回程序</span>
this.action = new QueryAction({}, { query: this });
this.result = new Result({ limit: Settings.RESULT_LIMIT }, { query: this });
this.scenario = new QueryScenario({}, { query: this });

this.set({type:'QM'});
},

parse: function(response) {
// Assign id so Backbone knows to PUT instead of POST
this.id = this.uuid;

this.set({
connection: response.cube.connectionName,
catalog: response.cube.catalogName,
schema: response.cube.schemaName,
cube: encodeURIComponent(response.cube.name),
axes: response.saikuAxes,
type: response.type
});

if (typeof response.properties != "undefined" && "saiku.ui.formatter" in response.properties) {
this.set({formatter : response.properties['saiku.ui.formatter']});
}

this.properties = new Properties(response.properties, { query: this });
this.reflect_properties();
},

reflect_properties: function() {
this.workspace.trigger('properties:loaded');
},

setProperty: function(key, value) {
if (typeof this.properties != "undefined" && this.properties.properties ) {
this.properties.properties[key] = value;
}
},
<span style="font-size:18px;color:#ff0000;">//页面查询绿色箭头执行查询方法
run: function(force, mdx)</span> {
// Check for automatic execution
Saiku.ui.unblock();
if (typeof this.properties != "undefined" && this.properties.properties['saiku.olap.query.automatic_execution'] === 'false'&&
! (force === true)) {
return;
}
this.workspace.unblock();

$(this.workspace.el).find(".workspace_results_info").empty();
this.workspace.trigger('query:run');
this.result.result = null;
// TODO - Validate query
// maybe we should sync it with the backend query JSON?
// this definitely needs improvement
if (this.get('type') != "MDX") {
var rows = $(this.workspace.el).find('.rows ul li').size();
var columns = $(this.workspace.el).find('.columns ul li').size();
if ((rows == 0 && columns == 0) && !this.workspace.other_dimension) {
var axes = this.get('axes');
if (axes) {
for (var axis_iter = 0; axis_iter < axes.length; axis_iter++) {
var axis = axes[axis_iter];
if (axis.name && axis.name == "ROWS") {
rows = axis.dimensionSelections.length;
}
if (axis.name && axis.name == "COLUMNS") {
columns = axis.dimensionSelections.length;
}
}
}
}
if (rows == 0 || columns == 0) {
$(this.workspace.table.el).html('');
$(this.workspace.processing).html('<span class="i18n">You need to put at least one level or measure on Columns and Rows for a valid query.</span>').show();
this.workspace.adjust();
Saiku.i18n.translate();
return;
}
}

// Run it
$(this.workspace.table.el)
.html('');
$(this.workspace.processing).html('<span class="processing_image">  </span> <span class="i18n">Running query...</span> [ <a class="cancel i18n" href="#cancel">Cancel</a> ]').show();
this.workspace.adjust();
this.workspace.trigger('query:fetch');
Saiku.i18n.translate();
// <a class="cancel" href="#cancel">x</a>

var message = '<span class="processing_image">  </span> <span class="i18n">Running query...</span> [ <a class="cancel i18n" href="#cancel">Cancel</a> ]';
this.workspace.block(message);

if (this.get('type')  == "MDX" && mdx != null) {
this.result.save({ mdx: mdx});
} else {
this.result.fetch();
}
},
<span style="font-size:18px;color:#ff0000;">//页面维度发生变化时调用该方法查询
move_dimension: function(dimension, target, index)</span> {
$(this.workspace.el).find('.run').removeClass('disabled_toolbar');
var url = "/axis/" + target + "/dimension/" + dimension;

this.action.post(url, {
data: {
position: index
},

success: function() {
if (('MODE' in Settings && (Settings.MODE == 'view' || Settings.MODE == 'table')) || (typeof this.query.properties != "undefined" && this.query.properties
.properties['saiku.olap.query.automatic_execution'] === 'true')) {
this.query.run(true);
}
}
});
},

<span style="color:#cc0000;"> </span><span style="font-size:18px;color:#ff0000;">url: function() {
return encodeURI(Saiku.session.username + "/query/" + this.uuid);
}</span>
});
URL:查询连接串示例:http://localhost:8080/saiku/rest/saiku/anonymousUser/query/4FF7D01E-8A6B-5EB4-991B-C0CE680A4BCA/result/flat
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  saiku BI 数据仓库