diff options
author | Alban Gruin | 2021-09-19 12:29:50 +0200 |
---|---|---|
committer | Alban Gruin | 2021-09-19 12:39:11 +0200 |
commit | 4b05babc1e5a4466028d7d210d9a7920a4a401f7 (patch) | |
tree | eda874f6ab2c8b613d09546a62064e0172c88df8 /src/ics.ml | |
parent | d489f3743cca9e6fb3dddbf10bbcb1e188b09f0b (diff) |
server, ics, pages: allow to generate ICS from modules
This adds the ability to generate an ICS file from a module ID, and to
filter it based on its groups.
To do this, you can enter a module ID on the frontpage. Then, µCS will
fetch the timetable, then return a page where one can select the
group(s) they want to filter (this is enabled by the new
Ics.get_all_groups function). Then, µCS is able to generate a link to
that calendar, not unlike with a single group ID.
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
Diffstat (limited to 'src/ics.ml')
-rw-r--r-- | src/ics.ml | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -17,6 +17,8 @@ open CalendarLib +module StringSet = Set.Make (String) + let to_date = Printer.Calendar.sprint "%Y%m%dT%H%M%S" let current_date () = to_date @@ Calendar.now () @@ -61,6 +63,8 @@ module Event = struct let has_groups groups event = List.fold_left (fun found group -> found || List.exists ((=) group) groups) false event.groups + + let get_groups event = event.groups end type t = Event.t list @@ -80,6 +84,12 @@ let gen_vtimezone tz = else "" +let get_all_groups events = + let add_groups_to_set set event = + List.fold_left (fun set elt -> StringSet.add elt set) set @@ Event.get_groups event in + List.fold_left add_groups_to_set StringSet.empty events + |> StringSet.to_seq + let to_string tz events = let date = current_date () in let vtimezone = gen_vtimezone tz in |