summaryrefslogtreecommitdiff
path: root/editor/actions
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-06-01 13:11:58 +0200
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commit72e3b16bbd258e63f047392c973ba5e8f0a823c8 (patch)
tree67f75383a9d20590587c648ecb5e3c78f6bd0044 /editor/actions
parent54f6e68c051afec0d20c349352feee5356e11b35 (diff)
Added export button in editor
Diffstat (limited to 'editor/actions')
-rwxr-xr-xeditor/actions/delete_page.ml7
-rwxr-xr-xeditor/actions/dune3
-rwxr-xr-xeditor/actions/editor_actions.ml (renamed from editor/actions/actions.ml)59
-rwxr-xr-xeditor/actions/export.ml46
4 files changed, 90 insertions, 25 deletions
diff --git a/editor/actions/delete_page.ml b/editor/actions/delete_page.ml
index 9086fc3..fb600bd 100755
--- a/editor/actions/delete_page.ml
+++ b/editor/actions/delete_page.ml
@@ -17,10 +17,13 @@ end
let create
: unit -> State.event Note.event
= fun () ->
- let title = Jstr.v "Confirmation" in
+ let title = Jstr.v "Confirmation"
+ and message =
+ Jstr.v "La page sera définitivement supprimée"
+ in
let ev = Elements.Popup.create
~title
- ~form:(Some (Forms.Delete_page.create () ))
+ ~form:(Some (Forms.Validation.create message ))
in
Note.E.map
(fun v -> State.E
diff --git a/editor/actions/dune b/editor/actions/dune
index 5d269c4..4044b52 100755
--- a/editor/actions/dune
+++ b/editor/actions/dune
@@ -1,11 +1,10 @@
(library
- (name actions)
+ (name editor_actions)
(libraries
brr
brr.note
elements
blog
- js_lib
forms
state
)
diff --git a/editor/actions/actions.ml b/editor/actions/editor_actions.ml
index f35beef..8c47363 100755
--- a/editor/actions/actions.ml
+++ b/editor/actions/editor_actions.ml
@@ -3,14 +3,8 @@ open Js_of_ocaml
open Brr
open Brr_note
-type button_actions =
- { delete : State.event Note.event
- ; redirect : State.event Note.event
- ; add: State.event Note.event
- }
-
let populate_menu
- : unit -> button_actions option
+ : unit -> State.event Note.event option
= fun () ->
match Blog.Sidebar.get () with
| None -> None
@@ -38,6 +32,24 @@ let populate_menu
~at:At.[ class' (Jstr.v "fa")
; class' (Jstr.v "fa-2x")
; class' (Jstr.v "fa-plus") ] ]
+
+ and export_button = El.button
+ ~at:At.[class' (Jstr.v "action-button")]
+ [ El.i
+ []
+ ~at:At.[ class' (Jstr.v "fa")
+ ; class' (Jstr.v "fa-2x")
+ ; class' (Jstr.v "fa-download") ]
+ ]
+
+ and load_button = El.button
+ ~at:At.[class' (Jstr.v "action-button")]
+ [ El.i
+ []
+ ~at:At.[ class' (Jstr.v "fa")
+ ; class' (Jstr.v "fa-2x")
+ ; class' (Jstr.v "fa-upload") ]
+ ]
in
(* We are waiting for event inside another event ( form validation inside
@@ -57,7 +69,15 @@ let populate_menu
Evr.on_el
Ev.click
(fun _ -> Add_page.create ())
- add_button) in
+ add_button)
+
+ and export_event =
+ Note.E.join (
+ Evr.on_el
+ Ev.click
+ (fun _ -> Export.create ())
+ export_button)
+ in
let stored_pages = State.Storage.get_ids () in
@@ -103,14 +123,8 @@ let populate_menu
let childs =
[ home_button
; add_button
- ; El.button
- ~at:At.[class' (Jstr.v "action-button")]
- [ El.i
- []
- ~at:At.[ class' (Jstr.v "fa")
- ; class' (Jstr.v "fa-2x")
- ; class' (Jstr.v "fa-download") ]
- ]
+ ; export_button
+ ; load_button
; delete_button
; El.button
~at:At.[class' (Jstr.v "action-button")]
@@ -126,8 +140,11 @@ let populate_menu
] in
let () = El.append_children element childs in
- Some
- { delete = delete_event
- ; redirect = redirect_event
- ; add = add_event
- }
+
+ Some (
+ Note.E.select
+ [ delete_event
+ ; redirect_event
+ ; add_event
+ ; export_event
+ ])
diff --git a/editor/actions/export.ml b/editor/actions/export.ml
new file mode 100755
index 0000000..a97eeac
--- /dev/null
+++ b/editor/actions/export.ml
@@ -0,0 +1,46 @@
+module Js = Js_of_ocaml.Js
+
+module M = struct
+
+ type t = unit
+
+ let update
+ : t -> State.t -> State.t
+ = fun _ state ->
+
+ (* Save this as a json element. The text may contains UTF-16 characters,
+ which will raise an error in the btoa function.
+
+ As an easy solution, we convert them into UTF-8 through the native
+ OCaml representation of string.
+ *)
+ let json = State.Storage.to_json ()
+ |> Jstr.to_string (* Encode into UTF-8 *)
+ |> Obj.magic (* Then type the element again as a string. *)
+ in
+ Elements.Transfert.send
+ ~mime_type:(Jstr.v "application/json")
+ ~filename:(Jstr.v "export.json")
+ json;
+
+ (* The function does not actually update the state, and return it
+ unchanged *)
+ state
+
+end
+
+(** Create a new element *)
+let create
+ : unit -> State.event Note.event
+ = fun () ->
+ let title = Jstr.v "Confirmation"
+ and message = Jstr.v "Exporter les notes" in
+ let ev = Elements.Popup.create
+ ~title
+ ~form:(Some (Forms.Validation.create message ))
+ in
+ Note.E.map
+ (fun v -> State.E
+ ( v
+ , (module M : State.Event with type t = M.t )))
+ (Note.E.Option.on_some ev)