Skip to content

Commit 7ea03f1

Browse files
committed
fix(web-app): Remove automatic dialog (cf. Mechanism-2 of PR ocaml-sf#372)
This fixes "bugs 1, 2" of issue ocaml-sf#505.
1 parent 1c068dd commit 7ea03f1

File tree

8 files changed

+9
-78
lines changed

8 files changed

+9
-78
lines changed

src/ace-lib/ace.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ let set_synchronized_status editor status =
8888

8989
let focus { editor } = editor##focus
9090

91-
let create_editor editor_div check_valid_state =
91+
let create_editor editor_div =
9292
let editor = edit editor_div in
9393
Js.Unsafe.set editor "$blockScrolling" (Js.Unsafe.variable "Infinity");
9494
let data =
@@ -102,8 +102,6 @@ let create_editor editor_div check_valid_state =
102102
editor##.customData := (data, None);
103103
editor##setOption (Js.string "displayIndentGuides") (Js.bool false);
104104
editor##on (Js.string "change") (fun () ->
105-
check_valid_state (set_contents data) (fun () -> focus data)
106-
(fun () -> set_synchronized_status data true);
107105
set_synchronized_status data false);
108106
data
109107

src/ace-lib/ace.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ type loc = {
1717
loc_end: int * int;
1818
}
1919

20-
val create_editor: Dom_html.divElement Js.t
21-
-> ((string -> unit) -> (unit -> unit) -> (unit -> unit) -> unit) -> 'a editor
20+
val create_editor: Dom_html.divElement Js.t -> 'a editor
2221

2322
val is_synchronized : 'a editor -> bool
2423

src/ace-lib/ocaml_mode.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ let do_delete ace_editor =
514514
Ace.remove ace_editor "left"
515515
end
516516

517-
let create_ocaml_editor div check_valid_state =
518-
let ace = Ace.create_editor div check_valid_state in
517+
let create_ocaml_editor div =
518+
let ace = Ace.create_editor div in
519519
Ace.set_mode ace "ace/mode/ocaml.ocp";
520520
Ace.set_tab_size ace !config.indent.IndentConfig.i_base;
521521
let editor = { ace; current_error = None; current_warnings = [] } in

src/ace-lib/ocaml_mode.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ type error = msg list
2424

2525
type warning = error
2626

27-
val create_ocaml_editor:
28-
Dom_html.divElement Js.t -> ((string -> unit) -> (unit -> unit) -> (unit -> unit) -> unit) -> editor
27+
val create_ocaml_editor: Dom_html.divElement Js.t -> editor
2928
val get_editor: editor -> editor Ace.editor
3029

3130
val report_error: editor -> ?set_class: bool -> error option -> warning list -> unit Lwt.t

