Bläddra i källkod

Added query to audits

Andrew Kane 9 år sedan
förälder
incheckning
a29659aebe

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

@@ -16,6 +16,7 @@ module Blazer
 
     def index
       @queries = Blazer::Query.order(:name).includes(:creator)
+      @trending_queries = Blazer::Audit.group(:query_id).where("created_at > ?", 2.days.ago).having("COUNT(*) >= 3").uniq.count(:user_id)
     end
 
     def new
@@ -57,9 +58,12 @@ module Blazer
       process_vars(@statement)
 
       if @success
+        @query = Query.find_by(id: params[:query_id]) if params[:query_id]
+
         # audit
         if Blazer.audit
           audit = Blazer::Audit.new(statement: @statement)
+          audit.query = @query
           audit.user = current_user if respond_to?(:current_user)
           audit.save!
         end
@@ -81,7 +85,6 @@ module Blazer
           end
         end
 
-        @query = Query.find_by(id: params[:query_id]) if params[:query_id]
         @filename = @query.name.parameterize if @query
 
         @min_width_types = (@rows.first || {}).select{|k, v| v.is_a?(Time) or v.is_a?(String) or smart_columns[k] }.keys

+ 1 - 0
app/models/blazer/audit.rb

@@ -1,5 +1,6 @@
 module Blazer
   class Audit < ActiveRecord::Base
     belongs_to :user
+    belongs_to :query
   end
 end

+ 3 - 0
app/views/blazer/queries/index.html.erb

@@ -21,6 +21,9 @@
             <% if query.created_at > 2.days.ago %>
               <small style="font-weight: bold; color: #5cb85c;">NEW</small>
             <% end %>
+            <% if @trending_queries[query.id] %>
+              <small style="font-weight: bold; color: #f60;">TRENDING</small>
+            <% end %>
           </td>
           <td class="creator text-right text-muted">
             <% if (creator = query.creator) and creator.respond_to?(Blazer.user_name) %>

+ 1 - 0
lib/generators/blazer/templates/install.rb

@@ -10,6 +10,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
 
     create_table :blazer_audits do |t|
       t.references :user
+      t.references :query
       t.text :statement
       t.timestamp :created_at
     end