Explorar el Código

Added refresh for dashboards

Andrew Kane hace 8 años
padre
commit
5d8a4d4593

+ 14 - 3
app/controllers/blazer/dashboards_controller.rb

@@ -1,6 +1,6 @@
 module Blazer
   class DashboardsController < BaseController
-    before_action :set_dashboard, only: [:show, :edit, :update, :destroy]
+    before_action :set_dashboard, only: [:show, :edit, :update, :destroy, :refresh]
 
     def index
       @dashboards = Blazer::Dashboard.order(:name)
@@ -29,9 +29,9 @@ module Blazer
 
       @smart_vars = {}
       @sql_errors = []
-      data_sources = @queries.map { |q| Blazer.data_sources[q.data_source] }.uniq
+      @data_sources = @queries.map { |q| Blazer.data_sources[q.data_source] }.uniq
       @bind_vars.each do |var|
-        data_sources.each do |data_source|
+        @data_sources.each do |data_source|
           query = data_source.smart_variables[var]
           if query
             rows, error, cached_at = data_source.run_statement(query)
@@ -58,6 +58,17 @@ module Blazer
       redirect_to dashboards_path
     end
 
+    def refresh
+      @dashboard.queries.each do |query|
+        data_source = Blazer.data_sources[query.data_source]
+        statement = query.statement.dup
+        process_vars(statement)
+        Blazer.transform_statement.call(data_source, statement) if Blazer.transform_statement
+        data_source.clear_cache(statement)
+      end
+      redirect_to dashboard_path(@dashboard, variable_params)
+    end
+
     protected
 
     def dashboard_params

+ 7 - 0
app/views/blazer/dashboards/show.html.erb

@@ -32,6 +32,13 @@
 
 <div style="margin-bottom: 60px;"></div>
 
+<% if @data_sources.any? { |ds| ds.cache } %>
+  <p class="text-muted" style="float: right;">
+    Some queries are cached
+    <%= link_to "Refresh", refresh_dashboard_path(@dashboard, variable_params), method: :post %>
+  </p>
+<% end %>
+
 <% if @bind_vars.any? %>
   <form id="bind" method="get" action="<%= url_for(params) %>" class="form-inline" style="margin-bottom: 10px;">
     <% date_vars = ["start_time", "end_time"] %>

+ 3 - 1
config/routes.rb

@@ -7,6 +7,8 @@ Blazer::Engine.routes.draw do
   resources :checks, except: [:show] do
     get :run, on: :member
   end
-  resources :dashboards
+  resources :dashboards do
+    post :refresh, on: :member
+  end
   root to: "queries#home"
 end