From 362aa6f29558a7a366bcb20266d304788dd75f3c Mon Sep 17 00:00:00 2001 From: Matthew Dang Date: Sat, 7 Sep 2024 13:22:00 -0400 Subject: [PATCH 01/15] Adding Modal Adding basic Modal, haven't hooked up save functionality yet. --- climbdex/templates/climbCreation.html.j2 | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/climbdex/templates/climbCreation.html.j2 b/climbdex/templates/climbCreation.html.j2 index 1acc90e..3aa6d88 100644 --- a/climbdex/templates/climbCreation.html.j2 +++ b/climbdex/templates/climbCreation.html.j2 @@ -32,12 +32,57 @@ d="M2 6a6 6 0 1 1 10.174 4.31c-.203.196-.359.4-.453.619l-.762 1.769A.5.5 0 0 1 10.5 13a.5.5 0 0 1 0 1 .5.5 0 0 1 0 1l-.224.447a1 1 0 0 1-.894.553H6.618a1 1 0 0 1-.894-.553L5.5 15a.5.5 0 0 1 0-1 .5.5 0 0 1 0-1 .5.5 0 0 1-.46-.302l-.761-1.77a2 2 0 0 0-.453-.618A5.98 5.98 0 0 1 2 6m6-5a5 5 0 0 0-3.479 8.592c.263.254.514.564.676.941L5.83 12h4.342l.632-1.467c.162-.377.413-.687.676-.941A5 5 0 0 0 8 1" /> +
{% include 'footer.html.j2' %}
+ + + + + + From f085852ee1397b8fb3a213adecac97bcadb28d07 Mon Sep 17 00:00:00 2001 From: Matthew Dang Date: Tue, 10 Sep 2024 18:08:51 -0400 Subject: [PATCH 02/15] Hiding button if not logged in Checking if there is cookies and hide set boulder button if doesn't exist. --- climbdex/templates/climbCreation.html.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/climbdex/templates/climbCreation.html.j2 b/climbdex/templates/climbCreation.html.j2 index 3aa6d88..dfe5848 100644 --- a/climbdex/templates/climbCreation.html.j2 +++ b/climbdex/templates/climbCreation.html.j2 @@ -32,9 +32,11 @@ d="M2 6a6 6 0 1 1 10.174 4.31c-.203.196-.359.4-.453.619l-.762 1.769A.5.5 0 0 1 10.5 13a.5.5 0 0 1 0 1 .5.5 0 0 1 0 1l-.224.447a1 1 0 0 1-.894.553H6.618a1 1 0 0 1-.894-.553L5.5 15a.5.5 0 0 1 0-1 .5.5 0 0 1 0-1 .5.5 0 0 1-.46-.302l-.761-1.77a2 2 0 0 0-.453-.618A5.98 5.98 0 0 1 2 6m6-5a5 5 0 0 0-3.479 8.592c.263.254.514.564.676.941L5.83 12h4.342l.632-1.467c.162-.377.413-.687.676-.941A5 5 0 0 0 8 1" /> + {% if request.cookies %} + {% endif %} From f1cc8eb2dacad6d2886b712b54c760cc7fe2e858 Mon Sep 17 00:00:00 2001 From: Matthew Dang Date: Tue, 10 Sep 2024 18:09:29 -0400 Subject: [PATCH 03/15] Passing login_cookie passking login_cookie to hide button. --- climbdex/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/climbdex/views.py b/climbdex/views.py index 4f29c5a..b5e8d04 100644 --- a/climbdex/views.py +++ b/climbdex/views.py @@ -87,6 +87,7 @@ def create(): colors = climbdex.db.get_data(board_name, "colors", {"layout_id": layout_id}) app_url = boardlib.api.aurora.WEB_HOSTS[board_name] placement_positions = get_placement_positions(board_name, layout_id, size_id) + login_cookie = flask.request.cookies.get(f"{board_name}_login") return flask.render_template( "climbCreation.html.j2", app_url=app_url, From d6a8344a23fbb3d5d8542bb1c742c8343d3bbb35 Mon Sep 17 00:00:00 2001 From: Matthew Dang Date: Wed, 11 Sep 2024 00:22:02 -0400 Subject: [PATCH 04/15] First Working Adding Draft/Final, No Matching/Matching, and setter angle. First working version. --- climbdex/api.py | 53 ++++++++++++++++++++ climbdex/static/js/climbCreation.js | 63 ++++++++++++++++++++++++ climbdex/templates/climbCreation.html.j2 | 27 ++++++++-- climbdex/views.py | 1 + 4 files changed, 139 insertions(+), 5 deletions(-) diff --git a/climbdex/api.py b/climbdex/api.py index d7a67cb..9b7f80b 100644 --- a/climbdex/api.py +++ b/climbdex/api.py @@ -154,3 +154,56 @@ def api_save_ascent( except Exception as e: logging.error(f"Error in save_ascent: {str(e)}", exc_info=True) return flask.jsonify({"error": str(e)}), 500 + +@blueprint.route("/api/v2/climbs", methods=["POST"]) +@ValidateParameters(parameter_error) +def api_climbs( + board: str = Json(), + layout_id: int = Json(), + name: str = Json(), + description: str = Json(), + is_draft: bool = Json(), + frames: str = Json(), + angle: int = Json(), +): + if angle == -1: + angle = None + + try: + login_cookie = flask.request.cookies.get(f"{board}_login") + if not login_cookie: + return flask.jsonify({"error": "Login required"}), 401 + + login_info = flask.json.loads(login_cookie) + token = login_info["token"] + setter_id = login_info["user_id"] + frames_count=1 + frames_pace=0 + # print(board) + # print(token) + # print(layout_id) + # print(setter_id) + # print(name) + # print(description) + # print(is_draft) + # print(frames) + # print(frames_count) + # print(frames_pace) + # print(angle) + result = boardlib.api.aurora.save_climb( + board=board, + token=token, + layout_id=layout_id, + setter_id=setter_id, + name=name, + description=description, + is_draft=is_draft, + frames=frames, + frames_count=frames_count, + frames_pace=frames_pace, + angle=angle, + ) + return flask.jsonify(result) + except Exception as e: + logging.error(f"Error in save_ascent: {str(e)}", exc_info=True) + return flask.jsonify({"error": str(e)}), 500 \ No newline at end of file diff --git a/climbdex/static/js/climbCreation.js b/climbdex/static/js/climbCreation.js index 995126a..72712a5 100644 --- a/climbdex/static/js/climbCreation.js +++ b/climbdex/static/js/climbCreation.js @@ -42,6 +42,69 @@ document illuminateClimb(board, bluetoothPacket); }); +document + .getElementById("button-save-climb") + .addEventListener("click", function () { + const urlParams = new URLSearchParams(window.location.search); + const board = urlParams.get("board"); + const layout_id = parseInt(urlParams.get("layout")); + const name = document.getElementById("name").value; + const is_matching = document.querySelector('input[name="is_matching"]:checked').id === "matching"; + const hasDescription = document.getElementById("description").value != ""; + const description = (is_matching ? "" : "No matching.") + (hasDescription ? " " : "") + document.getElementById("description").value; + const is_draft = document.querySelector('input[name="is_draft"]:checked').id === "draft"; + const frames = getFrames(); + const angle = parseInt(document.getElementById("select-angle").value); + + const data = { + board: board, + layout_id: layout_id, + name: name, + description: description, + is_draft: is_draft, + frames: frames, + angle: angle, + }; + + console.log(data); + + fetch("/api/v2/climbs", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }) + .then((response) => { + if (!response.ok) { + throw new Error("Network response was not ok " + response.statusText); + } + return response.json(); + }) + .then((data) => { + const successAlert = document.querySelector(".alert-success"); + successAlert.style.display = "block"; + + setTimeout(() => { + successAlert.style.display = "none"; + const setModal = document.getElementById("div-set-modal"); + const modalInstance = bootstrap.Modal.getInstance(setModal); + if (modalInstance) { + modalInstance.hide(); + } + }, 3000); + }) + .catch((error) => { + console.error("Error:", error); + const errorAlert = document.querySelector(".alert-danger"); + errorAlert.style.display = "block"; + + setTimeout(() => { + errorAlert.style.display = "none"; + }, 3000); + }); + }); + const backAnchor = document.getElementById("anchor-back"); backAnchor.href = location.origin; if (document.referrer) { diff --git a/climbdex/templates/climbCreation.html.j2 b/climbdex/templates/climbCreation.html.j2 index dfe5848..04a0dd8 100644 --- a/climbdex/templates/climbCreation.html.j2 +++ b/climbdex/templates/climbCreation.html.j2 @@ -55,23 +55,40 @@ - - - From 2ceac09d4b8d041c80d6df4215f9aaffb529712f Mon Sep 17 00:00:00 2001 From: Matthew Dang Date: Wed, 11 Sep 2024 01:16:54 -0400 Subject: [PATCH 06/15] Reset set boulder modal Added reset boulder modal script. --- climbdex/templates/climbCreation.html.j2 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/climbdex/templates/climbCreation.html.j2 b/climbdex/templates/climbCreation.html.j2 index afcfa08..cd45833 100644 --- a/climbdex/templates/climbCreation.html.j2 +++ b/climbdex/templates/climbCreation.html.j2 @@ -103,6 +103,27 @@ + + From c77bfbdd935b311e2c32dca902aa6c5a0d19bc6c Mon Sep 17 00:00:00 2001 From: Matthew Dang Date: Wed, 11 Sep 2024 01:30:56 -0400 Subject: [PATCH 07/15] Formatting modal and button Cleaned up formatting. --- climbdex/api.py | 2 +- climbdex/templates/climbCreation.html.j2 | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/climbdex/api.py b/climbdex/api.py index efc0e9e..5e81739 100644 --- a/climbdex/api.py +++ b/climbdex/api.py @@ -195,5 +195,5 @@ def api_climbs( ) return flask.jsonify(result) except Exception as e: - logging.error(f"Error in save_ascent: {str(e)}", exc_info=True) + logging.error(f"Error in api_climbs: {str(e)}", exc_info=True) return flask.jsonify({"error": str(e)}), 500 \ No newline at end of file diff --git a/climbdex/templates/climbCreation.html.j2 b/climbdex/templates/climbCreation.html.j2 index cd45833..022ed39 100644 --- a/climbdex/templates/climbCreation.html.j2 +++ b/climbdex/templates/climbCreation.html.j2 @@ -35,6 +35,9 @@ d="M2 6a6 6 0 1 1 10.174 4.31c-.203.196-.359.4-.453.619l-.762 1.769A.5.5 0 0 1 10.5 13a.5.5 0 0 1 0 1 .5.5 0 0 1 0 1l-.224.447a1 1 0 0 1-.894.553H6.618a1 1 0 0 1-.894-.553L5.5 15a.5.5 0 0 1 0-1 .5.5 0 0 1 0-1 .5.5 0 0 1-.46-.302l-.761-1.77a2 2 0 0 0-.453-.618A5.98 5.98 0 0 1 2 6m6-5a5 5 0 0 0-3.479 8.592c.263.254.514.564.676.941L5.83 12h4.342l.632-1.467c.162-.377.413-.687.676-.941A5 5 0 0 0 8 1" /> + + +
{% if request.cookies %}
+
- +
+
Angle