diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 769a5ab..d3c09cc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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? @@ -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 diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index b1719c2..68a26f8 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 7aedd9c..eb52513 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dec0a9f..8dbb399 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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) @@ -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, diff --git a/app/models/ability.rb b/app/models/ability.rb index e105917..b4e483f 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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 @@ -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 diff --git a/app/models/phase.rb b/app/models/phase.rb new file mode 100644 index 0000000..caefd8e --- /dev/null +++ b/app/models/phase.rb @@ -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 your #{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 your 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 \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index d6c119e..ebca996 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/dashboard/_moderator_dashboard.html.erb b/app/views/dashboard/_moderator_dashboard.html.erb index 33b76ce..416fdb8 100644 --- a/app/views/dashboard/_moderator_dashboard.html.erb +++ b/app/views/dashboard/_moderator_dashboard.html.erb @@ -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 diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 8259c46..ae8adb9 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -8,10 +8,12 @@

Your proposals

-
- 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 %>. -
+<% if can? :create, Proposal %> +
+ 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 %>. +
+<% end %> <% if @your_proposals.present? %> <% end %> -

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

+<% if can? :create, Proposal %> +

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

+<% end %> <% if @proposals_you_should_look_at.present? %>

You should consider reviewing these proposals

@@ -31,6 +35,18 @@ <% end %> +<% if @unvoted_proposals.present? %> +

You have not voted yet for these proposals

+
+ You have still <%= countdown_to Phase.last_voting_date %> to cast your votes for proposals! + <%= link_to "Read more about the process", about_path %> +
+ + +<% end %> + <% if @proposals_that_have_changed.present? %>

These proposals have been updated since you last made a suggestion