Events extension mostly functional

Can register attendees via camera
This commit is contained in:
benarc 2020-05-10 18:10:45 +01:00
parent ea3b858695
commit 76510b7892
5 changed files with 63 additions and 13 deletions

View File

@ -113,4 +113,13 @@ def get_event_tickets(event_id: str, wallet_id: str) -> Tickets:
rows = db.fetchall("SELECT * FROM tickets WHERE wallet = ? AND event = ?", (wallet_id, event_id)) rows = db.fetchall("SELECT * FROM tickets WHERE wallet = ? AND event = ?", (wallet_id, event_id))
print(rows) print(rows)
return [Tickets(**row) for row in rows]
def reg_ticket(ticket_id: str) -> Tickets:
with open_ext_db("events") as db:
db.execute("UPDATE tickets SET registered = ? WHERE id = ?", (True, ticket_id))
ticket = db.fetchone("SELECT * FROM tickets WHERE id = ?", (ticket_id,))
print(ticket[2])
rows = db.fetchall("SELECT * FROM tickets WHERE event = ?", (ticket[2],))
return [Tickets(**row) for row in rows] return [Tickets(**row) for row in rows]

View File

@ -1,4 +1,5 @@
{% extends "public.html" %} {% block page %} {% extends "public.html" %} {% block page %}
<div class="row q-col-gutter-md justify-center"> <div class="row q-col-gutter-md justify-center">
<div class="col-12 col-md-7 col-lg-6 q-gutter-y-md"> <div class="col-12 col-md-7 col-lg-6 q-gutter-y-md">
<q-card class="q-pa-lg"> <q-card class="q-pa-lg">
@ -60,6 +61,22 @@
</q-card-section> </q-card-section>
</q-card> </q-card>
</div> </div>
<q-dialog v-model="sendCamera.show" position="top">
<q-card class="q-pa-lg q-pt-xl">
<div class="text-center q-mb-lg">
<qrcode-stream
@decode="decodeQR"
class="rounded-borders"
></qrcode-stream>
</div>
<div class="row q-mt-lg">
<q-btn @click="closeCamera" flat color="grey" class="q-ml-auto"
>Cancel</q-btn
>
</div>
</q-card>
</q-dialog>
</div> </div>
{% endblock %} {% block styles %} {% endblock %} {% block styles %}
<link <link
@ -69,9 +86,18 @@
/> />
{% endblock %} {% block scripts %} {% endblock %} {% block scripts %}
<script src="{{ url_for('static', filename='vendor/vue-qrcode@1.0.2/vue-qrcode.min.js') }}"></script> <script src="{{ url_for('static', filename='vendor/vue-qrcode@1.0.2/vue-qrcode.min.js') }}"></script>
{% assets filters='rjsmin', output='__bundle__/core/chart.js',
'vendor/moment@2.25.1/moment.min.js', 'vendor/chart.js@2.9.3/chart.min.js' %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %} {% assets filters='rjsmin', output='__bundle__/core/wallet.js',
'vendor/bolt11/utils.js', 'vendor/bolt11/decoder.js',
'vendor/vue-qrcode-reader@2.2.0/vue-qrcode-reader.min.js' %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
<script> <script>
Vue.component(VueQrcode.name, VueQrcode) Vue.component(VueQrcode.name, VueQrcode)
Vue.use(VueQrcodeReader)
var mapEvents = function (obj) { var mapEvents = function (obj) {
obj.date = Quasar.utils.date.formatDate( obj.date = Quasar.utils.date.formatDate(
new Date(obj.time * 1000), new Date(obj.time * 1000),
@ -103,7 +129,7 @@
} }
}, },
sendCamera: { sendCamera: {
show: true, show: false,
camera: 'auto' camera: 'auto'
} }
} }
@ -115,6 +141,23 @@
showCamera: function () { showCamera: function () {
this.sendCamera.show = true this.sendCamera.show = true
}, },
decodeQR: function (res) {
this.sendCamera.show = false
var self = this
LNbits.api
.request('GET', '/events/api/v1/register/ticket/' + res)
.then(function (response) {
self.tickets = response.data.map(function (obj) {
self.$q.notify({
timeout: 5,
type: 'positive',
message: 'Registered!'
})
return mapEvents(obj)
})
})
},
getEventTickets: function () { getEventTickets: function () {
var self = this var self = this
console.log('obj') console.log('obj')
@ -125,7 +168,6 @@
) )
.then(function (response) { .then(function (response) {
self.tickets = response.data.map(function (obj) { self.tickets = response.data.map(function (obj) {
console.log(obj)
return mapEvents(obj) return mapEvents(obj)
}) })
}) })
@ -136,11 +178,4 @@
} }
}) })
</script> </script>
{% assets filters='rjsmin', output='__bundle__/core/chart.js', {% endblock %}
'vendor/moment@2.25.1/moment.min.js', 'vendor/chart.js@2.9.3/chart.min.js' %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %} {% assets filters='rjsmin', output='__bundle__/core/wallet.js',
'vendor/bolt11/utils.js', 'vendor/bolt11/decoder.js',
'vendor/vue-qrcode-reader@2.2.0/vue-qrcode-reader.min.js' %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %} {% endblock %}

View File

@ -11,8 +11,9 @@
and present it for registration! and present it for registration!
</h5> </h5>
<br /> <br />
<qrcode <qrcode
:value="{{ ticket_id }}" :value="'{{ ticket_id }}'"
:options="{width: 340}" :options="{width: 340}"
class="rounded-borders" class="rounded-borders"
></qrcode> ></qrcode>

View File

@ -7,7 +7,7 @@ from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from lnbits.settings import WALLET from lnbits.settings import WALLET
from lnbits.extensions.events import events_ext from lnbits.extensions.events import events_ext
from .crud import create_ticket, get_ticket, get_tickets, delete_ticket, create_event, update_event, get_event, get_events, delete_event, get_event_tickets from .crud import create_ticket, get_ticket, get_tickets, delete_ticket, create_event, update_event, get_event, get_events, delete_event, get_event_tickets, reg_ticket
#########Events########## #########Events##########
@ -153,3 +153,8 @@ def api_event_tickets(wallet_id, event_id):
return jsonify([ticket._asdict() for ticket in get_event_tickets(wallet_id=wallet_id, event_id=event_id)]), HTTPStatus.OK return jsonify([ticket._asdict() for ticket in get_event_tickets(wallet_id=wallet_id, event_id=event_id)]), HTTPStatus.OK
@events_ext.route("/api/v1/register/ticket/<ticket_id>", methods=["GET"])
def api_event_register_ticket(ticket_id):
return jsonify([ticket._asdict() for ticket in reg_ticket(ticket_id)]), HTTPStatus.OK