Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/phases'. Closes euruko2013#15.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosd committed Apr 21, 2013
2 parents b33c68a + 5939495 commit 37ab0f5
Show file tree
Hide file tree
Showing 24 changed files with 2,909 additions and 923 deletions.
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
check_authorization

helper_method :current_user, :user_signed_in?
helper_method :current_user, :user_signed_in?, :current_phase

before_filter :reload_settings if Rails.env.development?

Expand Down Expand Up @@ -36,4 +36,8 @@ def user_signed_in?
def current_user
@current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
end

def current_phase
@current_phase ||= Phase.current
end
end
19 changes: 16 additions & 3 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ def index
authorize! :see, :dashboard

@your_proposals = current_user.proposals
@proposals_you_should_look_at = current_user.proposals_you_should_look_at.limit(5)
@proposals_that_have_changed = current_user.proposals_that_have_changed
@proposals_that_have_been_withdrawn = current_user.proposals_that_have_been_withdrawn

if current_phase.new_submissions_allowed? || current_phase.submission_editing_allowed?
@proposals_you_should_look_at = current_user.proposals_you_should_look_at.limit(5)
end

if current_phase.submission_editing_allowed?
@proposals_that_have_changed = current_user.proposals_that_have_changed
end

if current_phase.voting_allowed?
@unvoted_proposals = current_user.proposals_without_own_votes.limit(5)
end

if current_phase.submission_withdrawal_allowed?
@proposals_that_have_been_withdrawn = current_user.proposals_that_have_been_withdrawn
end
end
end
1 change: 1 addition & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def index

@withdrawn_proposals = Proposal.withdrawn.all
@proposals = Proposal.active.order('created_at desc').all
@suggested_proposal = current_user.proposals_without_own_votes.active.sample || Proposal.active.sample if current_user

respond_with @proposals
end
Expand Down
17 changes: 12 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def remind_account_for_tickets
end

def remind_account_for_signup_reason
current_user && !current_user.signup_reason.present? && !request.path[/user/] && can?(:edit, current_user)
current_phase.in?(Phase::ZERO, Phase::ONE) && current_user && !current_user.signup_reason.present? && !request.path[/user/] && can?(:edit, current_user)
end

def remind_account_for_author_bio
current_phase.in?(Phase::INTERLUDE, Phase::TWO) && current_user && !current_user.signup_reason.present? && current_user.proposals.present? && !request.path[/user/] && can?(:edit, current_user)
end

def avatar_url(user, bigger=false)
Expand Down Expand Up @@ -136,15 +140,18 @@ def authentication_links(container = :p)
['Facebook', '/auth/facebook']].map { |name, url| content_tag container, link_to(name, url) }.join("\n").html_safe
end

def countdown_to_submissions_end
submissions_end = DateTime.parse(Settings.submissions_end)
if submissions_end > DateTime.now
content_tag :span, '', id: 'counter', data: {countdown_end: DateTime.parse(Settings.submissions_end).to_i * 1000}
def countdown_to(phase_end)
if phase_end > DateTime.now
content_tag :span, '', id: 'counter', data: {countdown_end: phase_end.to_i * 1000}
else
content_tag :span, 'no time'
end
end

def countdown_to_phase_end
countdown_to current_phase.ending_at
end

protected
def markdown_parser(options = {})
@markdown_parser ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML,
Expand Down
26 changes: 21 additions & 5 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Ability

# See the wiki for how to define abilities:
# https://github.com/ryanb/cancan/wiki/Defining-Abilities
def initialize(user)
def initialize(user, phase = Phase.current)
user ||= User.new

# Everyone
Expand All @@ -22,17 +22,33 @@ def initialize(user)
can :see, :my_motivation
can [:update], User, :id => user.id

can [:update, :create, :withdraw, :republish, :see_votes], Proposal, :proposer_id => user.id
if phase.new_submissions_allowed?
can [:create], Proposal, :proposer_id => user.id
end

if phase.submission_editing_allowed?
can [:update], Proposal, :proposer_id => user.id
end

if phase.submission_withdrawal_allowed?
can [:withdraw, :republish], Proposal, :proposer_id => user.id
end

can [:see_votes], Proposal, :proposer_id => user.id

can [:create], Suggestion, :author_id => user.id
if phase.new_suggestions_allowed?
can [:create], Suggestion, :author_id => user.id
end

if user.moderator?
can :update, Suggestion
can :see, :moderator_dashboard
end

can [:vote], Proposal
cannot [:vote], Proposal, :proposer_id => user.id
if phase.voting_allowed?
can [:vote], Proposal
cannot [:vote], Proposal, :proposer_id => user.id
end
end
end
end
123 changes: 123 additions & 0 deletions app/models/phase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
class Phase
def self.current
now = DateTime.now
all.detect { |phase| now >= phase.starting_at && now < phase.ending_at }
end

