saiku前端query.js

原创 2016年05月30日 10:49:43
/*  
 *   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-query-0.4-SNAPSHOT.jar

  • 2017年11月08日 09:30
  • 63KB
  • 下载

build 并deploy saiku-query0.1到nexus

一、下载saiku-query的源码:     https://github.com/OSBI/saiku-query.git 二、修改文件: 1、setting.xml文件(以下为关...

jquery_query_js获取url参数

  • 2012年12月13日 17:07
  • 30KB
  • 下载

query.unveil.js

  • 2017年06月26日 18:00
  • 1KB
  • 下载

Respond.js 兼容IE6-8 的CSS3 Media Query使用方法

书写基本样式 要想实现响应式布局,首先需要书写基本的响应式布局的样式。 html,body { height: 100%; } @media only screen and (min-wid...
  • cddcj
  • cddcj
  • 2016年11月04日 11:42
  • 996

AJA_Query_JS

  • 2009年04月09日 13:49
  • 2KB
  • 下载

jquery.query.js

  • 2013年09月13日 15:58
  • 8KB
  • 下载

用JS实现前端分页的简单方法

昨天朋友问我,后台传过来的数据在前端分页显示怎么做。 我也只做过后台分页查询前端显示的方法,没有做过后台不分页而在前端分页的形式。 于是研究了下后台返回全部数据,在前端将数据分页显示的办法。自己研究再...

Ext.Js前端布局插件

  • 2017年11月13日 10:53
  • 4.2MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:saiku前端query.js
举报原因:
原因补充:

(最多只允许输入30个字)