From 4b05babc1e5a4466028d7d210d9a7920a4a401f7 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 19 Sep 2021 12:29:50 +0200 Subject: 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 --- src/ics.ml | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/ics.ml') diff --git a/src/ics.ml b/src/ics.ml index 888e9e8..d6d165a 100644 --- a/src/ics.ml +++ b/src/ics.ml @@ -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 -- cgit v1.2.1