Skip to content

Commit d5d82fc

Browse files
committed
feat(ui): allow partial CSV export
1 parent c341fca commit d5d82fc

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/app/learnocaml_teacher_tab.ml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ let rec teacher_tab token _select _params () =
8585
write it down."]
8686
(Token.to_string new_token))
8787
in
88-
let action_csv_export () =
89-
retrieve (Learnocaml_api.Students_csv (token, [], []))
90-
>|= fun csv ->
91-
Learnocaml_common.fake_download
92-
~name:"learnocaml.csv"
93-
~contents:(Js.string csv)
94-
in
9588
let indent_style lvl =
9689
H.a_style (Printf.sprintf "text-align: left; padding-left: %dem;" lvl)
9790
in
@@ -191,6 +184,23 @@ let rec teacher_tab token _select _params () =
191184
let assignment_change = ref (fun _ -> assert false) in
192185
let assignment_remove = ref (fun _ -> assert false) in
193186

187+
let action_csv_export () =
188+
let exercises =
189+
Hashtbl.to_seq_keys selected_exercises |>
190+
List.of_seq
191+
in
192+
let students =
193+
Hashtbl.to_seq_keys selected_students |>
194+
Seq.filter_map (function `Token tk -> Some tk | `Any -> None) |>
195+
List.of_seq
196+
in
197+
retrieve (Learnocaml_api.Students_csv (token, exercises, students))
198+
>|= fun csv ->
199+
Learnocaml_common.fake_download
200+
~name:"learnocaml.csv"
201+
~contents:(Js.string csv)
202+
in
203+
194204
(* Exercises table *)
195205
let rec mk_table group_level acc status group =
196206
match group with
@@ -940,7 +950,7 @@ let rec teacher_tab token _select _params () =
940950
H.li ~a: [ H.a_onclick (fun _ -> Lwt.async action_new_token; true) ]
941951
[ H.txt [%i"Create new teacher token"] ];
942952
H.li ~a: [ H.a_onclick (fun _ -> Lwt.async action_csv_export; true) ]
943-
[ H.txt [%i"Download student data as CSV"] ];
953+
[ H.txt [%i"Download the data for selected students/exercises as CSV"] ];
944954
]
945955
];
946956
]

0 commit comments

Comments
 (0)