src/app/learnocaml_common.ml

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -712,72 +712,11 @@ let mouseover_toggle_signal elt sigvalue setter =
712712
in
713713
Manip.Ev.onmouseover elt hdl
714714
715-
(*
716-
717-
If a user has made no change to a solution for the exercise [id]
718-
for 180 seconds, [check_valid_editor_state id] ensures that there is
719-
no more recent version of this solution in the server. If this is
720-
the case, the user is asked if we should download this solution
721-
from the server.
722-
723-
This function reduces the risk of an involuntary overwriting of a
724-
student solution when the solution is open in several clients.
725-
726-
*)
727-
let is_synchronized_with_server_callback = ref (fun () -> false)
728-
729-
let is_synchronized_with_server () = !is_synchronized_with_server_callback ()
730-
731-
let check_valid_editor_state id =
732-
let last_changed = ref (Unix.gettimeofday ()) in
733-
fun update_content focus_back on_sync ->
734-
let update_local_copy checking_time () =
735-
let get_solution () =
736-
Learnocaml_local_storage.(retrieve (exercise_state id)).Answer.solution in
737-
try let mtime =
738-
Learnocaml_local_storage.(retrieve (exercise_state id)).Answer.mtime in
739-
if mtime > checking_time then begin
740-
let buttons =
741-
if is_synchronized_with_server () then
742-
[
743-
[%i "Fetch from server"],
744-
(fun () -> let solution = get_solution () in
745-
Lwt.return (focus_back (); update_content solution; on_sync ()));
746-
[%i "Ignore & keep editing"],
747-
(fun () -> Lwt.return (focus_back ()));
748-
]
749-
else
750-
[
751-
[%i "Ignore & keep editing"],
752-
(fun () -> Lwt.return (focus_back ()));
753-
[%i "Fetch from server & overwrite"],
754-
(fun () -> let solution = get_solution () in
755-
Lwt.return (focus_back (); update_content solution; on_sync ()));
756-
]
757-
in
758-
lwt_alert ~title:"Question"
759-
~buttons
760-
[ H.p [H.txt [%i "A more recent answer exists on the server. \
761-
Do you want to fetch the new version?"] ] ]
762-
end else Lwt.return_unit
763-
with
764-
| Not_found -> Lwt.return ()
765-
in
766-
let now = Unix.gettimeofday () in
767-
if now -. !last_changed > 180. then (
768-
let checking_time = !last_changed in
769-
last_changed := now;
770-
Lwt.async (update_local_copy checking_time)
771-
) else
772-
last_changed := now
773-
774-
775715
let ace_display tab =
776716
let ace = lazy (
777717
let answer =
778718
Ocaml_mode.create_ocaml_editor
779719
(Tyxml_js.To_dom.of_div tab)
780-
(fun _ _ _ -> ())
781720
in
782721
let ace = Ocaml_mode.get_editor answer in
783722
Ace.set_font_size ace 16;
@@ -983,12 +922,11 @@ module Editor_button (E : Editor_info) = struct
983922
984923
end
985924
986-
let setup_editor id solution =
925+
let setup_editor solution =
987926
let editor_pane = find_component "learnocaml-exo-editor-pane" in
988927
let editor =
989928
Ocaml_mode.create_ocaml_editor
990929
(Tyxml_js.To_dom.of_div editor_pane)
991-
(check_valid_editor_state id)
992930
in
993931
let ace = Ocaml_mode.get_editor editor in
994932
Ace.set_contents ace ~reset_undo:true solution;

src/app/learnocaml_common.mli

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ module Editor_button (_ : Editor_info) : sig
218218
val sync : Token.t option Lwt.t -> Learnocaml_data.SMap.key -> (unit -> unit) -> unit
219219
end
220220

221-
val setup_editor : string -> string -> Ocaml_mode.editor * Ocaml_mode.editor Ace.editor
222-
223-
val is_synchronized_with_server_callback : (unit -> bool) ref
221+
val setup_editor : string -> Ocaml_mode.editor * Ocaml_mode.editor Ace.editor
224222

225223
val typecheck :
226224
Learnocaml_toplevel.t ->

src/app/learnocaml_exercise_main.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ let () =
179179
Tyxml_js.Html5.[ h1 [ txt ex_meta.Exercise.Meta.title ] ;
180180
Tyxml_js.Of_dom.of_iFrame text_iframe ] ;
181181
(* ---- editor pane --------------------------------------------------- *)
182-
let editor, ace = setup_editor id solution in
183-
is_synchronized_with_server_callback := (fun () -> Ace.is_synchronized ace);
182+
let editor, ace = setup_editor solution in
184183
let module EB = Editor_button (struct let ace = ace let buttons_container = editor_toolbar end) in
185184
EB.cleanup (Learnocaml_exercise.(access File.template exo));
186185
EB.sync token id (fun () -> Ace.focus ace; Ace.set_synchronized ace) ;

src/app/learnocaml_playground_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let main () =
6464
(* ---- toplevel pane ------------------------------------------------- *)
6565
init_toplevel_pane toplevel_launch top toplevel_buttons_group toplevel_button ;
6666
(* ---- editor pane --------------------------------------------------- *)
67-
let editor, ace = setup_editor id solution in
67+
let editor, ace = setup_editor solution in
6868
let module EB = Editor_button (struct let ace = ace let buttons_container = editor_toolbar end) in
6969
EB.cleanup playground.Playground.template;
7070
EB.download id;

0 commit comments

Comments
 (0)