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

Reorganize webapp directory gui #703

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- name: Make Javascript app
run: |
opam exec -- make Kappapp.tar.gz build/site/index.html
cp -r gui/viz .
cp -r gui/js_lib/viz .
mv build/Kappapp.tar.gz .
mv build/site .
- name: Archive Javascript app
Expand Down
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 0.26.1
version = 0.26.2
profile=conventional
margin=80
if-then-else=k-r
Expand Down
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ SCRIPTSSOURCE = $(wildcard $(MANSCRIPTREP)*.sh)
SCRIPTSWITNESS = $(SCRIPTSSOURCE:.sh=.witness) $(MANGENREP)version.tex
MODELS = $(wildcard $(MANKAPPAMODELSREP)*.ka)

RESOURCES_HTML=$(wildcard gui/shared/*.js) $(wildcard gui/viz/*.js) $(wildcard gui/viz/*.css) gui/favicon.ico gui/package.json
RESOURCES_HTML=$(wildcard gui/js_lib/*.js) $(wildcard gui/js_lib/viz/*.js) $(wildcard gui/resources/*.css) gui/resources/favicon.ico gui/entry_point/package.json gui/entry_point/main.js

# `APP_EXT` defines where to fetch the js libs.
# `local` is to download them from the dev website e.g. github and saving them locally.
# `cdn` uses `cdnjs.cloudfare.com` to fetch the libs
# `debian` and `deploy` are also available
APP_EXT?=cdn
INDEX_HTML=gui/use-$(APP_EXT).html
INDEX_HTML=gui/entry_point/use-$(APP_EXT).html
ifeq ($(APP_EXT),local)
SITE_EXTRAS= build/site/external build/site/external/bootstrap-$(BOOTSTRAP_VERSION)-dist build/site/external/codemirror-$(CODEMIRROR_VERSION) build/site/external/dagre-d3 build/site/external/d3 build/site/external/jquery
else
Expand Down Expand Up @@ -174,7 +178,7 @@ Kappapp:

build/Kappapp.tar.gz: build/Kappapp
tar -C build -czf $@ Kappapp
rm -r build/Kappapp
rm -rf build/Kappapp

Kappapp.tar.gz: build/Kappapp.tar.gz

Expand Down Expand Up @@ -204,7 +208,7 @@ KappaBin:

build/KappaBin.zip: build/KappaBin
zip -y -r $@ build/KappaBin
rm -r build/KappaBin
rm -rf build/KappaBin

KappaBin.zip: build/KappaBin.zip

Expand All @@ -228,12 +232,12 @@ Kappapp.app:
+$(MAKE) clean
+$(MAKE) build/Kappapp.app

build/Info.plist: gui/Info.plist.skel $(wildcard .git/refs/heads/*)
build/Info.plist: gui/resources/Info.plist.skel $(wildcard .git/refs/heads/*)
mkdir -p build
sed -e s/'\(.*\)\".*tag: \([^,\"]*\)[,\"].*/\1\"\2\"'/g $< | \
sed -e 's/\$$Format:%D\$$'/"$$(git describe --always --dirty || echo unkown)"/ > $@

build/Kappa.iconset: gui/Kappa-Logo.png
build/Kappa.iconset: gui/resources/Kappa-Logo.png
mkdir -p build
rm -rf $@ && mkdir $@
sips -z 16 16 $< --out $@/icon_16x16.png
Expand Down
2 changes: 1 addition & 1 deletion core/parameters/exception_without_parameter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ let to_json exceptions_caught_and_uncaught =
( "caught",
JsonUtil.of_list caught_exception_to_json
exceptions_caught_and_uncaught.caught_error_list );
( "caught",
( "caught_to_ui",
JsonUtil.of_list caught_exception_to_json
exceptions_caught_and_uncaught.caught_error_list_to_ui );
( "uncaught",
Expand Down
28 changes: 23 additions & 5 deletions core/parameters/exception_without_parameter.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
* en Automatique. All rights reserved. This file is distributed
* under the terms of the GNU Library General Public License *)

(* The logic in this files describes a `degraded` mode for exceptions, before
the remanent_parameters were loaded.
these exceptions did not stop execution, so `uncaught` and `caught` may not
be good naming here. `caught` here basically add a trace to uncaught info
TODO: revamp/rename this?
*)

type uncaught_exception

exception Uncaught_exception of uncaught_exception
Expand All @@ -31,7 +38,10 @@ val build_caught_exception :
string option -> string option -> exn -> string list -> caught_exception

val add_uncaught_error :
?to_ui:bool -> uncaught_exception -> exceptions_caught_and_uncaught -> exceptions_caught_and_uncaught
?to_ui:bool ->
uncaught_exception ->
exceptions_caught_and_uncaught ->
exceptions_caught_and_uncaught

val stringlist_of_exception : exn -> string list -> string list
val stringlist_of_uncaught : uncaught_exception -> string list -> string list
Expand All @@ -41,10 +51,18 @@ val pp_exception : Format.formatter -> exn -> unit
val pp_uncaught : Format.formatter -> uncaught_exception -> unit
val pp_caught : Format.formatter -> caught_exception -> unit
val empty_exceptions_caught_and_uncaught : exceptions_caught_and_uncaught
val is_empty_exceptions_caught_and_uncaught : exceptions_caught_and_uncaught -> bool
val get_caught_exception_list : exceptions_caught_and_uncaught -> caught_exception list
val get_caught_exception_list_to_ui : exceptions_caught_and_uncaught -> caught_exception list
val get_uncaught_exception_list : exceptions_caught_and_uncaught -> uncaught_exception list

val is_empty_exceptions_caught_and_uncaught :
exceptions_caught_and_uncaught -> bool

val get_caught_exception_list :
exceptions_caught_and_uncaught -> caught_exception list

val get_caught_exception_list_to_ui :
exceptions_caught_and_uncaught -> caught_exception list

val get_uncaught_exception_list :
exceptions_caught_and_uncaught -> uncaught_exception list

val get_uncaught_exception_list_to_ui :
exceptions_caught_and_uncaught -> uncaught_exception list
Expand Down
4 changes: 2 additions & 2 deletions core/simulation/dune
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
(targets resource_strings.ml)
(deps
../../dev/load_files_into_ocaml_string_vars.sh
../../gui/shared/flux.js
../../gui/viz/common.js)
../../gui/js_lib/flux.js
../../gui/js_lib/viz/common.js)
(action
(with-stdout-to
%{targets}
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
(js_of_ocaml-lwt ( = 5.7.0 ))
(js_of_ocaml-ppx ( = 5.7.0 ))
(js_of_ocaml-tyxml ( = 5.7.0 ))
(ppx_inline_test ( = v0.15.1 ))
kappa-binaries
kappa-agents
)
Expand Down
14 changes: 7 additions & 7 deletions gui/JsSim.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ let onload (_ : 'a) : bool Js.t =
let () =
Dom.appendChild main (Tyxml_js.To_dom.of_div (Panel_projects.content ()))
in
let () = Dom.appendChild main (Panel_tab.navtabs ()) in
let () = Dom.appendChild main (Panel_tab.navcontents ()) in
let () = Dom.appendChild main (Panel_tabs.navtabs ()) in
let () = Dom.appendChild main (Panel_tabs.navcontents ()) in
let () =
Dom.appendChild main (Tyxml_js.To_dom.of_div (Panel_settings.content ()))
Dom.appendChild main (Tyxml_js.To_dom.of_div (Panel_preferences.content ()))
in

let () = Panel_projects.onload () in
let () = Panel_tab.onload () in
let () = Panel_settings.onload () in
let () = Panel_tabs.onload () in
let () = Panel_preferences.onload () in

let _ =
Dom_html.window##.onresize :=
Dom_html.handler (fun _ ->
let () = Panel_projects.onresize () in
let () = Panel_tab.onresize () in
let () = Panel_settings.onresize () in
let () = Panel_tabs.onresize () in
let () = Panel_preferences.onresize () in
Js._true)
in
Js._true
Expand Down
42 changes: 27 additions & 15 deletions gui/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
In this dir is the code for the webapp and electron app
In this dir is the code for the _Kappapp_ webapp and electron app!

`.ml` files starting by a capital, as `KaSimWorker.ml` are executable files.
### Directory structure

TODO: revamp this as it's really imprecise and incomplete
`viz/main.js` contains the code for the main electron process
`runtime_processes.ml` setups the manager and runs the local subprocesses on electron
`JsSim.ml` defines the window DOM and its different components
- Panel_tab contains all tabs from a project, other panels manages settings, projects...
- tabs are the tabs of different tools in a given project, some are in fact subtabs in the right hand side of the editor, which is called subpanel_editor
- state_* files manages in part the logic in the given app parts
The `.ml` files in this directory , as `KaSimWorker.ml` are executable files, as indicated by their capitalization.

`JsSim.ml` defines the main executable, with the window DOM and its different components,
while the other are the different workers that can be ran as webworkers/threads in the app.

`secret_method_name` indicate a method that should be called only by inherited classes. However this was not respected thoroughly so it has not be replaced
by `inherit parent as super ... super#private_method` which fills this need in the language
`ui` contains the different panels and tabs making the interface, along with their logic. The logic tries to match in limited fashion the view and controller roles in a Control/Model/View architecture (controller for controller_* files in `ui/tab_editor`)

`_mpi` indicates the message passing interface of the different processes and web workers (threads) used
Files in `state` manages state logic from different app part, similar to a `model` in a Control/Model/View architecture.

`entry_point` contains the entry point info for the html main page of the webapp and electron app config

`lib`, `lib_no_jsoo`, `js_lib` contain libs used by the webapp. Those in `lib_no_jsoo` do not depend on js_of_ocaml. Libs in `js_lib` are written in javascript`, while the other are in ocaml.

`resources` contains resources used to build the webapp and electron app.

### Runtime
The app is divided in :
- the interface
- the agents: kasim, kamoha, kasa, kastor. Which are handling respectively the simulation, the project files, the static analysis, the analysis of traces and computation of stories

There are two different runtimes for the agents (see `state_runtime.ml`) :
- webworkers/threads for the agents (`runtime_web_workers.ml`).
There are two different runtimes for the agents (see `state/state_runtime.ml`) :
- webworkers/threads for the agents (`state/runtime_web_workers.ml`).
This is the mode ran in the browser. The app uses a matching client to communicate with each thread e.g. `kasa_client` which are writing _messages_ to the agents. The threads are spawned as _workers_ e.g. `KaSaWorker`, which use the _message passing interface_ logic e.g. `kasa_mpi`, which parses the messages and compute what is asked by the clients.
There is a special case for the kasim agent. There is an `KaSimAsEmbedded` option that run it in the main thread and not in a separated web worker thread. The logic for the agent is then not in the `_mpi` but in `kasim_runtime` as it is used in both the _worker_ and in the main thread. Mode with kasim in a separated thread is called `KasimAsWebWorker`
- processes for the agents (`runtime_processes.ml`)
- processes for the agents (`state/runtime_processes.ml`)
This is the mode ran in the electron app. The app uses clients to communicate with agent processes.
Agents processes are defined in `core/agent` with a name starting with a capital letter. `mpi` files are in in different directories of `core` .
Kamoha agent and kastor agent have names that doesn't end in agent, which can be misleading. (TODO: change this?)
The app here spawns two processes, Kastor and KappaSwitchman. The KappaSwitchman one then spawns the other agents and manages the communication between them and the app.
Kastor is not included with the others as it can be communicated to in raw, and it doesn't have an internal state.

### Misc notes

This code uses js_of_ocaml, the React lib for reactive programming, and lwt.
Some changes in the code might cause parts of the code to not be called. This happens even with the removal of the dead code elimination in js_of_ocaml. A way to fix these issues is to use the Hooked lib in `lib_no_jsoo`, that is meant to replace the React lib with hooks, which don't have this issue. Replacing `React` by `Hooked` in place, and converting the signals to Hooked and back should help if this issue arise again.
Feel free to add an implementation for needed `React` functions that are not yet implemented in `lib_no_jsoo/hooked.ml`.

`secret_method_name` indicate a method that should be called only by inherited classes. However this was not respected thoroughly so it has not be replaced
by `inherit parent as super ... super#private_method` which fills this need in the language

`_mpi` indicates the message passing interface of the different processes and web workers (threads) used

40 changes: 19 additions & 21 deletions gui/dune
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
(library
(name kappa_js_lib)
(modules Common Hooked)
(libraries js_of_ocaml-lwt lwt_react)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags :standard -w +a -open Js_of_ocaml))

(rule
(with-stdout-to
js_of_ocaml_flags
Expand All @@ -18,7 +10,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaSimWorker)
(libraries kappa_js_lib kappa_json_api)
(libraries kappa_webapp_lib kappa_json_api)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -28,7 +20,7 @@
-open
Js_of_ocaml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_json_api))

Expand All @@ -39,7 +31,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaSaWorker)
(libraries kappa_js_lib kappa_kasa_export)
(libraries kappa_webapp_lib kappa_kasa_export)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -49,7 +41,7 @@
-open
Js_of_ocaml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_kasa_export))

