|
18 | 18 | open Js_utils |
19 | 19 | open Lwt.Infix |
20 | 20 | open Learnocaml_common |
| 21 | +open Grade_exercise |
21 | 22 | open Learnocaml_data |
22 | 23 | open Js_of_ocaml |
23 | 24 | open Editor_lib |
24 | 25 | open Dom_html |
25 | 26 | open Test_spec |
26 | | - |
27 | | -let display_report exo report = |
28 | | - let score, _failed = Report.result report in |
29 | | - let report_button = find_component "learnocaml-exo-button-report" in |
30 | | - Manip.removeClass report_button "success" ; |
31 | | - Manip.removeClass report_button "failure" ; |
32 | | - Manip.removeClass report_button "partial" ; |
33 | | - let grade = |
34 | | - let max = Learnocaml_exercise.(access File.max_score exo) in |
35 | | - if max = 0 then 999 else score * 100 / max |
36 | | - in |
37 | | - if grade >= 100 then begin |
38 | | - Manip.addClass report_button "success" ; |
39 | | - Manip.replaceChildren report_button |
40 | | - Tyxml_js.Html5.[ pcdata [%i"Report"] ] |
41 | | - end else if grade = 0 then begin |
42 | | - Manip.addClass report_button "failure" ; |
43 | | - Manip.replaceChildren report_button |
44 | | - Tyxml_js.Html5.[ pcdata [%i"Report"] ] |
45 | | - end else begin |
46 | | - Manip.addClass report_button "partial" ; |
47 | | - let pct = Format.asprintf "%2d%%" grade in |
48 | | - Manip.replaceChildren report_button |
49 | | - Tyxml_js.Html5.[ pcdata [%i"Report"] ; |
50 | | - span ~a: [ a_class [ "score" ] ] [ pcdata pct ]] |
51 | | - end ; |
52 | | - let report_container = find_component "learnocaml-exo-tab-report" in |
53 | | - Manip.setInnerHtml report_container |
54 | | - (Format.asprintf "%a" Report.(output_html ~bare: true) report) ; |
55 | | - grade |
56 | | - |
57 | | - |
58 | | -let get_grade = |
59 | | - let get_worker = get_worker_code "learnocaml-grader-worker.js" in |
60 | | - fun ?callback ?timeout exercise -> |
61 | | - get_worker () >>= fun worker_js_file -> |
62 | | - Grading_jsoo.get_grade ~worker_js_file ?callback ?timeout exercise |
63 | | - |
64 | 27 | (*----------------------------------------------------------------------*) |
65 | 28 |
|
66 | 29 | let init_tabs, select_tab = |
67 | | - let names = [ "toplevel" ; "report" ; "editor" ; "template" ; "test" ; |
68 | | - "question" ; "prelude" ; "prepare" ] in |
69 | | - let current = ref "question" in |
70 | | - let select_tab name = |
71 | | - set_arg "tab" name ; |
72 | | - Manip.removeClass |
73 | | - (find_component ("learnocaml-exo-button-" ^ !current)) |
74 | | - "front-tab" ; |
75 | | - Manip.removeClass |
76 | | - (find_component ("learnocaml-exo-tab-" ^ !current)) |
77 | | - "front-tab" ; |
78 | | - Manip.enable |
79 | | - (find_component ("learnocaml-exo-button-" ^ !current)) ; |
80 | | - Manip.addClass |
81 | | - (find_component ("learnocaml-exo-button-" ^ name)) |
82 | | - "front-tab" ; |
83 | | - Manip.addClass |
84 | | - (find_component ("learnocaml-exo-tab-" ^ name)) |
85 | | - "front-tab" ; |
86 | | - Manip.disable |
87 | | - (find_component ("learnocaml-exo-button-" ^ name)) ; |
88 | | - current := name in |
89 | | - let init_tabs () = |
90 | | - current := begin try |
91 | | - let requested = arg "tab" in |
92 | | - if List.mem requested names then requested else "question" |
93 | | - with Not_found -> "question" |
94 | | - end ; |
95 | | - List.iter |
96 | | - (fun name -> |
97 | | - Manip.removeClass |
98 | | - (find_component ("learnocaml-exo-button-" ^ name)) |
99 | | - "front-tab" ; |
100 | | - Manip.removeClass |
101 | | - (find_component ("learnocaml-exo-tab-" ^ name)) |
102 | | - "front-tab" ; |
103 | | - Manip.Ev.onclick |
104 | | - (find_component ("learnocaml-exo-button-" ^ name)) |
105 | | - (fun _ -> select_tab name ; true)) |
106 | | - names ; |
107 | | - select_tab !current in |
108 | | - init_tabs, select_tab |
109 | | - |
| 30 | + mk_tab_handlers "question" [ "toplevel" ; "report" ; "editor" ; "template" ; "test" ; |
| 31 | + "prelude" ; "prepare" ] |
| 32 | + |
| 33 | + |
110 | 34 | let set_string_translations () = |
111 | 35 | let translations = [ |
112 | 36 | "txt_preparing", [%i"Preparing the environment"]; |
@@ -142,13 +66,7 @@ let set_string_translations () = |
142 | 66 | translations |
143 | 67 |
|
144 | 68 | let () = |
145 | | - Lwt.async_exception_hook := begin function |
146 | | - | Failure message -> fatal message |
147 | | - | Server_caller.Cannot_fetch message -> fatal message |
148 | | - | exn -> fatal (Printexc.to_string exn) |
149 | | - end ; |
150 | | - (match Js_utils.get_lang() with Some l -> Ocplib_i18n.set_lang l | None -> ()); |
151 | | - Lwt.async @@ fun () -> |
| 69 | + run_async_with_log @@ fun () -> |
152 | 70 | (*set_string_translations ();*) |
153 | 71 | Learnocaml_local_storage.init () ; |
154 | 72 |
|
@@ -600,6 +518,9 @@ let () = |
600 | 518 | Lwt.return_unit |
601 | 519 | end; |
602 | 520 | *) |
| 521 | + |
| 522 | + (* TODO : factorize somehow this with |
| 523 | + src/app/learnocaml_exercise_main grade to learnocaml_common *) |
603 | 524 | let messages = Tyxml_js.Html5.ul [] in |
604 | 525 | let callback text = |
605 | 526 | Manip.appendChild messages Tyxml_js.Html5.(li [ pcdata text ]) in |
|
0 commit comments