Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide tokens in partition-view.html #540

Merged
merged 27 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a026374
feat: dropdown menu
Plictox Apr 20, 2023
41886a5
feat: dynamic implmentation
Plictox Apr 20, 2023
88dec16
feat: dynamic implementation
Plictox Apr 20, 2023
c3f204f
feat: hide tokens
Plictox Apr 20, 2023
3b68d80
feat: retrieve students data
Plictox Apr 21, 2023
126b963
feat: hide PII feature
Plictox Apr 24, 2023
d558618
feat: corrections
Plictox Apr 24, 2023
24f951d
Merge branch 'hide_tokens' of github.com:pfitaxel/learn-ocaml into hi…
Plictox Apr 24, 2023
b480b4b
feat: new fonction for hide tokens
Plictox Apr 25, 2023
858b54c
feat: implementation new algorithm
Plictox Apr 25, 2023
a1b7fd4
feat: corrections
Plictox Apr 25, 2023
a7a8c90
feat: first working implementation
Plictox Apr 26, 2023
8c2e3e5
feat: better implementation
Plictox Apr 26, 2023
c358b34
feat: enhancing html page
Plictox Apr 26, 2023
32ea5e1
feat: changes from review
Plictox Apr 27, 2023
f4fdd8f
feat: useless code deleted
Plictox Apr 27, 2023
c1f2f2f
feat: changing variable names
Plictox Apr 27, 2023
1d3abf4
feat: improved list_of_students_details
Plictox Apr 27, 2023
7d142b2
feat: improved students_partition
Plictox Apr 27, 2023
5c3a045
feat: changing default selection
Plictox Apr 27, 2023
9f2c2a6
feat: implementation for the details tab
Plictox Apr 27, 2023
608301f
feat: changing a into span
Plictox Apr 27, 2023
d8289fd
feat: Add learnocaml_partition_view.css
erikmd Apr 28, 2023
6b52d83
fix(partition-view): Fix the order of tabs in responsive mode
erikmd Apr 28, 2023
22542b7
refactor(partition-view): Turn the students_list in students_map ASAP
erikmd Apr 28, 2023
11d442d
fix: Fix `<selected>` bugs
erikmd Apr 29, 2023
0eddfea
fix: Apply review changes
erikmd Apr 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 73 additions & 9 deletions src/app/learnocaml_partition_view.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ open Js_utils
open Lwt
open Learnocaml_data
open Learnocaml_common
open List
Plictox marked this conversation as resolved.
Show resolved Hide resolved

module H = Tyxml_js.Html5
module React = Lwt_react

let find_tab name = (find_component ("learnocaml-exo-tab-" ^ name))

let tab_select_signal, init_tab, select_tab =
Expand All @@ -34,10 +34,19 @@ let open_tok tok =
let _win = window_open ("/student-view.html?token="^tok) "_blank" in
false

let list_of_tok =
(*
let selected_list =
List.map @@ fun x ->
let tok = Token.to_string x in
H.a ~a:[H.a_onclick (fun _ -> open_tok tok)] [H.txt (tok ^ " ")]
let choice = Manip.value (find_component "learnocaml-select-student-info") in
match choice with
|"tokens" ->
H.a ~a:[H.a_ondblclick (fun _ -> open_tok tok)] [H.txt (tok ^ " ")]
|"nickname" ->
let nick = "toto" in (*trouver comment récupérer les pseudos*)
H.a ~a:[H.a_ondblclick (fun _ -> open_tok tok)] [H.txt (nick ^ " ")]
|_ -> failwith "Error" (*à modifier*)
*)
Plictox marked this conversation as resolved.
Show resolved Hide resolved

let rec render_tree =
let open Asak.Wtree in
Expand Down Expand Up @@ -80,7 +89,36 @@ let render_classes xs =

let sum_with f = List.fold_left (fun acc x -> acc + f x) 0

let exercises_tab part =
let rec students_partition students part =
let open Student in
match part with
|[] -> []
|t::q -> let student_t = List.find (fun student -> student.token = t) students in
student_t :: students_partition students q
Plictox marked this conversation as resolved.
Show resolved Hide resolved

