Skip to content

Business intelligence made simple

Added query to audits

Andrew Kanea29659aebe9e
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index 1d044c94..d22b1be5 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/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
diff --git a/app/models/blazer/audit.rb b/app/models/blazer/audit.rb
index 60f46245..cf4cea6d 100644
--- a/app/models/blazer/audit.rb
+++ b/app/models/blazer/audit.rb
@@ -1,5 +1,6 @@
module Blazer
class Audit < ActiveRecord::Base
belongs_to :user
+ belongs_to :query
end
end
diff --git a/app/views/blazer/queries/index.html.erb b/app/views/blazer/queries/index.html.erb
index 5d9afe72..26ebfae6 100644
--- a/app/views/blazer/queries/index.html.erb
+++ b/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) %>
diff --git a/lib/generators/blazer/templates/install.rb b/lib/generators/blazer/templates/install.rb
index cd90e93a..3582c405 100644
--- a/lib/generators/blazer/templates/install.rb
+++ b/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