diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/index.html b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/index.html
index e19dee5..ee8c6d9 100755
--- a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/index.html
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/index.html
@@ -302,9 +302,9 @@
-
+ title="Save query">
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/SessionWorkspace.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/SessionWorkspace.js
index 1427d29..afc9758 100755
--- a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/SessionWorkspace.js
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/SessionWorkspace.js
@@ -142,7 +142,7 @@ var SessionWorkspace = Backbone.Model.extend({
url: function() {
if (this.first) {
this.first = false;
- return encodeURI(Saiku.session.username + "/discover/");
+ return encodeURI(Saiku.session.username + "/discover");
}
else {
return encodeURI(Saiku.session.username + "/discover/refresh");
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Dimension.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Dimension.js
new file mode 100755
index 0000000..2997f5e
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Dimension.js
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+/**
+ * Model which fetches the dimensions for a cube
+ */
+var Dimension = Backbone.Model.extend({
+ initialize: function(args) {
+ this.url = Saiku.session.username + "/discover/" +
+ args.key + "/dimensions";
+ },
+
+ parse: function(response) {
+ this.set({
+ template: _.template($("#template-dimensions").html())({
+ dimensions: response
+ }),
+
+ data: response
+ });
+
+ typeof localStorage !== "undefined" && localStorage && localStorage.setItem("dimension." + this.get('key'),
+ JSON.stringify(this));
+
+ return response;
+ }
+});
+
+/**
+ * Model which fetches the measures for a cube
+ */
+var Measure = Backbone.Model.extend({
+ initialize: function(args) {
+ this.url = Saiku.session.username + "/discover/" +
+ args.key + "/measures";
+ },
+
+ parse: function(response) {
+ this.set({
+ template: _.template($("#template-measures").html())({
+ measures: response
+ }),
+
+ data: response
+ });
+
+ typeof localStorage !== "undefined" && localStorage && localStorage.setItem("measure." + this.get('key'),
+ JSON.stringify(this));
+
+ return response;
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Member.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Member.js
new file mode 100755
index 0000000..4207fbe
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Member.js
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+/**
+ * Controls member selections
+ */
+var Member = Backbone.Model.extend({
+ initialize: function(args, options) {
+ this.cube = options.cube;
+ var dimension = options.dimension.split("/");
+ this.dimension = dimension[0];
+ this.hierarchy = dimension[2];
+ this.level = dimension[3];
+ },
+
+ url: function() {
+ var url = encodeURI(Saiku.session.username + "/discover/") +
+ this.cube + encodeURI("/dimensions/" + this.dimension +
+ "/hierarchies/" + this.hierarchy + "/levels/" + this.level);
+
+ return url;
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Properties.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Properties.js
new file mode 100755
index 0000000..a7edb55
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Properties.js
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+/**
+ * Maintains query properties like non empty and automatic execution
+ */
+var Properties = Backbone.Model.extend({
+ initialize: function(args, options) {
+ // Keep track of parent query
+ this.query = options.query;
+
+ // Update properties with defaults from settings
+ this.properties = {};
+ _.extend(this.properties, Settings.QUERY_PROPERTIES);
+ if (typeof args != "undefined" && args) {
+ _.extend(this.properties, args);
+ }
+ },
+
+ toggle: function(key) {
+ // Toggle property
+ this.properties[key] = this.properties[key] === 'true' ?
+ 'false' : 'true';
+
+ return this;
+ },
+
+ update: function(async) {
+ // FIXME - this really sucks
+ // Why can't we just use the body?
+ this.attributes = {
+ properties: _.template(
+ "<% _.each(properties, function(property, name) { %>" +
+ "<%= name %> <%= property %>\n" +
+ "<% }); %>"
+ )({ properties: this.properties })
+ };
+ this.save({ async: async });
+ },
+
+ parse: function(response) {
+ // FIXME - POST should return properties as well
+ if (typeof response == "object") {
+ _.extend(this.properties, response);
+ }
+
+ this.query.workspace.trigger('properties:loaded');
+ },
+
+ url: function() {
+ return encodeURI(this.query.url() + "/properties");
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Query.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Query.js
new file mode 100755
index 0000000..84da52e
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Query.js
@@ -0,0 +1,162 @@
+/*
+ * 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,
+
+ initialize: function(args, options) {
+ // Save cube
+ _.extend(this, options);
+
+ // Bind `this`
+ _.bindAll(this, "run", "move_dimension", "reflect_properties");
+
+ // Generate a unique query id
+ this.uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
+ function (c) {
+ var r = Math.random() * 16 | 0,
+ v = c == 'x' ? r : (r & 0x3 | 0x8);
+ return v.toString(16);
+ }).toUpperCase();
+
+ // Initialize properties, action handler, and result handler
+ 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;
+ }
+ },
+
+ run: function(force, mdx) {
+ // 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('You need to put at least one level or measure on Columns and Rows for a valid query.').show();
+ this.workspace.adjust();
+ Saiku.i18n.translate();
+ return;
+ }
+ }
+
+
+ // Run it
+ $(this.workspace.table.el)
+ .html('');
+ $(this.workspace.processing).html(' Running query... [ Cancel ]').show();
+ this.workspace.adjust();
+ this.workspace.trigger('query:fetch');
+ Saiku.i18n.translate();
+ // x
+
+ var message = ' Running query... [ Cancel ]';
+ this.workspace.block(message);
+
+
+ if (this.get('type') == "MDX" && mdx != null) {
+ this.result.save({ mdx: mdx});
+ } else {
+ this.result.fetch();
+ }
+ },
+
+ move_dimension: function(dimension, target, index) {
+ $(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);
+ }
+ }
+ });
+ },
+
+ url: function() {
+ return encodeURI(Saiku.session.username + "/query/" + this.uuid);
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/QueryAction.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/QueryAction.js
new file mode 100755
index 0000000..043ec5d
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/QueryAction.js
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+/**
+ * Model which handles "special" actions against the query
+ * Ex.: selections, swap axis, mdx
+ */
+var QueryAction = Backbone.Model.extend({
+ initialize: function(args, options) {
+ // Keep track of query
+ this.query = options.query;
+
+ // Set default url
+ this.url = this.query.url;
+ },
+
+ get: function(action, options) {
+ this.handle("fetch", action, options);
+ },
+
+ post: function(action, options) {
+ this.handle("save", action, options);
+ },
+
+ put: function(action, options) {
+ this.id = _.uniqueId('queryaction_');
+ this.handle("save", action, options);
+ delete this.id;
+ },
+
+ del: function(action, options) {
+ this.id = _.uniqueId('queryaction_');
+ this.handle("delete", action, options);
+ delete this.id;
+ },
+
+ // Call arbitrary actions against the query
+ handle: function(method, action, options) {
+ // Set query action
+ this.url = this.query.url() + action;
+
+ // Clear out old attributes
+ this.attributes = options.data? options.data : {};
+
+ // Initiate action
+ if (method == "save") {
+ // Handle response from server
+ this.parse = options.success;
+
+ this.save();
+ } else if (method == "delete") {
+ this.destroy(options);
+ } else if (method == "fetch") {
+ this.parse = function() {};
+ this.fetch(options);
+ }
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/QueryScenario.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/QueryScenario.js
new file mode 100755
index 0000000..b301d0d
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/QueryScenario.js
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+var QueryScenario = Backbone.Model.extend({
+ initialize: function(args, options) {
+ // Maintain `this`
+ _.bindAll(this, "attach_listeners", "activate", "clicked_cell", "save_writeback",
+ "cancel_writeback", "check_input");
+
+ this.query = options.query;
+ },
+
+ activate: function() {
+ $(this.query.workspace.el).find("td.data").unbind('click').addClass('cellhighlight').click(this.clicked_cell);
+ },
+
+ attach_listeners: function(args) {
+ if (args.workspace.query && args.workspace.query.properties &&
+ args.workspace.query.properties.properties['org.saiku.connection.scenario'] === "true" &&
+ $(args.workspace.el).find('.query_scenario').hasClass('on'))
+ $(args.workspace.el).find("td.data").click(this.clicked_cell);
+ },
+
+ clicked_cell: function(event) {
+ $target = $(event.target).hasClass('data') ?
+ $(event.target).find('div') : $(event.target);
+ var value = $target.attr('alt');
+ var pos = $target.attr('rel');
+
+ var $input = $("")
+ .keyup(this.check_input)
+ .blur(this.cancel_writeback);
+ $target.html('').append($input);
+ $input.focus();
+ },
+
+ check_input: function(event) {
+ if (event.which == 13) {
+ this.save_writeback(event);
+ } else if (event.which == 27 || event.which == 9) {
+ this.cancel_writeback(event);
+ }
+
+ return false;
+ },
+
+ save_writeback: function(event) {
+ var $input = $(event.target).closest('input');
+ this.set({
+ value: $input.val(),
+ position: $input.parent().attr('rel')
+ });
+ this.save();
+ var value = $input.val();
+ $input.parent().text(value);
+ },
+
+ cancel_writeback: function(event) {
+ var $input = $(event.target).closest('input');
+ $input.parent().text($input.parent().attr('alt'));
+ },
+
+ parse: function() {
+ this.query.run();
+ },
+
+ url: function() {
+ return this.query.url() + "/cell/" + this.get('position') +
+ "/" + this.get('value');
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Repository.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Repository.js
new file mode 100644
index 0000000..b1e6455
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Repository.js
@@ -0,0 +1,104 @@
+/*
+ * 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.
+ */
+
+/**
+ * Repository query
+ */
+
+var RepositoryObject = Backbone.Model.extend( {
+ url: function( ) {
+ var segment = Settings.BIPLUGIN ?
+ "/pentahorepository2/resource" : "/repository2/resource";
+ return encodeURI(Saiku.session.username + segment);
+ }
+} );
+
+var RepositoryAclObject = Backbone.Model.extend( {
+ url: function( ) {
+ var segment = Settings.BIPLUGIN ?
+ "/pentahorepository2/resource" : "/repository2/resource/acl";
+ return encodeURI(Saiku.session.username + segment);
+ },
+ parse: function(response) {
+ if (response != "OK") {
+ _.extend(this.attributes, response);
+ }
+ }
+} );
+
+var SavedQuery = Backbone.Model.extend({
+
+ parse: function(response) {
+ //console.log("response: " + response);
+ //this.xml = response;
+ },
+
+ url: function() {
+ var u = Settings.BIPLUGIN ?
+ encodeURI(Saiku.session.username + "/pentahorepository2/resource")
+ : encodeURI(Saiku.session.username + "/repository2/resource");
+ return u;
+ },
+
+ move_query_to_workspace: function(model, response) {
+ var file = response;
+ var filename = model.get('file');
+ for (var key in Settings) {
+ if (key.match("^PARAM")=="PARAM") {
+ var variable = key.substring("PARAM".length, key.length);
+ var Re = new RegExp("\\$\\{" + variable + "\\}","g");
+ var Re2 = new RegExp("\\$\\{" + variable.toLowerCase() + "\\}","g");
+ file = file.replace(Re,Settings[key]);
+ file = file.replace(Re2,Settings[key]);
+
+ }
+ }
+ //substitui o nome da conexao para usar a atual
+ //i3Geo
+ var xml1 = file.split("connection=");
+ var xml2 = file.split("cube=");
+ var file = xml1[0] + 'connection="' + Settings.NOMECONEXAO + '" cube=' + xml2[1];
+ var query = new Query({
+ xml: file,
+ formatter: Settings.CELLSET_FORMATTER
+ },{
+ name: filename
+ });
+
+ var tab = Saiku.tabs.add(new Workspace({ query: query }));
+ }
+});
+
+/**
+ * Repository adapter
+ */
+var Repository = Backbone.Collection.extend({
+ model: SavedQuery,
+
+ initialize: function(args, options) {
+ this.dialog = options.dialog;
+ },
+
+ parse: function(response) {
+ this.dialog.populate(response);
+ },
+
+ url: function() {
+ var segment = Settings.BIPLUGIN ?
+ "/pentahorepository2/?type=saiku" : "/repository2/?type=saiku";
+ return encodeURI(Saiku.session.username + segment);
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Result.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Result.js
new file mode 100755
index 0000000..04a85fb
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Result.js
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+/**
+ * Holds the resultset for a query, and notifies plugins when resultset updated
+ */
+var Result = Backbone.Model.extend({
+
+ result: null,
+ firstRun: false,
+
+ initialize: function(args, options) {
+ // Keep reference to query
+ this.query = options.query;
+ },
+
+ parse: function(response) {
+ // Show the UI if hidden
+ $(this.workspace).unblock();
+ Saiku.ui.unblock();
+ this.result = response;
+ this.firstRun = true;
+ this.query.workspace.trigger('query:result', {
+ workspace: this.query.workspace,
+ data: response
+ });
+
+ },
+
+ hasRun: function() {
+ return this.firstRun;
+ },
+
+ lastresult: function () {
+ return this.result;
+ },
+
+ url: function() {
+ return encodeURI(this.query.url() + "/result/" + this.query.get('formatter'));
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Session.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Session.js
new file mode 100755
index 0000000..4d1bb48
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/Session.js
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+
+/**
+ * Object which handles authentication and stores connections and cubes
+ * @param username
+ * @param password
+ * @returns {Session}
+ */
+var Session = Backbone.Model.extend({
+ username: null,
+ password: null,
+ sessionid: null,
+
+ initialize: function(args, options) {
+ // Attach a custom event bus to this model
+ _.extend(this, Backbone.Events);
+ _.bindAll(this, "check_session", "process_session", "load_session","login");
+ // Check if credentials are being injected into session
+ if (options && options.username && options.password) {
+ this.username = options.username;
+ this.password = options.password;
+ this.save({username:this.username, password:this.password},{success: this.check_session, error: this.check_session});
+
+ } else {
+ this.check_session();
+ }
+ },
+
+ check_session: function() {
+ if (this.sessionid === null || this.username === null || this.password === null) {
+ this.clear();
+ this.fetch({ success: this.process_session })
+ } else {
+ this.username = encodeURIComponent(options.username);
+ this.load_session();
+ }
+ },
+
+ load_session: function() {
+ this.sessionworkspace = new SessionWorkspace();
+ },
+
+ process_session: function(model, response) {
+ if ((response === null || response.sessionid == null)) {
+ // Open form and retrieve credentials
+ Saiku.ui.unblock();
+ this.form = new LoginForm({ session: this });
+ this.form.render().open();
+ } else {
+ this.sessionid = response.sessionid;
+ this.roles = response.roles;
+ this.username = encodeURIComponent(response.username);
+ this.language = response.language;
+ if (typeof this.language != "undefined" && this.language != Saiku.i18n.locale) {
+ Saiku.i18n.locale = this.language;
+ Saiku.i18n.automatic_i18n();
+ }
+ this.load_session();
+ }
+
+ return this;
+ },
+
+ error: function() {
+ $(this.form.el).dialog('open');
+ },
+
+ login: function(username, password) {
+ // Set expiration on localStorage to one day in the future
+ var expires = (new Date()).getTime() +
+ Settings.LOCALSTORAGE_EXPIRATION;
+ typeof localStorage !== "undefined" && localStorage && localStorage.setItem('expiration', expires);
+
+ this.save({username:username, password:password},{success: this.check_session, error: this.check_session});
+
+ },
+
+ logout: function() {
+ // FIXME - This is a hack (inherited from old UI)
+ Saiku.ui.unblock();
+ $('#header').empty().hide();
+ $('#tab_panel').remove();
+ Saiku.tabs = new TabSet();
+ Saiku.toolbar.remove();
+ Saiku.toolbar = new Toolbar();
+ typeof localStorage !== "undefined" && localStorage && localStorage.clear();
+ this.id = _.uniqueId('queryaction_');
+ this.clear();
+ this.sessionid = null;
+ this.username = null;
+ this.password = null;
+ this.destroy({async: false });
+ //console.log("REFRESH!");
+ document.location.reload(false)
+ delete this.id;
+
+ },
+
+ url: function() {
+
+ return "session";
+ }
+});
diff --git a/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/SessionWorkspace.js b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/SessionWorkspace.js
new file mode 100644
index 0000000..afc9758
--- /dev/null
+++ b/ferramentas/saiku/saiku-server/tomcat/webapps/ROOT/js/saiku/models/SessionWorkspace.js
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+
+/**
+ * Object which handles sessionworkspace and stores connections and cubes
+ * @param username
+ * @param password
+ * @returns {Session}
+ */
+var SessionWorkspace = Backbone.Model.extend({
+
+ initialize: function(args, options) {
+ // Attach a custom event bus to this model
+ _.extend(this, Backbone.Events);
+ _.bindAll(this, "process_datasources", "prefetch_dimensions");
+ this.initialized = false;
+ this.first = true;
+ // Check expiration on localStorage
+ if (typeof localStorage !== "undefined" && localStorage) {
+ if (localStorage.getItem('expiration') && !(localStorage.getItem('expiration') > (new Date()).getTime())) {
+ localStorage.clear();
+ } else if (!localStorage.getItem('saiku-version') || (localStorage.getItem('saiku-version') !== Settings.VERSION) ) {
+ localStorage.clear();
+ }
+ }
+ Saiku.ui.block("Loading datasources....");
+ this.fetch({success:this.process_datasources},{});
+ this.refresh();
+ },
+
+ refresh: function() {
+ typeof localStorage !== "undefined" && localStorage && localStorage.clear();
+ this.clear();
+ localStorage.setItem('saiku-version', Settings.VERSION);
+ this.fetch({success:this.process_datasources},{});
+ },
+
+ destroy: function() {
+ typeof localStorage !== "undefined" && localStorage && localStorage.clear();
+ return false;
+ },
+
+ process_datasources: function(model, response) {
+ // Save session in localStorage for other tabs to use
+ if (typeof localStorage !== "undefined" && localStorage && localStorage.getItem('session') === null) {
+ localStorage.setItem('session', JSON.stringify(response));
+ }
+
+ // Generate cube navigation for reuse
+ this.cube_navigation = _.template($("#template-cubes").html())({
+ connections: response
+ });
+
+
+ // Create cube objects
+ this.dimensions = {};
+ this.measures = {};
+ this.connections = response;
+ _.delay(this.prefetch_dimensions, 20);
+
+ if (!this.initialized) {
+ // Show UI
+ $(Saiku.toolbar.el).prependTo($("#header"));
+ $("#header").show();
+ Saiku.ui.unblock();
+ // Add initial tab
+ Saiku.tabs.render();
+ if (! Settings.ACTION) {
+ Saiku.tabs.add(new Workspace());
+ }
+ // Notify the rest of the application that login was successful
+ Saiku.events.trigger('session:new', {
+ session: this
+ });
+ } else {
+ if (! Settings.ACTION) {
+ Saiku.tabs.add(new Workspace());
+ }
+
+ }
+ },
+
+ prefetch_dimensions: function() {
+ if (! this.measures || ! this.dimensions) {
+ Log.log({
+ Message: "measures or dimensions not initialized",
+ Session: JSON.stringify(this)
+ });
+ return;
+ }
+
+ for(var i = 0; i < this.connections.length; i++) {
+ var connection = this.connections[i];
+ for(var j = 0; j < connection.catalogs.length; j++) {
+ var catalog = connection.catalogs[j];
+ for(var k = 0; k < catalog.schemas.length; k++) {
+ var schema = catalog.schemas[k];
+ for(var l = 0; l < schema.cubes.length; l++) {
+ var cube = schema.cubes[l];
+ var key = connection.name + "/" + catalog.name + "/"
+ + ((schema.name == "" || schema.name == null) ? "null" : schema.name)
+ + "/" + encodeURIComponent(cube.name);
+
+ if (typeof localStorage !== "undefined" && localStorage &&
+ localStorage.getItem("dimension." + key) !== null &&
+ localStorage.getItem("measure." + key) !== null) {
+ this.dimensions[key] = new Dimension(JSON.parse(localStorage.getItem("dimension." + key)));
+ this.measures[key] = new Measure(JSON.parse(localStorage.getItem("measure." + key)));
+ } else {
+ this.dimensions[key] = new Dimension({ key: key });
+ this.measures[key] = new Measure({ key: key });
+ if (Settings.DIMENSION_PREFETCH === true) {
+ this.dimensions[key].fetch();
+ this.measures[key].fetch();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Start routing
+ if (!this.initialized && Backbone.history) {
+ Backbone.history.start();
+ this.initialized = true;
+ }
+ },
+
+ url: function() {
+ if (this.first) {
+ this.first = false;
+ return encodeURI(Saiku.session.username + "/discover");
+ }
+ else {
+ return encodeURI(Saiku.session.username + "/discover/refresh");
+ }
+ }
+});
--
libgit2 0.21.2