Merge branch 'master' into lnticketsflat

This commit is contained in:
Ben Arc 2021-08-13 23:24:12 +01:00
commit 7bdbe08732
3 changed files with 81 additions and 21 deletions

View File

@ -29,14 +29,14 @@ async def create_copilot(
lnurl_title: Optional[str] = None,
show_message: Optional[int] = 0,
show_ack: Optional[int] = 0,
show_price: Optional[int] = 0,
show_price: Optional[str] = None,
amount_made: Optional[int] = None,
) -> Copilots:
copilot_id = urlsafe_short_hash()
await db.execute(
"""
INSERT INTO copilots (
INSERT INTO copilot.copilots (
id,
"user",
lnurl_toggle,
@ -55,15 +55,14 @@ async def create_copilot(
show_message,
show_ack,
show_price,
lnurl_title,
amount_made
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
copilot_id,
user,
lnurl_toggle,
int(lnurl_toggle),
wallet,
title,
animation1,
@ -76,10 +75,9 @@ async def create_copilot(
animation2webhook,
animation3webhook,
lnurl_title,
show_message,
show_ack,
int(show_message),
int(show_ack),
show_price,
lnurl_title,
0,
),
)
@ -89,21 +87,21 @@ async def create_copilot(
async def update_copilot(copilot_id: str, **kwargs) -> Optional[Copilots]:
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
await db.execute(
f"UPDATE copilots SET {q} WHERE id = ?", (*kwargs.values(), copilot_id)
f"UPDATE copilot.copilots SET {q} WHERE id = ?", (*kwargs.values(), copilot_id)
)
row = await db.fetchone("SELECT * FROM copilots WHERE id = ?", (copilot_id,))
row = await db.fetchone("SELECT * FROM copilot.copilots WHERE id = ?", (copilot_id,))
return Copilots.from_row(row) if row else None
async def get_copilot(copilot_id: str) -> Copilots:
row = await db.fetchone("SELECT * FROM copilots WHERE id = ?", (copilot_id,))
row = await db.fetchone("SELECT * FROM copilot.copilots WHERE id = ?", (copilot_id,))
return Copilots.from_row(row) if row else None
async def get_copilots(user: str) -> List[Copilots]:
rows = await db.fetchall("""SELECT * FROM copilots WHERE "user" = ?""", (user,))
rows = await db.fetchall("""SELECT * FROM copilot.copilots WHERE "user" = ?""", (user,))
return [Copilots.from_row(row) for row in rows]
async def delete_copilot(copilot_id: str) -> None:
await db.execute("DELETE FROM copilots WHERE id = ?", (copilot_id,))
await db.execute("DELETE FROM copilot.copilots WHERE id = ?", (copilot_id,))

View File

@ -31,3 +31,46 @@ async def m001_initial(db):
);
"""
)
async def m002_fix_data_types(db):
"""
Fix data types.
"""
if(db.type != "SQLITE"):
await db.execute("ALTER TABLE copilot.copilots ALTER COLUMN show_price TYPE TEXT;")
# If needed, migration for SQLite (RENAME not working properly)
#
# await db.execute(
# f"""
# CREATE TABLE copilot.new_copilots (
# id TEXT NOT NULL PRIMARY KEY,
# "user" TEXT,
# title TEXT,
# lnurl_toggle INTEGER,
# wallet TEXT,
# animation1 TEXT,
# animation2 TEXT,
# animation3 TEXT,
# animation1threshold INTEGER,
# animation2threshold INTEGER,
# animation3threshold INTEGER,
# animation1webhook TEXT,
# animation2webhook TEXT,
# animation3webhook TEXT,
# lnurl_title TEXT,
# show_message INTEGER,
# show_ack INTEGER,
# show_price TEXT,
# amount_made INTEGER,
# fullscreen_cam INTEGER,
# iframe_url TEXT,
# timestamp TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
# );
# """
# )
#
# await db.execute("INSERT INTO copilot.new_copilots SELECT * FROM copilot.copilots;")
# await db.execute("DROP TABLE IF EXISTS copilot.copilots;")
# await db.execute("ALTER TABLE copilot.new_copilots RENAME TO copilot.copilots;")

View File

@ -49,6 +49,7 @@
<q-th style="width: 5%"></q-th>
<q-th style="width: 5%"></q-th>
<q-th style="width: 5%"></q-th>
<q-th style="width: 5%"></q-th>
<q-th
v-for="col in props.cols"
@ -59,13 +60,13 @@
<div v-if="col.name == 'id'"></div>
<div v-else>{{ col.label }}</div>
</q-th>
<q-th auto-width></q-th>
<!-- <q-th auto-width></q-th> -->
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td auto-width>
<q-td>
<q-btn
unelevated
dense
@ -77,7 +78,7 @@
<q-tooltip> Panel </q-tooltip>
</q-btn>
</q-td>
<q-td auto-width>
<q-td>
<q-btn
unelevated
dense
@ -89,7 +90,7 @@
<q-tooltip> Compose window </q-tooltip>
</q-btn>
</q-td>
<q-td auto-width>
<q-td>
<q-btn
flat
dense
@ -101,7 +102,7 @@
<q-tooltip> Delete copilot </q-tooltip>
</q-btn>
</q-td>
<q-td auto-width>
<q-td>
<q-btn
flat
dense
@ -206,8 +207,9 @@
dense
v-model.trim="formDialogCopilot.data.animation1threshold"
type="number"
label="From *sats"
:min="10"
step="1"
label="From *sats (min. 10)"
:rules="[ val => val >= 10 || 'Please use minimum 10' ]"
>
</q-input>
</div>
@ -254,6 +256,7 @@
dense
v-model="formDialogCopilot.data.animation2threshold"
type="number"
step="1"
label="From *sats"
:min="formDialogCopilot.data.animation1threshold"
>
@ -302,6 +305,7 @@
dense
v-model="formDialogCopilot.data.animation3threshold"
type="number"
step="1"
label="From *sats"
:min="formDialogCopilot.data.animation2threshold"
>
@ -469,8 +473,10 @@
cancelCopilot: function (data) {
var self = this
self.formDialogCopilot.show = false
self.clearFormDialogCopilot()
},
closeFormDialog: function () {
this.clearFormDialogCopilot()
this.formDialog.data = {
is_unique: false
}
@ -512,6 +518,7 @@
.then(function (response) {
self.CopilotLinks.push(mapCopilot(response.data))
self.formDialogCopilot.show = false
self.clearFormDialogCopilot()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
@ -526,7 +533,9 @@
this.g.user.wallets[0].inkey
)
.then(function (response) {
self.CopilotLinks = response.data.map(mapCopilot)
if(response.data){
self.CopilotLinks = response.data.map(mapCopilot)
}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
@ -619,11 +628,21 @@
})
self.CopilotLinks.push(mapCopilot(response.data))
self.formDialogCopilot.show = false
self.clearFormDialogCopilot()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
clearFormDialogCopilot(){
this.formDialogCopilot.data = {
lnurl_toggle: false,
show_message: false,
show_ack: false,
show_price: 'None',
title: ''
}
},
exportcopilotCSV: function () {
var self = this
LNbits.utils.exportCSV(self.CopilotsTable.columns, this.CopilotLinks)