Expand All @@ -60,7 +52,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaStorWorker)
(libraries kappa_js_lib kappa_cflow)
(libraries kappa_webapp_lib kappa_cflow)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -70,7 +62,7 @@
-open
Js_of_ocaml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_cflow))

Expand All @@ -81,7 +73,7 @@
(flags
(:include js_of_ocaml_flags)))
(modules KaMoHaWorker)
(libraries kappa_js_lib kappa_grammar)
(libraries kappa_webapp_lib kappa_grammar)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags :standard -w +a))
Expand All @@ -95,18 +87,17 @@
(modules
:standard
\
Common
Hooked
KaSimWorker
KaSaWorker
KaStorWorker
KaMoHaWorker)
(libraries
js_of_ocaml-tyxml
lwt_react
kappa_js_lib
kappa_webapp_lib
kappa_json_api
kappa_parameters)
kappa_parameters
kappa_webapp_ui)
(preprocess
(pps js_of_ocaml-ppx tyxml-ppx))
(flags
Expand All @@ -118,7 +109,7 @@
-open
Js_of_ocaml_tyxml
-open
Kappa_js_lib
Kappa_webapp_lib
-open
Kappa_json_api
-open
Expand All @@ -140,4 +131,11 @@
-open
Kappa_logging
-open
Kappa_cflow))
Kappa_cflow
-open
Kappa_webapp_ui
-open
Kappa_webapp_ui
-open
Kappa_webapp_state
))
1 change: 1 addition & 0 deletions gui/entry_point/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`entry_point` contains the entry point info for the html main page of the webapp and electron app config
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading