Commit be5afbaa authored by Jiri Strojil's avatar Jiri Strojil

Preselection redone

parent 1062f3cd
......@@ -75,7 +75,7 @@ class SemesterProcessVolunteersController < ApplicationController
if params[:semester]
@selected_semester = Semester.parse(params[:semester])
else
@selected_semester = @semester.current
@selected_semester = @semester.preselect_semester
params[:semester] = Semester.to_s(@selected_semester)
end
end
......
......@@ -16,8 +16,6 @@ class Semester
11 => 2
}.freeze
SEMESTER_OFFSET = 4.months
class << self
def parse(string)
return unless string
......@@ -92,10 +90,10 @@ class Semester
# semester_number - required if year integer
def initialize(year = nil, number = 1)
@context = if year.nil?
Time.zone.now + SEMESTER_OFFSET
Time.zone.now
else
year -= 1 if number == 1
Time.zone.local(year, (18 - number * 6), 1) + SEMESTER_OFFSET
Time.zone.local(year, (18 - number * 6), 1)
end
end
......@@ -118,6 +116,12 @@ class Semester
)
end
def preselect_semester(offset = -4.months)
Semester.semester_range_from_start(
Semester.semester_start_time(@context + offset)
)
end
# params:
# count - shift of semesters - only positive integers
def previous(count = 1)
......@@ -178,7 +182,8 @@ class Semester
def existing_collection(count = 6)
collection(count) do |semester|
next unless Semester.new.current == semester || Semester.taken_semesters.include?(semester)
s = Semester.new
next unless s.preselect_semester == semester || s.current == semester || Semester.taken_semesters.include?(semester)
[Semester.i18n_t(semester, short: false), to_s(semester)]
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment