diff --git a/app/controllers/admin/flag_controller.rb b/app/controllers/admin/flag_controller.rb index 1a7032a..98912d1 100644 --- a/app/controllers/admin/flag_controller.rb +++ b/app/controllers/admin/flag_controller.rb @@ -1,5 +1,5 @@ class Admin::FlagController < AdminController def index - @flags = Flag.page_table.second + @flags = Flag.by_description end end \ No newline at end of file diff --git a/app/helpers/flag_helper.rb b/app/helpers/flag_helper.rb new file mode 100644 index 0000000..0ba010c --- /dev/null +++ b/app/helpers/flag_helper.rb @@ -0,0 +1,7 @@ +module FlagHelper + + def group(flag) + flag.description.group + end + +end diff --git a/app/helpers/group_helper.rb b/app/helpers/group_helper.rb index 138dc21..c0356f2 100644 --- a/app/helpers/group_helper.rb +++ b/app/helpers/group_helper.rb @@ -1,9 +1,9 @@ module GroupHelper def flag_text - if @user_flag.present? then "Unflag" - elsif @flag_count > 0 then "Flag (#{@flag_count})" - else "Flag" + if @user_flag.present? then "Unflag Content" + elsif @flag_count > 0 then "Flag as Inappropriate (#{@flag_count})" + else "Flag as Inappropriate" end end diff --git a/app/models/flag.rb b/app/models/flag.rb index 4288c82..811eb2c 100644 --- a/app/models/flag.rb +++ b/app/models/flag.rb @@ -2,38 +2,29 @@ class Flag < ActiveRecord::Base belongs_to :user belongs_to :description - def self.page_table_for_group(group) - sql = - " - SELECT - g.name as 'group', - d.description as description, - count(*) as num_flags - FROM flags f - Left join descriptions d on d.id = f.description_id - Left join groups g on g.id = d.group_id - WHERE d.group_id= ? - group by f.description_id - order by d.group_id - " - q = [sql, group.id] - Sql.execute(q) + + def self.flags + Flag.includes(:description =>:group).includes(:user) + end + + def self.by_description + flags = Flag.flags.order("groups.name") + + flags.group_by(&:description).map do |description, flags| + description = flags.first.description + flaggers = flags.map {|f| f.user.name}.join("
").html_safe + { + :group => description.group, + :group_name => description.group.name, + :description => description, + :flaggers => flaggers, + :flag_count => flags.length + } + end end - def self.page_table - sql = - " - SELECT - g.name as 'group', - d.description as description, - count(*) as num_flags - FROM flags f - Left join descriptions d on d.id = f.description_id - Left join groups g on g.id = d.group_id - group by f.description_id - order by d.group_id - " - Sql.execute(sql) + def self.group(group) + Flag.by_group.where("groups.id is ?", group.id) end end diff --git a/app/models/group.rb b/app/models/group.rb index 9129c32..6fbde48 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -44,7 +44,7 @@ def self.groups_with_pages end def self.search(name) - like = Rails.env.development? ? "LIKE" : "ILIKE" + like = Rails.env.production? ? "ILIKE" : "LIKE" Group.where("name #{like} ?", "%#{name}%") end diff --git a/app/views/admin/flag/_flag.html.haml b/app/views/admin/flag/_flag.html.haml index 4eac484..6ca55f7 100644 --- a/app/views/admin/flag/_flag.html.haml +++ b/app/views/admin/flag/_flag.html.haml @@ -1,6 +1,5 @@ %tr - %td= flag[0] - %td.page{:style => "position:relative", "rel" => "popover", "data-content" => Description.markdown(flag[1]), "data-original-title" => flag[0]} - = truncate(flag[1], :length => 60) - - %td= flag[2] \ No newline at end of file + %td= link_to flag[:group_name], group_path(flag[:group]) + %td= truncate(flag[:description].description, :length => 60) + %td= flag[:flaggers] + %td= flag[:flag_count] diff --git a/app/views/admin/flag/index.html.haml b/app/views/admin/flag/index.html.haml index ac0cf6b..3c6c061 100644 --- a/app/views/admin/flag/index.html.haml +++ b/app/views/admin/flag/index.html.haml @@ -12,5 +12,6 @@ %tr %th.yellow{:width => "100px"} Group %th.purple Page - %th.blue{:width => "70px"} Count + %th.green Flaggers + %th.blue Flag Count = render :partial => "flag", :collection => @flags \ No newline at end of file diff --git a/app/views/group/index.html.haml b/app/views/group/index.html.haml index e787d5f..94da237 100644 --- a/app/views/group/index.html.haml +++ b/app/views/group/index.html.haml @@ -46,8 +46,10 @@ - else .search-result-found + / Only the variables (length and params) should be bolded below Showing - %b #{@groups.length} search results for + %b #{@groups.length} + search results for %b #{params[:search]} %table.table-striped.search-results - @groups.each do |group| diff --git a/app/views/sidebar/section/_admin_toc.html.haml b/app/views/sidebar/section/_admin_toc.html.haml index d1844fd..e8d226e 100644 --- a/app/views/sidebar/section/_admin_toc.html.haml +++ b/app/views/sidebar/section/_admin_toc.html.haml @@ -3,7 +3,7 @@ %h3.title Admin Section .sidebar-content = link_to "Categories", admin_category_index_path - / = link_to "Flags", admin_flag_index_path + = link_to "Flags", admin_flag_index_path = link_to "Groups", admin_group_index_path = link_to "Pages", admin_description_index_path = link_to "Users", admin_user_index_path \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index bef60e1..a94df00 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ +# Routes for Dartmouth Group Directory +# See how all your routes lay out with "rake routes" + DGD::Application.routes.draw do - + root :to => 'splash#index' namespace :admin do @@ -29,7 +32,11 @@ end end - resources :flag, :only => [:index] + resources :flag, :only => [:index] do + collection do + post 'update' + end + end resources :group_exec, :only => [:index] @@ -67,60 +74,4 @@ match "/about" => "group#about", :as => :about match "/markdown" => "group#markdown", :as => :markdown - # The priority is based upon order of creation: - # first created -> highest priority. - - # Sample of regular route: - # match 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Sample resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Sample resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Sample resource route with more complex sub-resources - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', :on => :collection - # end - # end - - # Sample resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - root :to => 'splash#index' - - # See how all your routes lay out with "rake routes" - - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id(.:format)))' end