Small fixes + renames

This commit is contained in:
Fitti 2021-06-28 18:18:52 +02:00
parent 39844b257b
commit d24980aa3c
3 changed files with 36 additions and 33 deletions

View file

@ -243,8 +243,8 @@ async def delete_donation(donation_id: str) -> None:
async def update_donation(donation_id: str, **kwargs) -> Donation: async def update_donation(donation_id: str, **kwargs) -> Donation:
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
await db.execute(f"UPDATE form SET {q} WHERE id = ?", (*kwargs.values(), await db.execute(f"UPDATE Donations SET {q} WHERE id = ?",
donation_id)) (*kwargs.values(), donation_id))
row = await db.fetchone("SELECT * FROM Donations WHERE id = ?", row = await db.fetchone("SELECT * FROM Donations WHERE id = ?",
(donation_id,)) (donation_id,))
assert row, "Newly updated donation couldn't be retrieved" assert row, "Newly updated donation couldn't be retrieved"
@ -253,8 +253,8 @@ async def update_donation(donation_id: str, **kwargs) -> Donation:
async def update_service(service_id: str, **kwargs) -> Donation: async def update_service(service_id: str, **kwargs) -> Donation:
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
await db.execute(f"UPDATE form SET {q} WHERE id = ?", (*kwargs.values(), await db.execute(f"UPDATE Services SET {q} WHERE id = ?",
service_id)) (*kwargs.values(), service_id))
row = await db.fetchone("SELECT * FROM Services WHERE id = ?", row = await db.fetchone("SELECT * FROM Services WHERE id = ?",
(service_id,)) (service_id,))
assert row, "Newly updated service couldn't be retrieved" assert row, "Newly updated service couldn't be retrieved"

View file

