* make it possible to only see diagnostic info in the admin feed, and further diagnostic info of a certain type

This commit is contained in:
Seth Call 2014-08-14 12:44:46 -05:00
parent 154e2954d2
commit 5c9f0da222
2 changed files with 48 additions and 31 deletions

View File

@ -4,33 +4,57 @@ ActiveAdmin.register_page 'Feed' do
# get user information via params
user_id = nil
user_id = params[:feed][:user_id] if params[:feed] && params[:feed][:user_id] != ''
feed_type = 'all'
feed_type = params[:feed][:feed_type] if params[:feed] && !params[:feed][:feed_type].blank?
diagnostic_type = 'all'
diagnostic_type = params[:feed][:diagnostic_type] if params[:feed] && !params[:feed][:diagnostic_type].blank?
user_name = 'All'
user_name = User.find(user_id).to_label if user_id
render :partial => 'form', locals: {user_name: user_name, user_id: user_id }
page = (params[:page] ||= 1).to_i
per_page = 10
per_page = 100
offset = (page - 1) * per_page
# get feed ids
where_sql = ''
where_sql = "where user_id = '#{user_id}'" if user_id
sql_feed_ids = "SELECT id, 'music_sessions' as type, created_at FROM music_sessions #{where_sql}
UNION ALL
SELECT DISTINCT recording_id as id, 'recordings' as type, created_at FROM recorded_tracks #{where_sql}
UNION ALL
SELECT id, 'diagnostics' as type, created_at FROM diagnostics #{where_sql}
where_sql = "WHERE user_id = '#{user_id}'" if user_id
diagnostic_filter_sql = ''
if diagnostic_type != 'all'
if where_sql.blank?
diagnostic_filter_sql = "WHERE type = '#{diagnostic_type}'"
else
diagnostic_filter_sql = "AND type = '#{diagnostic_type}'"
end
end
music_session_sql = "SELECT id, 'music_sessions' as type, created_at FROM music_sessions #{where_sql}"
recordings_sql = "SELECT DISTINCT recording_id as id, 'recordings' as type, created_at FROM recorded_tracks #{where_sql}"
diagnostics_sql = "SELECT id, 'diagnostics' as type, created_at FROM diagnostics #{where_sql} #{diagnostic_filter_sql}"
feeds = []
if feed_type == 'all'
feeds << music_session_sql
feeds << recordings_sql
feeds << diagnostics_sql
elsif feed_type == 'recordings'
feeds << recordings_sql
elsif feed_type == 'sessions'
feeds << music_session_sql
elsif feed_type == 'diagnostics'
feeds << diagnostics_sql
else
raise "Unknown feed_type: #{feed_type}"
end
sql_feed_ids = "#{feeds.join(" UNION ALL ")}
ORDER BY created_at DESC
OFFSET #{offset}
LIMIT #{per_page};"
sql_feed_count = "SELECT COUNT(*) FROM (
SELECT id, 'music_sessions' as type, created_at FROM music_sessions #{where_sql}
UNION ALL
SELECT DISTINCT recording_id as id, 'recordings' as type, created_at FROM recorded_tracks #{where_sql}
UNION ALL
SELECT id, 'diagnostics' as type, created_at FROM diagnostics #{where_sql}
#{feeds.join(" UNION ALL ")}
ORDER BY created_at DESC
) AS IDS;"
feed_count = ActiveRecord::Base.connection.execute(sql_feed_count).values[0][0].to_i
@ -62,8 +86,8 @@ ActiveAdmin.register_page 'Feed' do
columns do
column do
panel "Music Sessions - #{user_name}" do
if sessions.count > 0
panel "Music Sessions - #{user_name}" do
table_for(sessions) do
column :creator do |msh|
link_to msh.creator.to_label, admin_feed_path({feed: {user_id: msh.creator.id}})
@ -96,15 +120,11 @@ ActiveAdmin.register_page 'Feed' do
end
end
end
else
span class: 'text-center' do
para 'No session activities.'
end
end
end
panel "Recordings - #{user_name}" do
if recordings.count > 0
panel "Recordings - #{user_name}" do
table_for(recordings) do
column :starter do |rec|
link_to rec.owner.to_label, admin_feed_path({feed: {user_id: rec.owner.id}})
@ -180,15 +200,11 @@ ActiveAdmin.register_page 'Feed' do
end
end
end
else
span class: 'text-center' do
para 'No recording activities.'
end
end
end
if diagnostics.count > 0
panel "Diagnostics - #{user_name}" do
if diagnostics.count > 0 then
table_for(diagnostics) do
column :user do |d|
span link_to d.user.to_label, admin_feed_path({feed: {user_id: d.user.id}})
@ -206,10 +222,6 @@ ActiveAdmin.register_page 'Feed' do
end
end
end
else
span class: 'text-center' do
para 'No diagnostic activities.'
end
end
end
end

View File

@ -1,6 +1,11 @@
<%= semantic_form_for :feed, url: admin_feed_path, method: :get do |f| %>
<%= f.inputs do %>
<%= f.input :user, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path, :input_html => { :id_element => "#feed_user_id" } %>
<%= f.input :user, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path, :input_html => { :id_element => "#feed_user_id" }, hint: 'If blank, all user info is returned. If not blank, then you will only see activity for that user' %>
<%= f.input :feed_type, as: :select, collection: ['all', 'recordings', 'sessions', 'diagnostics'], hint: "You can choose to only select to see 'recordings', 'sessions', or 'diagnostic info' with this dropdown" %>
<%= f.input :diagnostic_type, as: :select, collection: ['all'].concat(JamRuby::Diagnostic::DIAGNOSTIC_TYPES), hint: "If you select a specific option for Diagnostic type, select 'diagnostics' from the Feed type dropdown to only see diagnostic info of this type" %>
<%= f.input :user_id, :as => :hidden %>
<%= f.actions do %>
<%= f.action :submit, label: 'Submit', :wrapper_html => { :style => "margin-left:5px;" } %>
<% end %>
<% end %>
<% end %>