Browse files

Add Filter by Track UI to admin proposal index view.

Retrieves proposals by track for current year only.

Fixes #66
  • Loading branch information...
1 parent e583d74 commit 0cc7fa883a51adb564851edc9beedfb3b3ae3a7e @marioaquino marioaquino committed Apr 22, 2012
View
1 .gitignore
@@ -57,6 +57,7 @@ nbproject
# Vim
*.swp
*.swo
+tmp/tags
# RubyMine
.idea
View
9 features/review_submissions.feature
@@ -151,6 +151,13 @@ Feature: As a conference talks reviewer
When I see all proposals
Then the proposal I rated should have a 3 out of 5 star rating
-
+ @66
+ Scenario: View proposals by track
+ Given I am a logged in reviewer
+ And there are proposals with tracks
+ When I filter by one of the proposal tracks
+ Then I only see proposals from that track
+
+
View
22 features/step_definitions/proposal_steps.rb
@@ -71,6 +71,11 @@
Factory(:proposal).rate(3, User.last, 'appeal')
end
+Given /^there are proposals with tracks$/ do
+ Factory(:proposal) #default track
+ Factory(:proposal, :talk => Factory(:big_data_talk))
+end
+
When /^I rate the proposal with (\d+) stars$/ do |rating|
click_link rating
end
@@ -79,6 +84,13 @@
visit admin_proposals_path
end
+When /^I filter by one of the proposal tracks$/ do
+ visit admin_proposals_path
+ assert_record_count 2
+ check 'Big Data'
+ click_on 'Filter'
+end
+
Then /^the proposal I rated should have a (\d+) out of (\d+) star rating$/ do |rating, maximum|
page.should have_content("Your rating: #{rating} out of #{maximum}")
end
@@ -109,3 +121,13 @@ def check_email(body)
page.should have_css('li#proposal-1 span.stars-3')
end
+Then /^I only see proposals from that track$/ do
+ assert_record_count 1
+end
+
+def assert_record_count(number)
+ within('#sortable_list') do
+ page.should have_css('li.record', :count => number)
+ end
+end
+
View
11 public/stylesheets/admin.css
@@ -19,7 +19,7 @@
display: inline-block;
}
-#statusForm input[type="submit"] {
+#statusForm input[type='submit'] {
margin: 1.5em 0 0 8em;
width: 8em;
float: left;
@@ -35,3 +35,12 @@
float: left;
}
+#filter input[type='checkbox'] {
+ margin: 0 8px 0 0;
+ float: left;
+}
+
+#filter input[type='submit'] {
+ margin-top: 12px;
+}
+
View
5 spec/factories.rb
@@ -98,6 +98,11 @@
t.video_approval 'Yes'
t.duration '50 Minutes'
t.speakers { [Factory(:speaker)] }
+ t.track { Factory(:track) }
+end
+
+Factory.define :big_data_talk, :parent => :talk do |t|
+ t.track { Factory(:talk_track) }
end
Factory.define :keynote_speaker, :parent => :speaker do |ks|
View
7 vendor/engines/proposals/app/controllers/admin/proposals_controller.rb
@@ -13,14 +13,15 @@
#- limitations under the License.
#-
-
+require 'will_paginate/array'
module Admin
class ProposalsController < Admin::BaseController
expose(:proposal)
expose(:current_proposals) { proposals_for_format.paginate({:page => params[:page], :per_page => 20})}
expose(:session_times) { SessionTime.current_year }
expose(:format) { params[:format] || 'talk' }
+ expose(:filters) { params[:filter] || [] }
expose(:format_name) { format.capitalize.pluralize }
expose(:tracks) { Track.current_year }
@@ -46,7 +47,9 @@ def rate
end
def proposals_for_format
- if (Proposal.format_options.include?(format))
+ if !filters.empty?
+ Proposal.by_current_track filters
+ elsif Proposal.format_options.include?(format)
Proposal.current.send(format)
else
[]
View
11 vendor/engines/proposals/app/models/proposal.rb
@@ -31,17 +31,20 @@ class Proposal < ActiveRecord::Base
accepts_nested_attributes_for :talk
+ def self.current_year
+ DateTime.parse("Jan 1, #{Time.now.year}")
+ end
+
scope :pending, lambda {
where(:status => ['submitted', 'under review'])
}
scope :current, lambda {
- where('created_at > ?', DateTime.parse("Jan 1, #{Time.now.year}"))
+ where('created_at > ?', current_year)
}
- def self.by_taggings(*tags)
- joins(:talk => :tags).where('tags.name' => tags).uniq
- end
+ scope :by_current_track,
+ lambda {|track_name| joins(:talk => :track).where('tracks.name' => track_name).where('proposals.created_at > ?', current_year ) }
format_options.each {|format| scope format, :conditions => { :format => format } }
View
16 vendor/engines/proposals/app/views/admin/proposals/index.html.erb
@@ -35,5 +35,21 @@
<% if current_user.has_role? :organizer -%>
<li><%= link_to "Export Proposals", export_admin_proposals_path("csv") %></li>
<% end -%>
+ <% if format == 'talk' %>
+ <li>
+ <%= field_set_tag 'Filter By Track', :id => 'filter' do %>
+ <%= form_tag admin_proposals_path, :method => 'get' do %>
+ <%= hidden_field_tag :track_filter, true %>
+ <% tracks.each do |track| %>
+ <div>
+ <%= check_box_tag "filter[]", track.name, filters.include?(track.name) %>
+ <%= label_tag "filter[]", track.name %>
+ </div>
+ <% end %>
+ <%= submit_tag 'Filter' %>
+ <% end %>
+ <% end %>
+ </li>
+ <% end %>
</ul>
</div>
View
49 vendor/engines/proposals/spec/controllers/admin/proposals_controller_spec.rb
@@ -24,6 +24,55 @@
load(File.join(File.dirname(__FILE__),'..','..','..','app', 'controllers','admin', 'proposals_controller.rb'))
end
+ describe '#current_proposals' do
+ let(:paginated_proposals) { mock 'paginated_proposals' }
+ let(:proposals) { mock 'proposals' }
+
+ context 'proposals are filtered' do
+ let(:param) { ['foo'] }
+
+ login_admin
+
+ it 'returns filtered proposals based on params' do
+ Proposal.should_receive(:by_current_track).with(param).and_return(proposals)
+ proposals.should_receive(:paginate).with({:page => nil, :per_page => 20}).and_return(paginated_proposals)
+
+ get :index, :filter => param
+
+ controller.current_proposals.should == paginated_proposals
+ end
+ end
+
+ context 'proposals with supported format' do
+ let(:current_proposal) { mock 'current proposal' }
+ let(:formats) { [ format ] }
+ let(:format) { 'foo' }
+
+ it 'returns proposals from the supplied format' do
+ Proposal.should_receive(:format_options).and_return(formats)
+ Proposal.should_receive(:current).and_return(current_proposal)
+ current_proposal.should_receive(:send).with(format).and_return(proposals)
+ proposals.should_receive(:paginate).with({:page => nil, :per_page => 20}).and_return(paginated_proposals)
+
+ get :index, :format => format
+
+ controller.current_proposals.should == paginated_proposals
+
+ end
+ end
+
+ context 'proposals with unsupported format' do
+ let(:formats) { [] }
+ it 'returns an empty list' do
+ Proposal.should_receive(:format_options).and_return(formats)
+
+ get :index, :format => 'foo'
+
+ controller.current_proposals.should be_empty
+ end
+ end
+ end
+
context 'role checking' do
login_admin
View
11 vendor/engines/proposals/spec/models/proposal_spec.rb
@@ -297,4 +297,15 @@ def check_one_comment_list(comment_list, title, text)
subject.rejected?.should be_false
end
end
+
+ describe '.by_current_track' do
+ let!(:proposal) { Factory(:proposal) }
+ let(:track) { 'Ruby' }
+
+ before { Factory(:proposal, :talk => Factory(:big_data_talk)) }
+
+ it 'returns proposals from the current year for a given track name' do
+ described_class.by_current_track(track).should == [proposal]
+ end
+ end
end
View
4 vendor/engines/proposals/spec/views/admin/proposals/index.html.erb_spec.rb
@@ -32,15 +32,19 @@ def role_check(val = false)
it "hides export link for non-organizers" do
view.stub(:current_user).and_return(role_check)
+ view.stub(:format).and_return('talk')
view.stub(:format_name).and_return('Talks')
+ view.stub(:tracks).and_return([])
view.stub(:current_proposals).and_return([])
render
rendered.should_not =~ /Export Proposals/
end
it "shows the Export Pending Proposals link for organizers" do
view.stub(:current_user).and_return(role_check(true))
+ view.stub(:format).and_return('talk')
view.stub(:format_name).and_return('Talks')
+ view.stub(:tracks).and_return([])
view.stub(:current_proposals).and_return([])
render
rendered.should =~ /Export Proposals/

0 comments on commit 0cc7fa8

Please sign in to comment.