From af687df9debe43a3a25fb81a73e2677af6e90c88 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Sat, 11 Feb 2023 08:13:26 -0500 Subject: [PATCH] Added shit. --- resources/static/embedded-json-enc.js | 47 +++++++++++++++++++ resources/static/{ => vendor}/htmx.org@1.8.5 | 0 resources/static/{ => vendor}/json-enc.js | 0 .../static/{ => vendor}/uikit-icons.min.js | 0 resources/static/{ => vendor}/uikit.min.css | 0 resources/static/{ => vendor}/uikit.min.js | 0 resources/templates/actions.html | 3 -- resources/templates/base.html | 10 ++-- .../partials/actions/create_security.html | 16 +++++-- src/main.rs | 18 +++---- 10 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 resources/static/embedded-json-enc.js rename resources/static/{ => vendor}/htmx.org@1.8.5 (100%) rename resources/static/{ => vendor}/json-enc.js (100%) rename resources/static/{ => vendor}/uikit-icons.min.js (100%) rename resources/static/{ => vendor}/uikit.min.css (100%) rename resources/static/{ => vendor}/uikit.min.js (100%) diff --git a/resources/static/embedded-json-enc.js b/resources/static/embedded-json-enc.js new file mode 100644 index 0000000..afacf62 --- /dev/null +++ b/resources/static/embedded-json-enc.js @@ -0,0 +1,47 @@ +(function () { + function _isNumeric(str) { + if (typeof str != "string") { + return false + } + return !isNaN(str) && !isNaN(parseFloat(str)); + } + + function _cast(str) { + return _isNumeric(str) ? parseFloat(str) : str; + } + + function _addAssocToDict(obj, key, value) { + let splittedKey = Array.isArray(key) ? key : key.split("."); + const keyToAdd = splittedKey.shift(); + const isTerminal = splittedKey.length === 0; + if (isTerminal) { + obj[keyToAdd] = _cast(value); + return obj; + } + if (!(keyToAdd in obj)) { + obj[keyToAdd] = {}; + } + return _addAssocToDict(obj[keyToAdd], splittedKey, value); + } + + function _createPayload(params) { + let ret = {}; + for (let key of Object.keys(params)) { + _addAssocToDict(ret, key, params[key]); + } + return ret; + } + + htmx.defineExtension('json-enc', { + onEvent: function (name, evt) { + if (name === "htmx:configRequest") { + evt.detail.headers['Content-Type'] = "application/json"; + } + }, + + encodeParameters: function (xhr, parameters, elt) { + xhr.overrideMimeType('text/json'); + return (JSON.stringify(_createPayload(parameters))); + } + }); +})(); \ No newline at end of file diff --git a/resources/static/htmx.org@1.8.5 b/resources/static/vendor/htmx.org@1.8.5 similarity index 100% rename from resources/static/htmx.org@1.8.5 rename to resources/static/vendor/htmx.org@1.8.5 diff --git a/resources/static/json-enc.js b/resources/static/vendor/json-enc.js similarity index 100% rename from resources/static/json-enc.js rename to resources/static/vendor/json-enc.js diff --git a/resources/static/uikit-icons.min.js b/resources/static/vendor/uikit-icons.min.js similarity index 100% rename from resources/static/uikit-icons.min.js rename to resources/static/vendor/uikit-icons.min.js diff --git a/resources/static/uikit.min.css b/resources/static/vendor/uikit.min.css similarity index 100% rename from resources/static/uikit.min.css rename to resources/static/vendor/uikit.min.css diff --git a/resources/static/uikit.min.js b/resources/static/vendor/uikit.min.js similarity index 100% rename from resources/static/uikit.min.js rename to resources/static/vendor/uikit.min.js diff --git a/resources/templates/actions.html b/resources/templates/actions.html index 982b5c6..6f52ddb 100644 --- a/resources/templates/actions.html +++ b/resources/templates/actions.html @@ -24,9 +24,6 @@
- - -
diff --git a/resources/templates/base.html b/resources/templates/base.html index 3144491..69cf45d 100644 --- a/resources/templates/base.html +++ b/resources/templates/base.html @@ -4,11 +4,11 @@ ledger - - - - - + + + + + diff --git a/resources/templates/partials/actions/create_security.html b/resources/templates/partials/actions/create_security.html index 2c0d246..b2da1c7 100644 --- a/resources/templates/partials/actions/create_security.html +++ b/resources/templates/partials/actions/create_security.html @@ -1,7 +1,17 @@ - +
+ +
+ +
+ +
{%include "partials/actions/submit_button.html"%} diff --git a/src/main.rs b/src/main.rs index 006b0e9..baf3207 100644 --- a/src/main.rs +++ b/src/main.rs @@ -445,15 +445,15 @@ mod cli_test { assert_eq!(logic.process_events_count, 1); } - // #[test] - // fn run_web_ui() { - // let cmd = command_line_parser(); - // let m = cmd.get_matches_from(vec!["test", "webui", "run"]); - // let mut logic = TestCommandLineLogic::new(); - // let mut conn = Connection::open_in_memory().unwrap(); - // process_command_line(&mut conn, &m, &mut logic); - // assert_eq!(logic.run_webui_count, 1); - // } + #[test] + fn run_web_ui() { + let cmd = command_line_parser(); + let m = cmd.get_matches_from(vec!["test", "wui", "run"]); + let mut logic = TestCommandLineLogic::new(); + let mut conn = Connection::open_in_memory().unwrap(); + process_command_line(&mut conn, &m, &mut logic); + assert_eq!(logic.run_webui_count, 1); + } } struct ProCommandLineLogic {}