2017-06-07 10:23:02 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 18:12:52 +02:00
|
|
|
require 'uri'
|
2017-06-07 10:23:02 +02:00
|
|
|
|
2016-08-24 01:01:17 +02:00
|
|
|
module EventsHelper
|
2019-12-06 20:37:33 +01:00
|
|
|
def all_events(year = nil, soon = nil)
|
2017-06-07 10:23:02 +02:00
|
|
|
items_ = if year
|
|
|
|
@items.find_all("/events/#{year}/*.md")
|
|
|
|
else
|
|
|
|
@items.find_all('/events/*/*.md')
|
|
|
|
end
|
|
|
|
|
2019-12-06 20:37:33 +01:00
|
|
|
items_.select { |x| x[:soon] == soon }.sort_by { |x| x[:time] }
|
|
|
|
end
|
|
|
|
|
2020-10-13 12:01:47 +02:00
|
|
|
def tag_event_items
|
|
|
|
Set.new(items
|
|
|
|
.find_all('/events/*/*')
|
|
|
|
.flat_map { |i| i[:tags] || [] })
|
|
|
|
.to_a
|
|
|
|
.sort
|
|
|
|
.uniq.map { |y| [y, items["/events/#{y.gsub(' ', '_')}.html"]]}
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_events_by_tag(tag = nil, soon = nil)
|
|
|
|
@items.find_all('/events/*/*.md')
|
|
|
|
.filter{|i| (i[:tags] || []).include? tag }
|
|
|
|
.select { |x| x[:soon] == soon }
|
|
|
|
.sort_by { |x| x[:time] }
|
|
|
|
end
|
|
|
|
|
2020-01-13 14:31:55 +01:00
|
|
|
def soon_events
|
2019-12-06 20:37:33 +01:00
|
|
|
all_events(nil, true)
|
2016-10-03 15:15:48 +02:00
|
|
|
end
|
|
|
|
|
2017-06-07 10:23:02 +02:00
|
|
|
def upcoming_events(year = nil)
|
|
|
|
all_events(year).reject { |x| x[:time] <= Date.today }
|
2016-10-03 15:15:48 +02:00
|
|
|
end
|
|
|
|
|
2020-10-13 12:01:47 +02:00
|
|
|
def upcoming_events_in_year_or_tag(item)
|
|
|
|
if item[:is_yearly]
|
|
|
|
upcoming_events(item[:academic_year])
|
|
|
|
else
|
|
|
|
all_events_by_tag(item[:tag]).reject { |x| x[:time] <= Date.today }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-07 10:23:02 +02:00
|
|
|
def past_events(year = nil)
|
|
|
|
all_events(year).reject { |x| x[:time] > Date.today }.reverse
|
2016-08-24 01:01:17 +02:00
|
|
|
end
|
|
|
|
|
2020-10-13 12:01:47 +02:00
|
|
|
def past_events_in_year_or_tag(item)
|
|
|
|
if item[:is_yearly]
|
|
|
|
past_events(item[:academic_year])
|
|
|
|
else
|
|
|
|
all_events_by_tag(item[:tag]).reject { |x| x[:time] > Date.today }.reverse
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-07 10:23:02 +02:00
|
|
|
def academic_years_event_items
|
2020-10-13 12:01:47 +02:00
|
|
|
items.find_all('/events/*').reject { |e| e[:academic_year].nil? }.map { |e| [e[:academic_year], e] }.sort_by(&:first).reverse
|
2017-06-07 10:23:02 +02:00
|
|
|
end
|
|
|
|
|
2016-08-24 01:01:17 +02:00
|
|
|
def grouped_events
|
|
|
|
@items.find_all('/events/*/*/main.md')
|
|
|
|
end
|
|
|
|
|
2021-02-26 12:22:29 +01:00
|
|
|
def previous_events
|
|
|
|
all_events.reverse[(upcoming_events.length)..]
|
2020-02-17 00:32:23 +01:00
|
|
|
end
|
|
|
|
|
2016-08-24 01:01:17 +02:00
|
|
|
def sub_events(grouped_event)
|
|
|
|
if grouped_event.identifier =~ /main.md/
|
|
|
|
query = grouped_event.identifier.to_s.split('/')[0..-2].join('/') + '/*'
|
|
|
|
@items.find_all(query).reject do |i|
|
|
|
|
i.identifier =~ /main.md/
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|