From b296c387951a755d48f9c159eb8fe5c339716aed Mon Sep 17 00:00:00 2001 From: benarc Date: Mon, 11 May 2020 12:16:26 +0100 Subject: [PATCH 1/2] Working events extension --- lnbits/extensions/events/README.md | 14 +++---------- lnbits/extensions/events/config.json.example | 2 +- lnbits/extensions/events/crud.py | 3 ++- .../events/templates/events/_api_docs.html | 14 ++----------- .../events/templates/events/display.html | 1 + .../events/templates/events/register.html | 21 +++++++++++++------ .../events/templates/events/ticket.html | 16 ++++++++++++-- lnbits/extensions/events/views_api.py | 9 ++++++++ 8 files changed, 47 insertions(+), 33 deletions(-) diff --git a/lnbits/extensions/events/README.md b/lnbits/extensions/events/README.md index 2772945..9108519 100644 --- a/lnbits/extensions/events/README.md +++ b/lnbits/extensions/events/README.md @@ -1,11 +1,3 @@ -

Example Extension

-

*tagline*

-This is an example extension to help you organise and build you own. - -Try to include an image - - - -

If your extension has API endpoints, include useful ones here

- -curl -H "Content-type: application/json" -X POST https://YOUR-LNBITS/YOUR-EXTENSION/api/v1/EXAMPLE -d '{"amount":"100","memo":"example"}' -H "X-Api-Key: YOUR_WALLET-ADMIN/INVOICE-KEY" +

Events

+

Events: Sell and register event tickets

+Events alows you to make a wave of tickets for an event, each ticket is in the form of a unqiue QRcode, which the user presents at registration. Events comes with a shareable ticket scanner, which can be used to register attendees. diff --git a/lnbits/extensions/events/config.json.example b/lnbits/extensions/events/config.json.example index 3c9055d..6bc144a 100644 --- a/lnbits/extensions/events/config.json.example +++ b/lnbits/extensions/events/config.json.example @@ -1,6 +1,6 @@ { "name": "Events", - "short_description": "Sell/register event tickets", + "short_description": "Sell and register event tickets", "icon": "local_activity", "contributors": ["benarc"] } diff --git a/lnbits/extensions/events/crud.py b/lnbits/extensions/events/crud.py index 6c8503b..b35a4bf 100644 --- a/lnbits/extensions/events/crud.py +++ b/lnbits/extensions/events/crud.py @@ -9,7 +9,7 @@ from .models import Tickets, Events #######TICKETS######## -def create_ticket(wallet: str, event: str, name: str, email: str) -> Tickets: +def create_ticket(wallet: str, event: str, name: str, email: str) -> Tickets: with open_ext_db("events") as db: eventdata = get_event(event) sold = eventdata.sold + 1 @@ -78,6 +78,7 @@ def update_event(event_id: str, **kwargs) -> Events: q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) with open_ext_db("events") as db: db.execute(f"UPDATE events SET {q} WHERE id = ?", (*kwargs.values(), event_id)) + row = db.fetchone("SELECT * FROM events WHERE id = ?", (event_id,)) return Events(**row) if row else None diff --git a/lnbits/extensions/events/templates/events/_api_docs.html b/lnbits/extensions/events/templates/events/_api_docs.html index c2a71b0..0caedae 100644 --- a/lnbits/extensions/events/templates/events/_api_docs.html +++ b/lnbits/extensions/events/templates/events/_api_docs.html @@ -7,21 +7,11 @@ > -
Events: Sell and register tickets for an event
-

Events alows you to make a wave of tickets for an event. Once an attendee has paid for a ticket they get a unqiue code. Events comes with a shareable scanning frontend, so you can register the attendees
+

Events: Sell and register ticket waves for an event
+

Events alows you to make a wave of tickets for an event, each ticket is in the form of a unqiue QRcode, which the user presents at registration. Events comes with a shareable ticket scanner, which can be used to register attendees.
Created by, Ben Arc

