Commit 01ee9c9d authored by Jiri Strojil's avatar Jiri Strojil

Uniq collection

parent 71f6ec87
......@@ -36,6 +36,10 @@ class Semester
MONTH_NUMBER_MAP[date.month]
end
def taken_semesters
SemesterProcess.all.pluck(:semester)
end
def year(date = nil)
date = to_process_date(date)
date.month == 12 ? date.year + 1 : date.year
......@@ -77,7 +81,7 @@ class Semester
def semester_range_from_start(date_time)
date_time = date_time.to_date
date_time..date_time.advance(months: 5).end_of_month
date_time...date_time.advance(months: 5).end_of_month
end
end
......@@ -155,6 +159,17 @@ class Semester
def collection(count = 3, direction: :previous, with_current: true)
list(count, direction: direction, with_current: with_current).map do |semester|
if block_given?
yield semester
else
[Semester.i18n_t(semester, short: false), to_s(semester)]
end
end.compact
end
def unique_collection(count = 3)
collection(count) do |semester|
next if Semester.taken_semesters.include?(semester)
[Semester.i18n_t(semester, short: false), to_s(semester)]
end
end
......
......@@ -3,7 +3,7 @@
= f.input_field :kind, value: @semester_process.kind, as: :hidden
.row:.col-xs-12.col-md-4
= f.input :semester, collection: @semester&.collection || [Semester.i18n_t(@semester_process.semester, short: false)],
= f.input :semester, collection: @semester&.unique_collection || [Semester.i18n_t(@semester_process.semester, short: false)],
selected: params[:semester], input_html: { class: 'semester-selector' }, disabled: !@semester
.row
......
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