From 1736198a7d9951aac8fefcdff49ef841da13e566 Mon Sep 17 00:00:00 2001 From: Ben Arc Date: Tue, 20 Apr 2021 14:33:41 +0100 Subject: [PATCH] localstorage paneltest --- .../copilot/templates/copilot/index.html | 21 ++++++++++++++- .../copilot/templates/copilot/panel.html | 15 ++++++----- lnbits/extensions/copilot/views.py | 27 +++++-------------- lnbits/extensions/copilot/views_api.py | 1 - 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/lnbits/extensions/copilot/templates/copilot/index.html b/lnbits/extensions/copilot/templates/copilot/index.html index 7b1657fed..94614aa10 100644 --- a/lnbits/extensions/copilot/templates/copilot/index.html +++ b/lnbits/extensions/copilot/templates/copilot/index.html @@ -497,10 +497,29 @@ LNbits.utils.notifyApiError(error) }) }, + getCopilot: function (copilot_id) { + var self = this + LNbits.api + .request( + 'GET', + '/copilot/api/v1/copilot/' + copilot_id, + this.g.user.wallets[0].inkey + ) + .then(function (response) { + return response.data + }) + .catch(function (error) { + LNbits.utils.notifyApiError(error) + }) + }, opencopilotCompose: function (copilot_id) { + localStorage.setItem( + 'copilot', + JSON.stringify(this.getCopilot(copilot_id)) + ) let params = 'scrollbars=no, resizable=no,status=no,location=no,toolbar=no,menubar=no,width=1722,height=972,left=200,top=200' - open('../copilot/cp/' + copilot_id, 'test', params) + open('../copilot/cp/', 'test', params) }, deleteCopilotLink: function (chargeId) { diff --git a/lnbits/extensions/copilot/templates/copilot/panel.html b/lnbits/extensions/copilot/templates/copilot/panel.html index be2a579ed..61e7b9a0f 100644 --- a/lnbits/extensions/copilot/templates/copilot/panel.html +++ b/lnbits/extensions/copilot/templates/copilot/panel.html @@ -15,9 +15,7 @@
-
- Title: {{ copilot.title }} -
+
Title:
@@ -120,7 +118,7 @@ openCompose: function () { let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=1722,height=972,left=200,top=200` - open('../copilot/cp/{{ copilot.id }}', 'test', params) + open('../copilot/cp/', 'test', params) }, animationBTN: function (name) { this.connection.send(name) @@ -130,7 +128,8 @@ } }, created: function () { - console.log('{{ copilot.id }}') + var copilot = JSON.parse(localStorage.getItem('copilot')) + console.log(copilot.id) if (location.protocol == 'https:') { console.log(location.protocol) @@ -139,7 +138,8 @@ document.domain + ':' + location.port + - '/copilot/ws/panel/{{ copilot.id }}' + '/copilot/ws/panel/' + + copilot.id ) } else { this.connection = new WebSocket( @@ -147,7 +147,8 @@ document.domain + ':' + location.port + - '/copilot/ws/panel/{{ copilot.id }}' + '/copilot/ws/panel/' + + copilot.id ) } this.connection.addEventListener('open', function (event) {}) diff --git a/lnbits/extensions/copilot/views.py b/lnbits/extensions/copilot/views.py index 86b55ebc7..ce552a170 100644 --- a/lnbits/extensions/copilot/views.py +++ b/lnbits/extensions/copilot/views.py @@ -21,29 +21,14 @@ async def index(): return await render_template("copilot/index.html", user=g.user) -@copilot_ext.route("/cp/") -async def compose(copilot_id): - copilot = await get_copilot(copilot_id) or abort( - HTTPStatus.NOT_FOUND, "Copilot link does not exist." - ) - if copilot.lnurl_toggle: - return await render_template( - "copilot/compose.html", - copilot=copilot, - lnurl=copilot.lnurl, - lnurl_toggle=copilot.lnurl_toggle, - ) - return await render_template( - "copilot/compose.html", copilot=copilot, lnurl_toggle=copilot.lnurl_toggle - ) +@copilot_ext.route("/cp/") +async def compose(): + return await render_template("copilot/compose.html") -@copilot_ext.route("/") -async def panel(copilot_id): - copilot = await get_copilot(copilot_id) or abort( - HTTPStatus.NOT_FOUND, "Copilot link does not exist." - ) - return await render_template("copilot/panel.html", copilot=copilot) +@copilot_ext.route("/pn/") +async def panel(): + return await render_template("copilot/panel.html") ##################WEBSOCKET ROUTES######################## diff --git a/lnbits/extensions/copilot/views_api.py b/lnbits/extensions/copilot/views_api.py index 360a29d5d..c7078c543 100644 --- a/lnbits/extensions/copilot/views_api.py +++ b/lnbits/extensions/copilot/views_api.py @@ -103,4 +103,3 @@ async def api_copilot_ws_relay(copilot_id, comment, data): await updater(data, comment, copilot_id) print(comment) return "", HTTPStatus.OK -