- - - - - diff --git a/lnbits/extensions/events/templates/events/display.html b/lnbits/extensions/events/templates/events/display.html index 4579197..04658c4 100644 --- a/lnbits/extensions/events/templates/events/display.html +++ b/lnbits/extensions/events/templates/events/display.html @@ -154,6 +154,7 @@ axios .post('/events/api/v1/tickets/' + self.paymentCheck, { event: '{{ event_id }}', + event_name: '{{ event_name }}', name: self.formDialog.data.name, email: self.formDialog.data.email }) diff --git a/lnbits/extensions/events/templates/events/register.html b/lnbits/extensions/events/templates/events/register.html index e64e462..c7caea8 100644 --- a/lnbits/extensions/events/templates/events/register.html +++ b/lnbits/extensions/events/templates/events/register.html @@ -84,6 +84,7 @@ type="text/css" href="{{ url_for('static', filename='vendor/vue-qrcode-reader@2.2.0/vue-qrcode-reader.min.css') }}" /> + {% endblock %} {% block scripts %} {% assets filters='rjsmin', output='__bundle__/core/chart.js', @@ -135,6 +136,9 @@ } }, methods: { + hoverEmail: function (tmp) { + this.tickets.data.emailtemp = tmp + }, closeCamera: function () { this.sendCamera.show = false }, @@ -144,19 +148,21 @@ decodeQR: function (res) { this.sendCamera.show = false var self = this - + LNbits.api .request('GET', '/events/api/v1/register/ticket/' + res) .then(function (response) { + self.$q.notify({ + type: 'positive', + message: 'Registered!' + }) self.tickets = response.data.map(function (obj) { - self.$q.notify({ - timeout: 5, - type: 'positive', - message: 'Registered!' - }) return mapEvents(obj) }) }) + .catch(function (error) { + LNbits.utils.notifyApiError(error) + }) }, getEventTickets: function () { var self = this @@ -171,6 +177,9 @@ return mapEvents(obj) }) }) + .catch(function (error) { + LNbits.utils.notifyApiError(error) + }) } }, created: function () { diff --git a/lnbits/extensions/events/templates/events/ticket.html b/lnbits/extensions/events/templates/events/ticket.html index c6d0a14..f8eaf93 100644 --- a/lnbits/extensions/events/templates/events/ticket.html +++ b/lnbits/extensions/events/templates/events/ticket.html @@ -7,7 +7,7 @@

{{ ticket_name }} Ticket


- Bookmark or screenshot this page,
+ Bookmark, print or screenshot this page,
and present it for registration!

@@ -17,6 +17,10 @@ :options="{width: 340}" class="rounded-borders" > +
+ + Print @@ -28,7 +32,15 @@ Vue.component(VueQrcode.name, VueQrcode) new Vue({ el: '#vue', - mixins: [windowMixin] + mixins: [windowMixin], + data: function () { + return {} + }, + methods: { + printWindow: function () { + window.print() + } + } }) {% endblock %} diff --git a/lnbits/extensions/events/views_api.py b/lnbits/extensions/events/views_api.py index 8a856df..e04ee8b 100644 --- a/lnbits/extensions/events/views_api.py +++ b/lnbits/extensions/events/views_api.py @@ -155,6 +155,15 @@ def api_event_tickets(wallet_id, event_id): @events_ext.route("/api/v1/register/ticket/", methods=["GET"]) def api_event_register_ticket(ticket_id): + + ticket = get_ticket(ticket_id) + + if not ticket: + return jsonify({"message": "Ticket does not exist."}), HTTPStatus.FORBIDDEN + + if ticket.registered == True: + return jsonify({"message": "Ticket already registered"}), HTTPStatus.FORBIDDEN + return jsonify([ticket._asdict() for ticket in reg_ticket(ticket_id)]), HTTPStatus.OK From c099885bbb4ba650156f88ee7fdbbfda63389f14 Mon Sep 17 00:00:00 2001 From: benarc Date: Mon, 11 May 2020 12:34:16 +0100 Subject: [PATCH 2/2] Changed extension name to Support Tickets --- lnbits/extensions/lnticket/config.json | 6 ------ lnbits/extensions/lnticket/config.json.example | 6 ++++++ .../extensions/lnticket/templates/lnticket/_api_docs.html | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 lnbits/extensions/lnticket/config.json create mode 100644 lnbits/extensions/lnticket/config.json.example diff --git a/lnbits/extensions/lnticket/config.json b/lnbits/extensions/lnticket/config.json deleted file mode 100644 index 8207de1..0000000 --- a/lnbits/extensions/lnticket/config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "LNTicket", - "short_description": "Pay-per-word LN ticket system", - "icon": "contact_support", - "contributors": ["benarc"] -} diff --git a/lnbits/extensions/lnticket/config.json.example b/lnbits/extensions/lnticket/config.json.example new file mode 100644 index 0000000..dc45ece --- /dev/null +++ b/lnbits/extensions/lnticket/config.json.example @@ -0,0 +1,6 @@ +{ + "name": "Support Tickets", + "short_description": "LN support ticket system", + "icon": "contact_support", + "contributors": ["benarc"] +} diff --git a/lnbits/extensions/lnticket/templates/lnticket/_api_docs.html b/lnbits/extensions/lnticket/templates/lnticket/_api_docs.html index 59bd1b3..8f08ace 100644 --- a/lnbits/extensions/lnticket/templates/lnticket/_api_docs.html +++ b/lnbits/extensions/lnticket/templates/lnticket/_api_docs.html @@ -7,8 +7,8 @@ > -
LNTickets: Get paid sats for questions
-

LNTickets allow you to charge people per word for contacting you. Applications incude, paid support ticketting, PAYG language services, such as translation, spam protection (people have to pay to contact you).
+

Support Tickets: Get paid sats to answer questions
+

Charge people per word for contacting you. Possible applications incude, paid support ticketing, PAYG language services, contact spam protection (people have to pay to contact you).
Created by, Ben Arc