Pārlūkot izejas kodu

Added turbolinks

Andrew Kane 8 gadi atpakaļ
vecāks
revīzija
787e30134a

+ 4 - 0
CHANGELOG.md

@@ -1,3 +1,7 @@
+## 1.7.1 [unreleased]
+
+- Added turbolinks
+
 ## 1.7.0
 
 - Added ability to cancel queries on backend for Postgres and Redshift

+ 12 - 4
app/assets/javascripts/blazer/application.js

@@ -1,5 +1,6 @@
 //= require ./jquery
 //= require ./jquery_ujs
+//= require ./turbolinks
 //= require ./list
 //= require ./stupidtable
 //= require ./jquery.stickytableheaders
@@ -19,10 +20,17 @@
 //= require ./Sortable
 //= require ./bootstrap
 
-$( function () {
-  $('.dropdown-toggle').mouseenter( function () {
-    $(this).parent().addClass('open');
-  });
+$(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;
 });
 
 function uuid() {

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 4 - 0
app/assets/javascripts/blazer/turbolinks.js


+ 1 - 1
app/controllers/blazer/dashboards_controller.rb

@@ -66,7 +66,7 @@ module Blazer
         Blazer.transform_statement.call(data_source, statement) if Blazer.transform_statement
         data_source.clear_cache(statement)
       end
-      redirect_to dashboard_path(@dashboard, variable_params)
+      head :ok
     end
 
     protected

+ 1 - 1
app/controllers/blazer/queries_controller.rb

@@ -144,7 +144,7 @@ module Blazer
       process_vars(@statement, @query.data_source)
       Blazer.transform_statement.call(data_source, @statement) if Blazer.transform_statement
       data_source.clear_cache(@statement)
-      redirect_to query_path(@query, variable_params)
+      head :ok
     end
 
     def update

+ 1 - 0
app/views/blazer/checks/_form.html.erb

@@ -66,5 +66,6 @@
       <%= link_to "Delete", check_path(@check), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger" %>
     <% end %>
     <%= f.submit "Save", class: "btn btn-success" %>
+    <%= link_to "Back", :back, class: "btn btn-link" %>
   </p>
 <% end %>

+ 1 - 1
app/views/blazer/checks/index.html.erb

@@ -32,7 +32,7 @@
         </td>
         <td style="text-align: right; padding: 1px;">
           <%= link_to "Edit", edit_check_path(check), class: "btn btn-info" %>
-          <%= link_to "Run Now", run_check_path(check), target: "_blank", class: "btn btn-primary" %>
+          <%= link_to "Run Now", run_check_path(check), class: "btn btn-primary" %>
         </td>
       </tr>
     <% end %>

+ 1 - 16
app/views/blazer/dashboards/_form.html.erb

@@ -46,6 +46,7 @@
       <%= link_to "Delete", dashboard_path(@dashboard), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger" %>
     <% end %>
     <%= f.submit "Save", class: "btn btn-success" %>
+    <%= link_to "Back", :back, class: "btn btn-link" %>
   </p>
 <% end %>
 
@@ -54,20 +55,4 @@
     $(this).parents("li:first").remove();
   });
   Sortable.create($(".list-group").get(0));
-
-  // $("form").submit( function () {
-  //   var query_ids = $("li").map( function () {
-  //     return $(this).attr("data-query-id");
-  //   });
-  //   console.log(query_ids.join(","));
-  //   return false;
-  // });
-
-  // var editableList = Sortable.create($(".list-group").get(0), {
-  //   filter: '.js-remove',
-  //   onFilter: function (evt) {
-  //     var el = editableList.closest(evt.item); // get dragged item
-  //     el && el.parentNode.removeChild(el);
-  //   }
-  // });
 </script>

+ 3 - 3
app/views/blazer/dashboards/show.html.erb

@@ -21,12 +21,12 @@
 <% 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 %>
+    <%= link_to "Refresh", refresh_dashboard_path(@dashboard, variable_params), method: :post, remote: true, class: "refresh-link" %>
   </p>
 <% end %>
 
 <% if @bind_vars.any? %>
-  <form id="bind" method="get" action="<%= dashboard_path(@dashboard, variable_params) %>" class="form-inline" style="margin-bottom: 10px;">
+  <form id="bind" method="get" action="<%= dashboard_path(@dashboard) %>" class="form-inline" style="margin-bottom: 10px;">
     <% date_vars = ["start_time", "end_time"] %>
     <% if (date_vars - @bind_vars).empty? %>
       <% @bind_vars = @bind_vars - date_vars %>
@@ -123,7 +123,7 @@
 
 <% @queries.each_with_index do |query, i| %>
   <div style="padding-top: 10px; clear: both;">
-    <h4 style="text-align: center;"><%= link_to query.friendly_name, query_path(query, variable_params), target: "_blank", style: "color: inherit;" %></h4>
+    <h4 style="text-align: center;"><%= link_to query.friendly_name, query_path(query, variable_params), style: "color: inherit;" %></h4>
     <div id="chart-<%= i %>" class="chart">
       <p class="text-muted">Loading...</p>
     </div>

+ 5 - 2
app/views/blazer/queries/_form.html.erb

@@ -147,11 +147,14 @@
     $("#results").html("")
   })
 
-  $(window).unload(function() {
+  function cancelQuery() {
     if (runningQuery) {
       remoteCancelQuery(runningQuery)
     }
-  })
+  }
+
+  $(window).unload(cancelQuery)
+  $(document).on("turbolinks:click", cancelQuery)
 
   $("#run").click( function (e) {
     e.preventDefault();

+ 1 - 1
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 %>
+          <%= link_to "Refresh", refresh_query_path(@query, variable_params), method: :post, remote: true, class: "refresh-link" %>
         <% end %>
       </p>
     <% end %>

+ 2 - 2
app/views/blazer/queries/show.html.erb

@@ -38,7 +38,7 @@
 <% end %>
 
 <% if @bind_vars.any? %>
-  <form id="bind" method="get" action="<%= query_path(@query, variable_params) %>" class="form-inline" style="margin-bottom: 10px;">
+  <form id="bind" method="get" action="<%= query_path(@query) %>" class="form-inline" style="margin-bottom: 10px;">
     <% date_vars = ["start_time", "end_time"] %>
     <% if (date_vars - @bind_vars).empty? %>
       <% @bind_vars = @bind_vars - date_vars %>
@@ -169,7 +169,7 @@
     // do not highlight really long queries
     // this can lead to performance issues
     if ($("code").text().length < 10000) {
-      hljs.initHighlightingOnLoad();
+      hljs.highlightBlock(document.getElementById("code"));
     }
   </script>
 <% end %>

+ 3 - 2
app/views/layouts/blazer/application.html.erb

@@ -4,9 +4,10 @@
     <title><%= blazer_title ? blazer_title : "Blazer" %></title>
 
     <meta charset="utf-8" />
+    <meta name="turbolinks-cache-control" content="no-cache">
 
-    <%= stylesheet_link_tag "blazer/application" %>
-    <%= javascript_include_tag "blazer/application" %>
+    <%= stylesheet_link_tag "blazer/application", "data-turbolinks-track" => "reload" %>
+    <%= javascript_include_tag "blazer/application", "data-turbolinks-track" => "reload" %>
     <script>
       var runQueriesPath = <%= run_queries_path.to_json.html_safe %>;
       var cancelQueriesPath = <%= cancel_queries_path.to_json.html_safe %>;

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels