From 1663442724c43cf763d56592f505981cd911cceb Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 12 Aug 2024 14:55:01 +0300 Subject: Use localstorage to track current commit. --- gn2/wqflask/templates/gn_editor.html | 12 ++++++---- gn2/wqflask/templates/gn_editor_commit.html | 27 ++++++++++++++++++----- gn2/wqflask/templates/gn_editor_results_page.html | 25 ++++++++++++++++----- gn2/wqflask/views.py | 13 ++++++++++- 4 files changed, 60 insertions(+), 17 deletions(-) (limited to 'gn2') diff --git a/gn2/wqflask/templates/gn_editor.html b/gn2/wqflask/templates/gn_editor.html index dca6d161..d55662c3 100644 --- a/gn2/wqflask/templates/gn_editor.html +++ b/gn2/wqflask/templates/gn_editor.html @@ -94,8 +94,7 @@ fixedWidthGutter: false, // boolean: true if the gutter should be fixed width theme: "ace/theme/dracula", // theme string from ace/theme or custom? scrollSpeed: 2, // number: the scroll speed index - - dragDelay: 0, // number: the drag delay before drag starts. it's 150ms for mac by default + dragDelay: 0, dragEnabled: true, // boolean: enable dragging focusTimout: 0, // number: the focus delay before focus starts. tooltipFollowsMouse: true, // boolean: true if the gutter tooltip should follow mouse @@ -112,8 +111,13 @@ foldStyle: 'markbegin', // enum: 'manual'/'markbegin'/'markbeginend'. mode: 'ace/mode/markdown' - } - + } + let hash = {{ hash|tojson }} + let filePath = {{ file_path|tojson }} + localStorage.setItem("gn_editor_sha" ,hash) + document.querySelector("#output").addEventListener("commitEvent", function(event){ + htmx.ajax("POST", "/editor/commit", {target: "#output", swap:"innerHTML",values: {'msg':event.detail.payload, 'content': editor.getValue(), "hash": localStorage.getItem("gn_editor_sha"), "file_path": filePath}}) + }) document.querySelector("#output").addEventListener("updateEditor", function(event){ editor.setOptions({ diff --git a/gn2/wqflask/templates/gn_editor_commit.html b/gn2/wqflask/templates/gn_editor_commit.html index 7c419c0b..0ea20adb 100644 --- a/gn2/wqflask/templates/gn_editor_commit.html +++ b/gn2/wqflask/templates/gn_editor_commit.html @@ -1,5 +1,5 @@
-
+

Commit your Changes

@@ -13,7 +13,7 @@

-
@@ -21,14 +21,29 @@

-

- +
+{% block js %} + + +{% endblock %} diff --git a/gn2/wqflask/templates/gn_editor_results_page.html b/gn2/wqflask/templates/gn_editor_results_page.html index 9453ba02..8cfa35dc 100644 --- a/gn2/wqflask/templates/gn_editor_results_page.html +++ b/gn2/wqflask/templates/gn_editor_results_page.html @@ -2,26 +2,39 @@
-

Results status

+

Results status - {{status}}


{% if error %} -

error occurred *error message hereh

+

Error-type: {{error}}

+

Error-message: + {{msg}}

{% else %}
-

Commit Sha: - commit hash +

New Commit Sha: + {{commit_sha}}


Commit Message: - commit message + {{message}}

{% endif %} -
+
+{% block js %} + + + +{% endblock %} diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index cfcbf150..14929b28 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -327,7 +327,18 @@ def editor_settings(): def commit_editor(): if request.method == "GET": return render_template("gn_editor_commit.html") - return render_template("gn_editor_results_page.html") + results = requests.post("http://localhost:8091/commit", json={ + "content": request.form.get("content"), + "filename": request.form.get("file_path"), + "email": "test@gmail.com", #replace this from auth + "username": "usernm1", # replace this username + "commit_message": request.form.get("msg"), + "prev_commit": request.form.get("hash")}) + # check if error here and show results page + # use ok here + data = results.json() + data["filename"] = request.form.get("file_path") + return render_template("gn_editor_results_page.html", **data) @app.route("/gnqna/hist/", methods=["GET"]) -- cgit v1.2.3