Business intelligence made simple
Lighten dependencies
Andrew Kane0de5faf2f409
diff --git a/app/assets/javascripts/blazer/routes.js.erb b/app/assets/javascripts/blazer/routes.js.erbindex 744009d3..eb99e41f 100644--- a/app/assets/javascripts/blazer/routes.js.erb+++ b/app/assets/javascripts/blazer/routes.js.erb@@ -1,26 +1,23 @@-<%#= JsRoutes.generate(engine: Blazer::Engine, prefix: Blazer::Engine.app.url_helpers.root_path) %>--// temp fixvar Routes = {run_queries_path: function() {- return gon.root_path + "queries/run"+ return rootPath + "queries/run"},cancel_queries_path: function() {- return gon.root_path + "queries/cancel"+ return rootPath + "queries/cancel"},schema_queries_path: function(params) {- return gon.root_path + "queries/schema?data_source=" + params.data_source+ return rootPath + "queries/schema?data_source=" + params.data_source},tables_queries_path: function(params) {- return gon.root_path + "queries/tables?data_source=" + params.data_source+ return rootPath + "queries/tables?data_source=" + params.data_source},queries_path: function() {- return gon.root_path + "queries"+ return rootPath + "queries"},query_path: function(id) {- return gon.root_path + "queries/" + id+ return rootPath + "queries/" + id},dashboard_path: function(id) {- return gon.root_path + "dashboards/" + id+ return rootPath + "dashboards/" + id}}diff --git a/app/controllers/blazer/base_controller.rb b/app/controllers/blazer/base_controller.rbindex c470e020..66147066 100644--- a/app/controllers/blazer/base_controller.rb+++ b/app/controllers/blazer/base_controller.rb@@ -19,94 +19,87 @@ module Blazerif Blazer.before_actionbefore_action Blazer.before_action.to_symend- before_action :set_js_routeslayout "blazer/application"private- def process_vars(statement, data_source)- (@bind_vars ||= []).concat(extract_vars(statement)).uniq!- @bind_vars.each do |var|- params[var] ||= Blazer.data_sources[data_source].variable_defaults[var]- end- @success = @bind_vars.all? { |v| params[v] }-- if @success+ def process_vars(statement, data_source)+ (@bind_vars ||= []).concat(extract_vars(statement)).uniq!@bind_vars.each do |var|- value = params[var].presence- if value- if ["start_time", "end_time"].include?(var)- value = value.to_s.gsub(" ", "+") # fix for Quip bug- end+ params[var] ||= Blazer.data_sources[data_source].variable_defaults[var]+ end+ @success = @bind_vars.all? { |v| params[v] }++ if @success+ @bind_vars.each do |var|+ value = params[var].presence+ if value+ if ["start_time", "end_time"].include?(var)+ value = value.to_s.gsub(" ", "+") # fix for Quip bug+ end- if var.end_with?("_at")- begin- value = Blazer.time_zone.parse(value)- rescue- # do nothing+ if var.end_with?("_at")+ begin+ value = Blazer.time_zone.parse(value)+ rescue+ # do nothing+ endend- end- if value =~ /\A\d+\z/- value = value.to_i- elsif value =~ /\A\d+\.\d+\z/- value = value.to_f+ if value =~ /\A\d+\z/+ value = value.to_i+ elsif value =~ /\A\d+\.\d+\z/+ value = value.to_f+ endend+ statement.gsub!("{#{var}}", ActiveRecord::Base.connection.quote(value))end- statement.gsub!("{#{var}}", ActiveRecord::Base.connection.quote(value))endend- end- def parse_smart_variables(var, data_source)- smart_var_data_source =- ([data_source] + Array(data_source.settings["inherit_smart_settings"]).map { |ds| Blazer.data_sources[ds] }).find { |ds| ds.smart_variables[var] }-- if smart_var_data_source- query = smart_var_data_source.smart_variables[var]-- if query.is_a? Hash- smart_var = query.map { |k,v| [v, k] }- elsif query.is_a? Array- smart_var = query.map { |v| [v, v] }- elsif query- result = smart_var_data_source.run_statement(query)- smart_var = result.rows.map { |v| v.reverse }- error = result.error if result.error+ def parse_smart_variables(var, data_source)+ smart_var_data_source =+ ([data_source] + Array(data_source.settings["inherit_smart_settings"]).map { |ds| Blazer.data_sources[ds] }).find { |ds| ds.smart_variables[var] }++ if smart_var_data_source+ query = smart_var_data_source.smart_variables[var]++ if query.is_a? Hash+ smart_var = query.map { |k,v| [v, k] }+ elsif query.is_a? Array+ smart_var = query.map { |v| [v, v] }+ elsif query+ result = smart_var_data_source.run_statement(query)+ smart_var = result.rows.map { |v| v.reverse }+ error = result.error if result.error+ endend- end-- [smart_var, error]- end- def extract_vars(statement)- # strip commented out lines- # and regex {1} or {1,2}- statement.gsub(/\-\-.+/, "").gsub(/\/\*.+\*\//m, "").scan(/\{\w*?\}/i).map { |v| v[1...-1] }.reject { |v| /\A\d+(\,\d+)?\z/.match(v) || v.empty? }.uniq- end- helper_method :extract_vars+ [smart_var, error]+ end- def variable_params- params.except(:controller, :action, :id, :host, :query, :dashboard, :query_id, :query_ids, :table_names, :authenticity_token, :utf8, :_method, :commit, :statement, :data_source, :name, :fork_query_id, :blazer, :run_id).permit!- end- helper_method :variable_params+ def extract_vars(statement)+ # strip commented out lines+ # and regex {1} or {1,2}+ statement.gsub(/\-\-.+/, "").gsub(/\/\*.+\*\//m, "").scan(/\{\w*?\}/i).map { |v| v[1...-1] }.reject { |v| /\A\d+(\,\d+)?\z/.match(v) || v.empty? }.uniq+ end+ helper_method :extract_vars- def blazer_user- send(Blazer.user_method) if Blazer.user_method && respond_to?(Blazer.user_method)- end- helper_method :blazer_user+ def variable_params+ params.except(:controller, :action, :id, :host, :query, :dashboard, :query_id, :query_ids, :table_names, :authenticity_token, :utf8, :_method, :commit, :statement, :data_source, :name, :fork_query_id, :blazer, :run_id).permit!+ end+ helper_method :variable_params- def render_errors(resource)- @errors = resource.errors- action = resource.persisted? ? :edit : :new- render action, status: :unprocessable_entity- end+ def blazer_user+ send(Blazer.user_method) if Blazer.user_method && respond_to?(Blazer.user_method)+ end+ helper_method :blazer_user- def set_js_routes- gon.push(- root_path: root_path- )- end+ def render_errors(resource)+ @errors = resource.errors+ action = resource.persisted? ? :edit : :new+ render action, status: :unprocessable_entity+ endendenddiff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex 01ce4bdd..c82c919c 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -26,12 +26,6 @@ module Blazerdashboard: true}end-- gon.push(- dashboards: @dashboards,- queries: @queries,- more: @more- )enddef indexdiff --git a/app/views/blazer/queries/home.html.erb b/app/views/blazer/queries/home.html.erbindex 012bd4bb..dcecbf24 100644--- a/app/views/blazer/queries/home.html.erb+++ b/app/views/blazer/queries/home.html.erb@@ -50,6 +50,10 @@</div><script>+ <%= blazer_js_var "dashboards", @dashboards %>+ <%= blazer_js_var "queries", @queries %>+ <%= blazer_js_var "more", @more %>+var prepareSearch = function (list) {var i, q, searchStrfor (i = 0; i < list.length; i++) {@@ -70,17 +74,17 @@el: "#queries",data: {searchTerm: "",- more: gon.more,+ more: more,updateCounter: 0},created: function() {- this.listItems = gon.dashboards.concat(gon.queries)+ this.listItems = dashboards.concat(queries)prepareSearch(this.listItems)this.queryIds = {}- for (i = 0; i < gon.queries.length; i++) {- this.queryIds[gon.queries[i].id] = true+ for (i = 0; i < queries.length; i++) {+ this.queryIds[queries[i].id] = true}if (this.more) {diff --git a/app/views/layouts/blazer/application.html.erb b/app/views/layouts/blazer/application.html.erbindex 36cfbdd8..5dcf297f 100644--- a/app/views/layouts/blazer/application.html.erb+++ b/app/views/layouts/blazer/application.html.erb@@ -7,7 +7,9 @@<%= stylesheet_link_tag "blazer/application" %><%= javascript_include_tag "blazer/application" %>- <%= Gon::Base.render_data %>+ <script>+ <%= blazer_js_var "rootPath", root_path %>+ </script><% if blazer_maps? %><%= stylesheet_link_tag "https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.css" %><%= javascript_include_tag "https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.js" %>diff --git a/blazer.gemspec b/blazer.gemspecindex 4dc74773..33c8be62 100644--- a/blazer.gemspec+++ b/blazer.gemspec@@ -20,8 +20,6 @@ Gem::Specification.new do |spec|spec.add_dependency "rails"spec.add_dependency "chartkick"spec.add_dependency "safely_block", ">= 0.1.1"- spec.add_dependency "js-routes"- spec.add_dependency "gon"spec.add_development_dependency "bundler", "~> 1.7"spec.add_development_dependency "rake", "~> 10.0"diff --git a/lib/blazer.rb b/lib/blazer.rbindex c95660e6..ba4c4b33 100644--- a/lib/blazer.rb+++ b/lib/blazer.rb@@ -2,8 +2,6 @@ require "csv"require "yaml"require "chartkick"require "safely/core"-require "js-routes"-require "gon"require "blazer/version"require "blazer/data_source"require "blazer/result"