From b5cb7526b8d505b5b5fcaec96f5088019cfabdaa Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Sun, 13 May 2012 16:06:38 -0400 Subject: [PATCH 1/9] Enabled Flags page. --- app/controllers/admin/flag_controller.rb | 4 +- .../sidebar/section/_admin_toc.html.haml | 2 +- config/routes.rb | 67 +++---------------- 3 files changed, 13 insertions(+), 60 deletions(-) diff --git a/app/controllers/admin/flag_controller.rb b/app/controllers/admin/flag_controller.rb index 1a7032a..229df3e 100644 --- a/app/controllers/admin/flag_controller.rb +++ b/app/controllers/admin/flag_controller.rb @@ -1,5 +1,7 @@ class Admin::FlagController < AdminController def index - @flags = Flag.page_table.second + if Flag.page_table.present? + @flags = Flag.page_table.second + end end end \ No newline at end of file diff --git a/app/views/sidebar/section/_admin_toc.html.haml b/app/views/sidebar/section/_admin_toc.html.haml index d1844fd..a150388 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 # TODO: implement this = 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 From 887941db2fa41b6a5f0d415a09b96d370616d1b2 Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Sun, 13 May 2012 17:10:00 -0400 Subject: [PATCH 2/9] Only variables should be bolded in search results --- app/views/group/index.html.haml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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| From fa6408010c77d1e73eed7b52b9516394147dd8fd Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Sun, 13 May 2012 18:50:53 -0400 Subject: [PATCH 3/9] Fixed problem with SQL query in production vs devel/test --- app/models/group.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ae6ce79311e029df985723d1ecc0bd0598c6d57d Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Sun, 13 May 2012 18:51:50 -0400 Subject: [PATCH 4/9] Update Flagged Pages page so that groups link to their group page. A rather inefficient query if you ask me, perhaps there is a more direct method (line 2). --- app/views/admin/flag/_flag.html.haml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/views/admin/flag/_flag.html.haml b/app/views/admin/flag/_flag.html.haml index 4eac484..2b6a63c 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]} + %td= link_to flag[0], group_path(Group.search(flag[0]).first) + %td.page{:style => "position:relative", "rel" => "popover", "data-original-title" => flag[0]} = truncate(flag[1], :length => 60) - - %td= flag[2] \ No newline at end of file + %td= flag[2] From 742394d58856510387e2f7fdae4580ed8a83d22d Mon Sep 17 00:00:00 2001 From: Jason Laster Date: Sun, 13 May 2012 20:31:06 -0400 Subject: [PATCH 5/9] remove sql --- app/controllers/admin/flag_controller.rb | 4 +-- app/helpers/flag_helper.rb | 7 +++++ app/models/flag.rb | 39 ++++++------------------ app/views/admin/flag/_flag.html.haml | 7 ++--- app/views/admin/flag/index.html.haml | 2 +- 5 files changed, 21 insertions(+), 38 deletions(-) create mode 100644 app/helpers/flag_helper.rb diff --git a/app/controllers/admin/flag_controller.rb b/app/controllers/admin/flag_controller.rb index 229df3e..827df63 100644 --- a/app/controllers/admin/flag_controller.rb +++ b/app/controllers/admin/flag_controller.rb @@ -1,7 +1,5 @@ class Admin::FlagController < AdminController def index - if Flag.page_table.present? - @flags = Flag.page_table.second - end + @flags = Flag.by_group 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/models/flag.rb b/app/models/flag.rb index 4288c82..dbcbb9f 100644 --- a/app/models/flag.rb +++ b/app/models/flag.rb @@ -2,38 +2,17 @@ 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_group + Flag.flags.order("groups.name") 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/views/admin/flag/_flag.html.haml b/app/views/admin/flag/_flag.html.haml index 2b6a63c..6627a25 100644 --- a/app/views/admin/flag/_flag.html.haml +++ b/app/views/admin/flag/_flag.html.haml @@ -1,5 +1,4 @@ %tr - %td= link_to flag[0], group_path(Group.search(flag[0]).first) - %td.page{:style => "position:relative", "rel" => "popover", "data-original-title" => flag[0]} - = truncate(flag[1], :length => 60) - %td= flag[2] + %td= link_to group(flag).name, group_path(group(flag)) + %td= truncate(flag.description.description, :length => 60) + %td= flag.description.user.name diff --git a/app/views/admin/flag/index.html.haml b/app/views/admin/flag/index.html.haml index ac0cf6b..64df24f 100644 --- a/app/views/admin/flag/index.html.haml +++ b/app/views/admin/flag/index.html.haml @@ -12,5 +12,5 @@ %tr %th.yellow{:width => "100px"} Group %th.purple Page - %th.blue{:width => "70px"} Count + %th.green Authors = render :partial => "flag", :collection => @flags \ No newline at end of file From 43f88137411e811eeb9a6948dca9b14ca336155a Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Sun, 13 May 2012 20:41:50 -0400 Subject: [PATCH 6/9] Changed flagging text --- app/helpers/group_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/group_helper.rb b/app/helpers/group_helper.rb index 138dc21..4059df4 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" + if @user_flag.present? then "Unflag Content" elsif @flag_count > 0 then "Flag (#{@flag_count})" - else "Flag" + else "Flag as Inappropriate" end end From 3fbc01622bbd6fed5ba04b88392f2fc93b2f52db Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Sun, 13 May 2012 20:47:56 -0400 Subject: [PATCH 7/9] Removed TODO comment --- app/views/sidebar/section/_admin_toc.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/sidebar/section/_admin_toc.html.haml b/app/views/sidebar/section/_admin_toc.html.haml index a150388..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 # TODO: implement this + = 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 From 7dd8ee06c081721116adb61f589b2380ad35644e Mon Sep 17 00:00:00 2001 From: Jason Laster Date: Sun, 13 May 2012 20:49:24 -0400 Subject: [PATCH 8/9] add group by description --- app/controllers/admin/flag_controller.rb | 2 +- app/models/flag.rb | 16 ++++++++++++++-- app/views/admin/flag/_flag.html.haml | 7 ++++--- app/views/admin/flag/index.html.haml | 3 ++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/flag_controller.rb b/app/controllers/admin/flag_controller.rb index 827df63..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.by_group + @flags = Flag.by_description end end \ No newline at end of file diff --git a/app/models/flag.rb b/app/models/flag.rb index dbcbb9f..811eb2c 100644 --- a/app/models/flag.rb +++ b/app/models/flag.rb @@ -7,8 +7,20 @@ def self.flags Flag.includes(:description =>:group).includes(:user) end - def self.by_group - Flag.flags.order("groups.name") + 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.group(group) diff --git a/app/views/admin/flag/_flag.html.haml b/app/views/admin/flag/_flag.html.haml index 6627a25..6ca55f7 100644 --- a/app/views/admin/flag/_flag.html.haml +++ b/app/views/admin/flag/_flag.html.haml @@ -1,4 +1,5 @@ %tr - %td= link_to group(flag).name, group_path(group(flag)) - %td= truncate(flag.description.description, :length => 60) - %td= flag.description.user.name + %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 64df24f..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.green Authors + %th.green Flaggers + %th.blue Flag Count = render :partial => "flag", :collection => @flags \ No newline at end of file From 928278aae9f4f3dcdfb6d9545c077011d34eb537 Mon Sep 17 00:00:00 2001 From: Avery Yen Date: Sun, 13 May 2012 21:18:02 -0400 Subject: [PATCH 9/9] Changed text of Flag (count) -> Flag as Inappropriate (count). --- app/helpers/group_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/group_helper.rb b/app/helpers/group_helper.rb index 4059df4..c0356f2 100644 --- a/app/helpers/group_helper.rb +++ b/app/helpers/group_helper.rb @@ -2,7 +2,7 @@ module GroupHelper def flag_text if @user_flag.present? then "Unflag Content" - elsif @flag_count > 0 then "Flag (#{@flag_count})" + elsif @flag_count > 0 then "Flag as Inappropriate (#{@flag_count})" else "Flag as Inappropriate" end end