@ -4,7 +4,7 @@
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md"> <div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
<q-card> <q-card>
<q-card-section> <q-card-section>
<q-btn unelevated color="deep-purple" @click="formDialog.show = true" <q-btn unelevated color="deep-purple" @click="serviceDialog.show = true"
>New Service</q-btn >New Service</q-btn
> >
</q-card-section> </q-card-section>
@ -62,7 +62,7 @@
flat flat
dense dense
size="xs" size="xs"
@click="updateformDialog(props.row.id)" @click="updateserviceDialog(props.row.id)"
icon="edit" icon="edit"
color="light-blue" color="light-blue"
></q-btn> ></q-btn>
@ -162,14 +162,14 @@
</q-card> </q-card>
</div> </div>
<q-dialog v-model="formDialog.show" position="top"> <q-dialog v-model="serviceDialog.show" position="top">
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card"> <q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
<q-form @submit="sendServiceData" class="q-gutter-md"> <q-form @submit="sendServiceData" class="q-gutter-md">
<q-select <q-select
filled filled
dense dense
emit-value emit-value
v-model="formDialog.data.wallet" v-model="serviceDialog.data.wallet"
:options="g.user.walletOptions" :options="g.user.walletOptions"
label="Wallet *" label="Wallet *"
> >
@ -177,7 +177,7 @@
<q-input <q-input
filled filled
dense dense
v-model.trim="formDialog.data.twitchuser" v-model.trim="serviceDialog.data.twitchuser"
type="name" type="name"
label="Twitch Username *" label="Twitch Username *"
></q-input> ></q-input>
@ -185,7 +185,7 @@
filled filled
dense dense
emit-value emit-value
v-model="formDialog.data.servicename" v-model="serviceDialog.data.servicename"
:options="servicenames" :options="servicenames"
label="Streamlabs" label="Streamlabs"
hint="The service you use for alerts. (Currently only Streamlabs)" hint="The service you use for alerts. (Currently only Streamlabs)"
@ -193,20 +193,20 @@
<q-input <q-input
filled filled
dense dense
v-model.trim="formDialog.data.client_id" v-model.trim="serviceDialog.data.client_id"
type="name" type="name"
label="Client ID *" label="Client ID *"
></q-input> ></q-input>
<q-input <q-input
filled filled
dense dense
v-model.trim="formDialog.data.client_secret" v-model.trim="serviceDialog.data.client_secret"
type="name" type="name"
label="Client Secret *" label="Client Secret *"
></q-input> ></q-input>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<q-btn <q-btn
v-if="formDialog.data.id" v-if="serviceDialog.data.id"
unelevated unelevated
color="deep-purple" color="deep-purple"
type="submit" type="submit"
@ -217,7 +217,7 @@
v-else v-else
unelevated unelevated
color="deep-purple" color="deep-purple"
:disable="formDialog.data.client_id == null || formDialog.data.client_secret == 0 || formDialog.data.twitchuser == null" :disable="serviceDialog.data.client_id == null || serviceDialog.data.client_secret == 0 || serviceDialog.data.twitchuser == null"
type="submit" type="submit"
>Create Service</q-btn >Create Service</q-btn
> >
@ -237,7 +237,7 @@
'YYYY-MM-DD HH:mm' 'YYYY-MM-DD HH:mm'
) )
obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.amount) obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.amount)
obj.displayUrl = ['/twitchalerts/', obj.id].join('') obj.displayUrl = ['/twitchalerts/api/v1/getaccess/', obj.id].join('')
return obj return obj
} }
@ -246,7 +246,7 @@
mixins: [windowMixin], mixins: [windowMixin],
data: function() { data: function() {
return { return {
servicenames: ["Streamlabs"], servicenames: ['Streamlabs'],
services: [], services: [],
donations: [], donations: [],
servicesTable: { servicesTable: {
@ -294,7 +294,7 @@
rowsPerPage: 10 rowsPerPage: 10
} }
}, },
formDialog: { serviceDialog: {
show: false, show: false,
data: {} data: {}
} }
@ -360,9 +360,9 @@
}, },
sendServiceData: function() { sendServiceData: function() {
var wallet = _.findWhere(this.g.user.wallets, { var wallet = _.findWhere(this.g.user.wallets, {
id: this.formDialog.data.wallet id: this.serviceDialog.data.wallet
}) })
var data = this.formDialog.data var data = this.serviceDialog.data
if (data.id) { if (data.id) {
this.updateService(wallet, data) this.updateService(wallet, data)
@ -377,22 +377,23 @@
.request('POST', '/twitchalerts/api/v1/services', wallet.inkey, data) .request('POST', '/twitchalerts/api/v1/services', wallet.inkey, data)
.then(function(response) { .then(function(response) {
self.services.push(mapTwitchAlerts(response.data)) self.services.push(mapTwitchAlerts(response.data))
self.formDialog.show = false self.serviceDialog.show = false
self.formDialog.data = {} self.serviceDialog.data = {}
}) })
.catch(function(error) { .catch(function(error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
updateformDialog: function(formId) { updateserviceDialog: function(serviceId) {
var link = _.findWhere(this.services, {id: formId}) var link = _.findWhere(this.services, {id: serviceId})
console.log(link.id) console.log(link.id)
this.formDialog.data.id = link.id this.serviceDialog.data.id = link.id
this.formDialog.data.wallet = link.wallet this.serviceDialog.data.wallet = link.wallet
this.formDialog.data.name = link.name this.serviceDialog.data.twitchuser = link.twitchuser
this.formDialog.data.description = link.description this.serviceDialog.data.servicename = link.servicename
this.formDialog.data.costpword = link.costpword this.serviceDialog.data.client_id = link.client_id
this.formDialog.show = true this.serviceDialog.data.client_secret = link.client_secret
this.serviceDialog.show = true
}, },
updateService: function(wallet, data) { updateService: function(wallet, data) {
var self = this var self = this
@ -410,8 +411,8 @@
return obj.id == data.id return obj.id == data.id
}) })
self.services.push(mapTwitchAlerts(response.data)) self.services.push(mapTwitchAlerts(response.data))
self.formDialog.show = false self.serviceDialog.show = false
self.formDialog.data = {} self.serviceDialog.data = {}
}) })
.catch(function(error) { .catch(function(error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)

View file

@ -157,7 +157,8 @@ async def api_get_services():
wallet_ids = (await get_user(g.wallet.user)).wallet_ids wallet_ids = (await get_user(g.wallet.user)).wallet_ids
services = [] services = []
for wallet_id in wallet_ids: for wallet_id in wallet_ids:
services += await get_services(wallet_id) new_services = await get_services(wallet_id)
services += new_services if new_services else []
return ( return (
jsonify([ jsonify([
service._asdict() for service in services service._asdict() for service in services
@ -172,7 +173,8 @@ async def api_get_donations():
wallet_ids = (await get_user(g.wallet.user)).wallet_ids wallet_ids = (await get_user(g.wallet.user)).wallet_ids
donations = [] donations = []
for wallet_id in wallet_ids: for wallet_id in wallet_ids:
donations += await get_donations(wallet_id) new_donations = await get_donations(wallet_id)
donations += new_donations if new_donations else []
return ( return (
jsonify([ jsonify([
donation._asdict() for donation in donations donation._asdict() for donation in donations