From 1ce191d9c266b62e62d3cf9e614d43fe421bf439 Mon Sep 17 00:00:00 2001 From: Cedric Hurst Date: Thu, 6 Jul 2017 21:01:22 -0500 Subject: [PATCH] #269 implementing chapter-specific review date ranges --- app/assets/stylesheets/_chapters-new.scss | 11 ++++++++- app/controllers/finalists_controller.rb | 2 +- app/controllers/projects_controller.rb | 2 +- app/helpers/application_helper.rb | 7 +++++- app/models/chapter.rb | 11 ++++++++- app/views/chapters/_form.html.erb | 23 +++++++++++++++++++ ...001034_add_chapter_project_review_dates.rb | 11 +++++++++ 7 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170707001034_add_chapter_project_review_dates.rb diff --git a/app/assets/stylesheets/_chapters-new.scss b/app/assets/stylesheets/_chapters-new.scss index d78be913..8600d5dc 100644 --- a/app/assets/stylesheets/_chapters-new.scss +++ b/app/assets/stylesheets/_chapters-new.scss @@ -6,4 +6,13 @@ margin-bottom: 25px; } } -} \ No newline at end of file + + .input .error { + float: left; + width: 100%; + font-weight: bold; + font-size: 120%; + color: $pink; + margin: 1em 0; + } +} diff --git a/app/controllers/finalists_controller.rb b/app/controllers/finalists_controller.rb index f3dbb914..634a5299 100644 --- a/app/controllers/finalists_controller.rb +++ b/app/controllers/finalists_controller.rb @@ -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). diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f636cddf..5e4690f6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3a69b688..7c28c8d7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/chapter.rb b/app/models/chapter.rb index f9caf7d3..fd12eee1 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -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? @@ -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 diff --git a/app/views/chapters/_form.html.erb b/app/views/chapters/_form.html.erb index 46aaa47f..e1c686c5 100644 --- a/app/views/chapters/_form.html.erb +++ b/app/views/chapters/_form.html.erb @@ -16,6 +16,10 @@ <%= 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 %> @@ -23,3 +27,22 @@ <%= 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 %> diff --git a/db/migrate/20170707001034_add_chapter_project_review_dates.rb b/db/migrate/20170707001034_add_chapter_project_review_dates.rb new file mode 100644 index 00000000..15fc0f4a --- /dev/null +++ b/db/migrate/20170707001034_add_chapter_project_review_dates.rb @@ -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