2020-02-27 21:43:59 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-29 01:05:32 +02:00
|
|
|
# Helpers for data
|
2020-02-28 13:26:02 +01:00
|
|
|
module VerenigingenHelper
|
2020-08-29 01:05:32 +02:00
|
|
|
# Helpers for navbar partial
|
|
|
|
def current_child_of(item)
|
|
|
|
child_of(item, @item)
|
|
|
|
end
|
2020-08-29 00:09:04 +02:00
|
|
|
|
2020-08-29 01:05:32 +02:00
|
|
|
def child_of(parent, child)
|
|
|
|
children_of(parent).include?(child)
|
|
|
|
end
|
2020-08-29 00:09:04 +02:00
|
|
|
|
2020-08-29 01:05:32 +02:00
|
|
|
# Data helpers
|
|
|
|
def themas
|
|
|
|
@items.find_all("**/themas/*")
|
|
|
|
end
|
2020-08-29 00:09:04 +02:00
|
|
|
|
2020-09-12 17:19:35 +02:00
|
|
|
def verenigingen_voor_thema(thema)
|
|
|
|
@items.filter{|i| i[:themas] and i[:themas].include?(thema)}.to_a
|
|
|
|
end
|
|
|
|
|
2020-09-15 20:25:58 +02:00
|
|
|
def verenigingen_voor_konvent(konvent)
|
|
|
|
@items.find_all("**/verenigingen/*").filter { |i| i[:konvent] == konvent }.to_a
|
|
|
|
end
|
|
|
|
|
2020-08-29 01:05:32 +02:00
|
|
|
def konventen
|
|
|
|
@items.find_all("**/konventen/*").to_a
|
|
|
|
end
|
|
|
|
|
|
|
|
def evenementen
|
|
|
|
@items.find_all("**/evenementen/*")
|
|
|
|
end
|
|
|
|
|
|
|
|
def projecten
|
|
|
|
@items.find_all("**/projecten/*").to_a
|
|
|
|
end
|
|
|
|
|
|
|
|
def konventen_and_projecten
|
|
|
|
konventen.union(projecten)
|
|
|
|
end
|
|
|
|
|
|
|
|
def verenigingen
|
|
|
|
@items.find_all("**/verenigingen/*").map { |x| {
|
|
|
|
"naam" => x[:naam],
|
|
|
|
"verkorte_naam" => x[:verkorte_naam],
|
|
|
|
"konvent" => x[:konvent],
|
2020-09-05 21:40:05 +02:00
|
|
|
"themas" => x[:themas],
|
|
|
|
"postcodes" => x[:postcodes].to_a,
|
2020-09-15 17:56:12 +02:00
|
|
|
"id" => x[:id],
|
|
|
|
"path" => x.path
|
2020-08-29 01:05:32 +02:00
|
|
|
} }.to_a
|
|
|
|
end
|
|
|
|
|
2020-09-05 21:40:05 +02:00
|
|
|
def postcodes_per_vereniging
|
|
|
|
@items.find_all("**/verenigingen/*").map { |x| {
|
|
|
|
"postcodes" => x[:postcodes],
|
|
|
|
"id" => x[:id]
|
|
|
|
} }.flatten.to_a
|
|
|
|
end
|
2020-09-12 17:19:35 +02:00
|
|
|
|
2020-09-05 21:40:05 +02:00
|
|
|
|
2020-08-29 01:05:32 +02:00
|
|
|
def abbreviation(item)
|
2020-09-15 17:56:12 +02:00
|
|
|
item['id']
|
2020-08-29 01:05:32 +02:00
|
|
|
end
|
|
|
|
|
2020-09-04 22:25:13 +02:00
|
|
|
def all_groups
|
|
|
|
@items.find_all("**/verenigingen/*") + @items.find_all("**/konventen/*")
|
|
|
|
end
|
|
|
|
|
2020-08-29 01:05:32 +02:00
|
|
|
def image_url(item)
|
|
|
|
if item[:image].nil?
|
|
|
|
"https://dsa.ugent.be/api/verenigingen/#{ abbreviation item }/logo?size=medium"
|
|
|
|
else
|
|
|
|
item[:image]
|
2020-03-19 21:05:26 +01:00
|
|
|
end
|
2020-08-29 16:01:18 +02:00
|
|
|
end
|
|
|
|
|
2020-08-29 01:05:32 +02:00
|
|
|
def image_tag(item)
|
2020-08-29 16:04:59 +02:00
|
|
|
"<img src='#{ image_url item }' alt='#{ item[:naam] } logo' />"
|
2020-08-29 00:09:04 +02:00
|
|
|
end
|
2020-08-28 22:41:50 +02:00
|
|
|
end
|