let list_of_students_details students part=
Plictox marked this conversation as resolved.
Show resolved Hide resolved
let open Student in
let open Partition in
let bad_type_students = students_partition students part.bad_type in
let not_graded_students = students_partition students part.not_graded in
let rec create_div students_list id = match students_list with
| [] -> []
| t::q -> let tok = Token.to_string t.token in
let nick = Option.value t.nickname ~default:"Student" in
H.a ~a:[
Plictox marked this conversation as resolved.
Show resolved Hide resolved
H.a_ondblclick (fun _ -> open_tok tok);
H.a_class ["student"];
H.a_user_data "anon" ("Student " ^ string_of_int id ^ " ");
H.a_user_data "token" (tok ^ " ");
H.a_user_data "nickname" (nick ^ " ");
(* i added the spaces here in the attribute,
for now i don't see how to do it otherwise*)
] []
:: (create_div q (id + 1))
in (create_div not_graded_students 1,
create_div bad_type_students (1 + List.length not_graded_students))

let exercises_tab students part =
let open Partition in
let not_graded =
string_of_int (List.length part.not_graded)
Expand All @@ -98,8 +136,9 @@ let exercises_tab part =
part.partition_by_grade in
string_of_int s
^ " codes implemented the function with the right type." in
H.p (H.txt not_graded :: list_of_tok part.not_graded)
:: H.p ( H.txt bad_type :: list_of_tok part.bad_type)
let (a,b) = list_of_students_details students part in
H.p (H.txt not_graded :: a)
:: H.p ( H.txt bad_type :: b)
Plictox marked this conversation as resolved.
Show resolved Hide resolved
:: H.p [H.txt total_sum]
:: render_classes part.partition_by_grade

Expand Down Expand Up @@ -136,6 +175,16 @@ let _class_selection_updater =
Manip.replaceChildren (find_tab "details")
[H.ul @@ mkfirst (List.hd xs) :: List.map mkelem (List.tl xs)]

let set_classes s =
Manip.removeClass (find_tab "list") ("token-id");
Manip.removeClass (find_tab "list") ("anon-id");
Manip.removeClass (find_tab "list") ("nickname-id");
Manip.removeClass (find_tab "details") ("token-id");
Manip.removeClass (find_tab "details") ("anon-id");
Manip.removeClass (find_tab "details") ("nickname-id");
Manip.addClass (find_tab "list") (s ^ "-id");
Manip.addClass (find_tab "details") (s ^ "-id");true
Plictox marked this conversation as resolved.
Show resolved Hide resolved

let main () =
Learnocaml_local_storage.init ();
(match Js_utils.get_lang() with Some l -> Ocplib_i18n.set_lang l | None -> ());
Expand Down Expand Up @@ -174,13 +223,28 @@ let main () =
then update_repr_code id
else true in

retrieve (Learnocaml_api.Partition (teacher_token, exercise_id, fun_id, prof))
>>= fun part ->
let fetch_students =
retrieve (Learnocaml_api.Students_list teacher_token)
>>= fun students_map ->
let students = students_map in
Lwt.return students
Plictox marked this conversation as resolved.
Show resolved Hide resolved
in
let fetch_part =
retrieve (Learnocaml_api.Partition (teacher_token, exercise_id, fun_id, prof))
>>= fun partition ->
let part = partition in
Lwt.return part
Plictox marked this conversation as resolved.
Show resolved Hide resolved
in
Lwt.both fetch_students fetch_part >>= fun (students, part) ->
hide_loading ~id:"learnocaml-exo-loading" ();
Manip.replaceChildren (find_tab "list") (exercises_tab part);
Manip.replaceChildren (find_tab "list") (exercises_tab students part);
init_tab ();
Manip.Ev.onclick (find_component "learnocaml-exo-button-answer")
(fun _ -> select_tab "answer"; update_repr_code (React.S.value selected_repr_signal));
Manip.Ev.onchange_select (find_component "learnocaml-select-student-info")
(fun _ ->let choice = Manip.value (find_component "learnocaml-select-student-info") in
set_classes choice
);
Plictox marked this conversation as resolved.
Show resolved Hide resolved
Lwt.return_unit

let () = run_async_with_log main
2 changes: 1 addition & 1 deletion src/state/learnocaml_data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ module Student = struct
results: (float * int option) SMap.t;
creation_date: float;
tags: SSet.t;
}
}
Plictox marked this conversation as resolved.
Show resolved Hide resolved

let enc =
let open Json_encoding in
Expand Down
14 changes: 14 additions & 0 deletions static/css/learnocaml_common.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ code, pre, textarea {
font-size: 18px;
line-height: 18px;
}

div.anon-id a.student::before {
content: attr(data-anon);
}

div.token-id a.student::before {
content: attr(data-token);
}

div.nickname-id a.student::before {
content: attr(data-nickname);
}
Plictox marked this conversation as resolved.
Show resolved Hide resolved


/* -------------------- fix browser's CSSs ------------------------ */
button > img {
vertical-align: -10%;
Expand Down
9 changes: 7 additions & 2 deletions static/partition-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<div class="logo">
<img src="/icons/logo_ocsf.svg">
<span>Learn OCaml</span>
<select id="learnocaml-select-student-info">
<option value="anon" selected="selected">Hide PII<option>
<option value="nickname">Show nicknames</option>
<option value="token">Show tokens</option>
</select>
Plictox marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div id="learnocaml-token">
</div>
Expand All @@ -54,8 +59,8 @@
<button id="learnocaml-exo-button-answer">Answer</button>
</div>
<div id="learnocaml-exo-tabs">
<div id="learnocaml-exo-tab-details" class="front-tab"></div>
<div id="learnocaml-exo-tab-list"></div>
<div id="learnocaml-exo-tab-details" class="front-tab anon-id"></div>
<div id="learnocaml-exo-tab-list" class="anon-id"></div>
Plictox marked this conversation as resolved.
Show resolved Hide resolved
<div id="learnocaml-exo-tab-answer">
<div id="learnocaml-exo-answer-pane" class="pane"></div>
<div id="learnocaml-exo-answer-toolbar" class="buttons">
Expand Down