Business intelligence made simple
Added turbolinks to buttons and forms
Andrew Kane5b2f570991ac
diff --git a/app/assets/javascripts/blazer/application.js b/app/assets/javascripts/blazer/application.jsindex 7703664a..cbd8ce99 100644--- a/app/assets/javascripts/blazer/application.js+++ b/app/assets/javascripts/blazer/application.js@@ -24,10 +24,6 @@ $(document).on('mouseenter', '.dropdown-toggle', function () {$(this).parent().addClass('open');});-$(document).on('ajax:complete', '.refresh-link', function () {- Turbolinks.visit(window.location.pathname + window.location.search);-});-$(document).on("submit", "form[method=get]", function() {Turbolinks.visit(this.action+(this.action.indexOf('?') == -1 ? '?' : '&')+$(this).serialize());return false;diff --git a/app/assets/stylesheets/blazer/application.css b/app/assets/stylesheets/blazer/application.cssindex fb18a493..9162f134 100644--- a/app/assets/stylesheets/blazer/application.css+++ b/app/assets/stylesheets/blazer/application.css@@ -174,3 +174,7 @@ input.search:focus {#code.expanded {max-height: none;}++.turbolinks-progress-bar {+ visibility: hidden;+}diff --git a/app/controllers/blazer/base_controller.rb b/app/controllers/blazer/base_controller.rbindex 139debd9..c0bd02fe 100644--- a/app/controllers/blazer/base_controller.rb+++ b/app/controllers/blazer/base_controller.rb@@ -80,5 +80,45 @@ module Blazersend(Blazer.user_method) if Blazer.user_method && respond_to?(Blazer.user_method)endhelper_method :blazer_user++ # from turbolinks+ # https://github.com/turbolinks/turbolinks-rails/blob/master/lib/turbolinks/redirection.rb+ def redirect_to(url = {}, options = {})+ turbolinks = options.delete(:turbolinks)++ super.tap do+ if turbolinks != false && request.xhr? && !request.get?+ visit_location_with_turbolinks(location, turbolinks)+ else+ if request.headers["Turbolinks-Referrer"]+ store_turbolinks_location_in_session(location)+ end+ end+ end+ end++ def visit_location_with_turbolinks(location, action)+ visit_options = {+ action: action.to_s == "advance" ? action : "replace"+ }++ script = []+ script << "Turbolinks.clearCache()"+ script << "Turbolinks.visit(#{location.to_json}, #{visit_options.to_json})"++ self.status = 200+ self.response_body = script.join("\n")+ response.content_type = "text/javascript"+ end++ def store_turbolinks_location_in_session(location)+ session[:_turbolinks_location] = location if session+ end++ def set_turbolinks_location_header_from_session+ if session && session[:_turbolinks_location]+ response.headers["Turbolinks-Location"] = session.delete(:_turbolinks_location)+ end+ endendenddiff --git a/app/controllers/blazer/dashboards_controller.rb b/app/controllers/blazer/dashboards_controller.rbindex 9e59f559..c8e6336b 100644--- a/app/controllers/blazer/dashboards_controller.rb+++ b/app/controllers/blazer/dashboards_controller.rb@@ -66,7 +66,7 @@ module BlazerBlazer.transform_statement.call(data_source, statement) if Blazer.transform_statementdata_source.clear_cache(statement)end- head :ok+ redirect_to dashboard_path(@dashboard, variable_params)endprotecteddiff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex 17a17895..92affcf7 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -144,7 +144,7 @@ module Blazerprocess_vars(@statement, @query.data_source)Blazer.transform_statement.call(data_source, @statement) if Blazer.transform_statementdata_source.clear_cache(@statement)- head :ok+ redirect_to query_path(@query, variable_params)enddef updatediff --git a/app/views/blazer/checks/_form.html.erb b/app/views/blazer/checks/_form.html.erbindex ef470745..de601bd8 100644--- a/app/views/blazer/checks/_form.html.erb+++ b/app/views/blazer/checks/_form.html.erb@@ -63,7 +63,7 @@<p class="text-muted">Emails are sent when a check starts failing, and when it starts passing again.<p><% if @check.persisted? %>- <%= link_to "Delete", check_path(@check), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger" %>+ <%= link_to "Delete", check_path(@check), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger", remote: true %><% end %><%= f.submit "Save", class: "btn btn-success" %><%= link_to "Back", :back, class: "btn btn-link" %>diff --git a/app/views/blazer/dashboards/_form.html.erb b/app/views/blazer/dashboards/_form.html.erbindex 6dfdc0c5..79148b52 100644--- a/app/views/blazer/dashboards/_form.html.erb+++ b/app/views/blazer/dashboards/_form.html.erb@@ -43,7 +43,7 @@</div><p><% if @dashboard.persisted? %>- <%= link_to "Delete", dashboard_path(@dashboard), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger" %>+ <%= link_to "Delete", dashboard_path(@dashboard), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger", remote: true %><% end %><%= f.submit "Save", class: "btn btn-success" %><%= link_to "Back", :back, class: "btn btn-link" %>diff --git a/app/views/blazer/dashboards/show.html.erb b/app/views/blazer/dashboards/show.html.erbindex d72c60da..9f99a914 100644--- a/app/views/blazer/dashboards/show.html.erb+++ b/app/views/blazer/dashboards/show.html.erb@@ -21,7 +21,7 @@<% if @data_sources.any? { |ds| ds.cache_mode != "off" } %><p class="text-muted" style="float: right;">Some queries may be cached- <%= link_to "Refresh", refresh_dashboard_path(@dashboard, variable_params), method: :post, remote: true, class: "refresh-link" %>+ <%= link_to "Refresh", refresh_dashboard_path(@dashboard, variable_params), method: :post, remote: true %></p><% end %>diff --git a/app/views/blazer/queries/_form.html.erb b/app/views/blazer/queries/_form.html.erbindex 01a69ad0..5402d81c 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, url: (@query.persisted? ? query_path(@query, variable_params) : queries_path(variable_params)), 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"}, remote: true do |f| %><div class="row"><div id="statement-box" class="col-xs-8"><div class= "form-group">@@ -41,7 +41,7 @@</div><div class="text-right"><% if @query.persisted? %>- <%= link_to "Delete", query_path(@query), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger" %>+ <%= link_to "Delete", query_path(@query), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger", remote: true %><%= f.submit "Fork", class: "btn btn-info" %><% end %><%= f.submit @query.persisted? ? "Update" : "Create", class: "btn btn-success" %>diff --git a/app/views/blazer/queries/run.html.erb b/app/views/blazer/queries/run.html.erbindex 14ac2f08..54b12717 100644--- a/app/views/blazer/queries/run.html.erb+++ b/app/views/blazer/queries/run.html.erb@@ -20,7 +20,7 @@<% end %><% if @query && !params[:data_source] %>- <%= link_to "Refresh", refresh_query_path(@query, variable_params), method: :post, remote: true, class: "refresh-link" %>+ <%= link_to "Refresh", refresh_query_path(@query, variable_params), method: :post, remote: true %><% end %></p><% end %>