Business intelligence made simple
Easier to edit queries with variables without sessions
Andrew Kane0903dca92a61
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex 068bec70..9816d805 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -29,7 +29,7 @@ module Blazer@query.creator = current_user if respond_to?(:current_user) && Blazer.user_classif @query.save- redirect_to @query+ redirect_to query_path(@query, variable_params)elserender :newend@@ -37,7 +37,6 @@ module Blazerdef show@statement = @query.statement.dup- session[:blazer_params] = params.except(:controller, :action, :id, :host)process_vars(@statement)@smart_vars = {}@@ -116,7 +115,7 @@ module Blazerdef updateif @query.update(query_params)- redirect_to query_path(@query, session_params.merge(only_path: true))+ redirect_to query_path(@query, variable_params)elserender :editend@@ -180,7 +179,6 @@ module Blazerdef process_vars(statement)@bind_vars = extract_vars(statement)- params = session_params.merge(self.params)@success = @bind_vars.all? { |v| params[v] }if @success@@ -195,9 +193,10 @@ module Blazerendend- def session_params- session[:blazer_params] || {}+ def variable_params+ params.except(:controller, :action, :id, :host, :query, :table_names, :authenticity_token, :utf8, :_method, :commit)end+ helper_method :variable_paramsdef settingsYAML.load(File.read(Rails.root.join("config", "blazer.yml")))diff --git a/app/views/blazer/queries/_form.html.erb b/app/views/blazer/queries/_form.html.erbindex d152048a..7e606a72 100644--- a/app/views/blazer/queries/_form.html.erb+++ b/app/views/blazer/queries/_form.html.erb@@ -2,7 +2,7 @@<div class="alert alert-danger"><%= @query.errors.full_messages.first %></div><% end %>-<%= form_for @query, html: {class: "the_form", autocomplete: "off"} do |f| %>+<%= form_for @query, url: (@query.persisted? ? query_path(@query, variable_params) : queries_path(variable_params)), html: {class: "the_form", autocomplete: "off"} do |f| %><div class="row"><div class="col-xs-8"><div class= "form-group">@@ -85,6 +85,7 @@var error_line = null;var xhr;+ var params = <%= raw json_escape(variable_params.to_json) %>;$("#run").click(function (e) {e.preventDefault();@@ -98,7 +99,7 @@if (xhr) {xhr.abort();}- xhr = $.post("<%= run_queries_path %>", {statement: editor.getValue()}, function (data) {+ xhr = $.post("<%= run_queries_path %>", $.extend({}, params, {statement: editor.getValue()}), function (data) {$("#results").html(data);error_line = /LINE (\d+)/g.exec($("#results").find('.alert-danger').text());diff --git a/app/views/blazer/queries/show.html.erb b/app/views/blazer/queries/show.html.erbindex e551160f..38798b65 100644--- a/app/views/blazer/queries/show.html.erb+++ b/app/views/blazer/queries/show.html.erb@@ -10,8 +10,8 @@</h3></div><div class="col-sm-3 text-right">- <%= link_to "Edit", edit_query_path(@query), class: "btn btn-default" %>- <%= link_to "Fork", new_query_path(statement: @query.statement), class: "btn btn-info" %>+ <%= link_to "Edit", edit_query_path(@query, variable_params), class: "btn btn-default" %>+ <%= link_to "Fork", new_query_path(variable_params.merge(statement: @query.statement)), class: "btn btn-info" %><% if !@error && @success %><%= button_to "Download", run_queries_path(statement: @statement, query_id: @query.id, format: "csv"), class: "btn btn-primary" %>