def self.all
[ZERO, ONE, INTERLUDE, TWO, CONFIRMATION, LINEUP]
end

def self.last_submission_date
ONE.ending_at
end

def self.last_voting_date
INTERLUDE.ending_at
end

attr_accessor :name

attr_accessor :main_text
attr_accessor :countdown_text

attr_accessor :starting_at
attr_accessor :ending_at

attr_accessor :new_submissions_allowed
alias_method :new_submissions_allowed?, :new_submissions_allowed

attr_accessor :submission_editing_allowed
alias_method :submission_editing_allowed?, :submission_editing_allowed

attr_accessor :new_suggestions_allowed
alias_method :new_suggestions_allowed?, :new_suggestions_allowed

attr_accessor :voting_allowed
alias_method :voting_allowed?, :voting_allowed

attr_accessor :submission_withdrawal_allowed
alias_method :submission_withdrawal_allowed?, :submission_withdrawal_allowed

ZERO = Phase.new.tap do |p|
p.name = "Before the beginning"
p.main_text = "Be part of #{Settings.event_name}: we highly encourage you to submit as many proposals as you want, help the authors make theirs better and finally select the most interesting ones for the final agenda! What are you waiting for?"
p.countdown_text = "before the submissions open!"
p.starting_at = DateTime.new(1970, 1, 1)
p.ending_at = DateTime.parse('2013-03-28T00:00:00+2')

p.new_submissions_allowed = false
p.submission_editing_allowed = false
p.voting_allowed = false
p.new_suggestions_allowed = false
p.submission_withdrawal_allowed = false
end.freeze

ONE = Phase.new.tap do |p|
p.name = "Phase 1: Submissions"
p.main_text = "Be part of #{Settings.event_name}: we highly encourage you to submit as many proposals as you want, help the authors make theirs better and finally select the most interesting ones for the final agenda! What are you waiting for?"
p.countdown_text = "to submit, refine and discuss proposals!"
p.starting_at = DateTime.parse('2013-03-28T00:00:00+2')
p.ending_at = DateTime.parse('2013-04-24T00:00:00+3')

p.new_submissions_allowed = true
p.submission_editing_allowed = true
p.voting_allowed = true
p.new_suggestions_allowed = true
p.submission_withdrawal_allowed = true
end.freeze

INTERLUDE = Phase.new.tap do |p|
p.name = "Interlude"
p.main_text = "Make it <em>your</em> #{Settings.event_name}: select the finalists before the grand voting! We highly encourage you to go through every single proposal select the most interesting ones. After all, this is what the conference is all about! What are you waiting for?"
p.countdown_text = "to cast your votes that will define the finalists!"
p.starting_at = DateTime.parse('2013-04-24T00:00:00+3')
p.ending_at = DateTime.parse('2013-04-29T00:00:00+3')

p.new_submissions_allowed = false
p.submission_editing_allowed = false
p.voting_allowed = true
p.new_suggestions_allowed = false
p.submission_withdrawal_allowed = true
end.freeze

TWO = Phase.new.tap do |p|
p.name = "Phase 2: Final voting"
p.main_text = "This is it! This is the time you define #{Settings.event_name}! Make <strong>your</strong> ideal lineup."
p.countdown_text = "to define the conference schedule!"
p.starting_at = DateTime.parse('2013-04-29T00:00:00+3')
p.ending_at = DateTime.parse('2013-05-06T00:00:00+3')

p.new_submissions_allowed = false
p.submission_editing_allowed = false
p.voting_allowed = false
p.new_suggestions_allowed = false
p.submission_withdrawal_allowed = true
end.freeze

CONFIRMATION = Phase.new.tap do |p|
p.name = "Speakers confirmation"
p.main_text = ""
p.starting_at = DateTime.parse('2013-05-06T00:00:00+3')
p.ending_at = DateTime.parse('2013-05-09T00:00:00+3')

p.new_submissions_allowed = false
p.submission_editing_allowed = false
p.voting_allowed = false
p.new_suggestions_allowed = false
p.submission_withdrawal_allowed = true
end.freeze

LINEUP = Phase.new.tap do |p|
p.name = "Lineup announcement"
p.main_text = ""
p.starting_at = DateTime.parse('2013-05-09T00:00:00+3')
p.ending_at = DateTime.parse('2100-01-01T00:00:00+2')

p.new_submissions_allowed = false
p.submission_editing_allowed = false
p.voting_allowed = false
p.new_suggestions_allowed = false
p.submission_withdrawal_allowed = false
end.freeze
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def proposals_you_should_look_at
Proposal.active.without_suggestions_from(self).without_votes_from(self).not_proposed_by(self)
end

def proposals_without_own_votes
Proposal.active.without_votes_from(self).not_proposed_by(self)
end

