Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#269 implementing chapter-specific review date ranges #296

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/assets/stylesheets/_chapters-new.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
margin-bottom: 25px;
}
}
}

.input .error {
float: left;
width: 100%;
font-weight: bold;
font-size: 120%;
color: $pink;
margin: 1em 0;
}
}
2 changes: 1 addition & 1 deletion app/controllers/finalists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class FinalistsController < ApplicationController
include ApplicationHelper

def index
@start_date, @end_date = extract_timeframe
@start_date, @end_date = extract_timeframe_for_chapter(@chapter)
@projects = Project.
includes(:chapter).
voted_for_by_members_of(current_chapter).
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ProjectsController < ApplicationController
include ApplicationHelper

def index
@start_date, @end_date = extract_timeframe
@start_date, @end_date = extract_timeframe_for_chapter(@chapter)
@short_listed = params[:short_list]

project_filter = ProjectFilter.new(@chapter.projects).during(@start_date, @end_date)
Expand Down
7 changes: 6 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module ApplicationHelper
def extract_timeframe
start_date = params[:start]
end_date = params[:end]
end_date = params[:end]
end

def extract_timeframe_for_chapter(chapter)
start_date = params[:start] || chapter.project_review_start.to_s
end_date = params[:start] || chapter.project_review_end.to_s
[start_date, end_date]
end

Expand Down
11 changes: 10 additions & 1 deletion app/models/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ class Chapter < ActiveRecord::Base

validates_format_of :slug, :with => /\A[a-z0-9-]+\Z/

validate :project_review_end_after_start

attr_accessible :name, :twitter_url, :facebook_url, :blog_url, :rss_feed_url, :description,
:country, :extra_question_1, :extra_question_2, :extra_question_3, :slug,
:email_address, :time_zone, :inactive, :locale, :submission_response_email
:email_address, :time_zone, :inactive, :locale, :submission_response_email,
:project_review_start, :project_review_end

def should_generate_new_friendly_id?
slug.blank?
Expand Down Expand Up @@ -127,4 +130,10 @@ def inactive=(bool)
self.inactive_at = nil
end
end

def project_review_end_after_start
if project_review_start.present? && project_review_end.present? && project_review_end < project_review_start
errors.add(:project_review_end, "#{I18n.t('activerecord.errors.models.chapter.attributes.project_review_end.before_start')}")
end
end
end
23 changes: 23 additions & 0 deletions app/views/chapters/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,33 @@
<%= form.input :country, :priority => COUNTRY_PRIORITY %>
<%= form.input :time_zone %>
<%= form.input :locale, :collection => I18n.available_locales, :include_blank => false, :label => t('simple_form.labels.chapter.locale', :slug => chapter.slug) %>

<%= form.input :project_review_start, :as => 'string', :include_blank => true %>
<%= form.input :project_review_end, :as => 'string', :include_blank => true %>

<%= form.input :extra_question_1 %>
<%= form.input :extra_question_2 %>
<%= form.input :extra_question_3 %>
<%= form.input :submission_response_email, :input_html => { :placeholder => Chapter::DEFAULT_SUBMISSION_RESPONSE_EMAIL } %>

<%= form.button :submit %>
<% end -%>

<% content_for :javascript do %>
<% javascript_tag do %>
$(window).load(function(){
$('#chapter_project_review_start').datepicker({
dateFormat: 'yy-mm-dd',
onClose: function(selectedDate) {
$('#chapter_project_review_start').blur();
$('#chapter_project_review_end').datepicker("option", "minDate", selectedDate);
}
});

$('#chapter_project_review_end').datepicker({
dateFormat: 'yy-mm-dd',
onClose: function() { $('#chapter_project_review_end').blur() }
});
});
<% end %>
<% end %>
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ en:
extra_question_2: Extra question 2
extra_question_3: Extra question 3
submission_response_email: Customized Email Response
project_review_start: Project Review Period Start Date
project_review_end: Project Review Period End Date
inactive: This chapter is inactive
submit: Submit
locale: Language for %{slug}.awesomefoundation.org redirect
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20170707001034_add_chapter_project_review_dates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddChapterProjectReviewDates < ActiveRecord::Migration
def up
add_column :chapters, :project_review_start, :date
add_column :chapters, :project_review_end, :date
end

def down
remove_column :chapters, :project_review_start
remove_column :chapters, :project_review_end
end
end