def proposals_that_have_changed
proposals_of_interest.active.not_proposed_by(self).select { |p| p.updated_at > p.suggestions.by(self).maximum(:updated_at) }
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/_moderator_dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%
submissions_start = DateTime.parse(Settings.submissions_start).to_date
submissions_start = Phase::ONE.starting_at.to_date

proposals = Proposal.scoped
suggestions = Suggestion.scoped
Expand Down
26 changes: 21 additions & 5 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

<h2>Your proposals</h2>

<div class="alert">
You have still <%= countdown_to_submissions_end %> to submit or edit a proposal!
Since proposals are anonymised, other users will not see that you are the author of these. <%= link_to "Read more about the process", about_path %>.
</div>
<% if can? :create, Proposal %>
<div class="alert">
You have still <%= countdown_to Phase.last_submission_date %> to submit or edit a proposal!
Since proposals are anonymised, other users will not see that you are the author of these. <%= link_to "Read more about the process", about_path %>.
</div>
<% end %>

<% if @your_proposals.present? %>
<ul id="your-proposals" class="proposals">
Expand All @@ -22,7 +24,9 @@
</ul>
<% end %>

<p><%= link_to "Propose #{'another' if @your_proposals.present?} talk", new_proposal_path, class: "btn btn-primary" %></p>
<% if can? :create, Proposal %>
<p><%= link_to "Propose #{'another' if @your_proposals.present?} talk", new_proposal_path, class: "btn btn-primary" %></p>
<% end %>

<% if @proposals_you_should_look_at.present? %>
<h2>You should consider reviewing these proposals</h2>
Expand All @@ -31,6 +35,18 @@
</ul>
<% end %>

<% if @unvoted_proposals.present? %>
<h2>You have not voted yet for these proposals</h2>
<div class="alert">
You have still <%= countdown_to Phase.last_voting_date %> to cast your votes for proposals!
<%= link_to "Read more about the process", about_path %>
</div>

<ul id="you-should-vote-for-these" class="proposals">
<%= render :partial => 'proposals/proposal_listing', collection: @unvoted_proposals %>
</ul>
<% end %>

<% if @proposals_that_have_changed.present? %>
<h2>These proposals have been updated since you last made a suggestion</h2>
<ul id="things-have-changed" class="proposals">
Expand Down
8 changes: 4 additions & 4 deletions app/views/home/about.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,22 @@
</tr>
<tr>
<td>Interlude: Final call for shortlist selection</td>
<td>April 24th - April 30th</td>
<td>April 24th - April 28th</td>
<td></td>
</tr>
<tr>
<td>Phase 2: Final voting & selection</td>
<td>May 1st - May 7th</td>
<td>April 29th - May 5th</td>
<td></td>
</tr>
<tr>
<td>Speakers confirmation</td>
<td>May 8th - May 14th</td>
<td>May 6th - May 8th</td>
<td></td>
</tr>
<tr>
<td>Final lineup announcement</td>
<td>May 15th</td>
<td>May 9th</td>
<td></td>
</tr>
<tr>
Expand Down
8 changes: 8 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
<%= link_to "Tell them now", edit_user_path(current_user) %>.
</div>
<% end -%>

<% if remind_account_for_author_bio -%>
<div class="alert">
<i class="icon-user"></i>
You have some proposals waiting to get into the shortlist!
<%= link_to "Why don't you update your profile with some background info about you?", edit_user_path(current_user) %>
</div>
<% end -%>
</section>

<%= yield %>
Expand Down
22 changes: 11 additions & 11 deletions app/views/proposals/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<div class="hero-unit">
<%= page_title "#{Settings.event_name} Call for Presentations" %>

<p>
Be part of <%= Settings.event_name %>:
we highly encourage you to submit as many proposals as you want,
help the authors make theirs better
and finally select the most interesting ones for the final agenda!
What are you waiting for?
</p>
<% if current_phase.main_text %>
<p><%= current_phase.main_text.html_safe %></p>
<% end %>

<p>
You have <%= countdown_to_submissions_end %> to submit, refine and discuss proposals!
</p>
<% if current_phase.countdown_text %>
<p>You have <%= countdown_to_phase_end %> <%= current_phase.countdown_text %></p>
<% end %>

<p>
<% if user_signed_in? %>
<%= link_to "Propose a talk", new_proposal_path, :class => 'btn btn-primary' %>
<% if can? :create, Proposal %>
<%= link_to "Propose a talk", new_proposal_path, :class => 'btn btn-primary' %>
<% elsif @suggested_proposal && can?(:vote, @suggested_proposal) %>
<%= link_to "Cast your votes!", proposal_path(@suggested_proposal), :class => 'btn btn-primary' %>
<% end %>
<% else %>
<div class="btn-group">
<%= link_to 'Join the party', '#', :class => 'btn btn-primary dropdown-toggle', :data => {:toggle => 'dropdown'} %>
Expand Down
Loading

0 comments on commit 37ab0f5

Please sign in to comment.