Switching lnurl links from model to crud
This commit is contained in:
parent
c749da80dd
commit
ba7e11e30d
14 changed files with 100 additions and 180 deletions
|
|
@ -29,12 +29,10 @@
|
|||
:pagination.sync="tempsTable.pagination"
|
||||
>
|
||||
<temp v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
<q-tr :props="props">
|
||||
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
||||
${ col.label }
|
||||
</q-th>
|
||||
<q-th auto-width>LNURL-pay</q-th>
|
||||
<q-th auto-width>LNURL-withdraw</q-th>
|
||||
</q-tr>
|
||||
</temp>
|
||||
|
||||
|
|
@ -46,27 +44,42 @@
|
|||
:props="props"
|
||||
>
|
||||
${ col.value }
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
unelevated
|
||||
dense
|
||||
size="sm"
|
||||
v-if="col.name == 'lnurlpayamount'"
|
||||
icon="qr_code"
|
||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
class="q-mr-sm"
|
||||
@click="openUrlDialog(props.row.id)"
|
||||
></q-btn>
|
||||
<q-btn
|
||||
unelevated
|
||||
dense
|
||||
size="sm"
|
||||
v-if="col.name == 'lnurlwithdrawamount'"
|
||||
icon="qr_code"
|
||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
class="q-mr-sm"
|
||||
@click="openUrlDialog(props.row.id)"
|
||||
></q-btn>
|
||||
</q-td>
|
||||
></q-btn></q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
unelevated
|
||||
dense
|
||||
size="sm"
|
||||
icon="launch"
|
||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
type="a"
|
||||
:href="props.row.temp"
|
||||
target="_blank"
|
||||
><q-tooltip>Open public page</q-tooltip></q-btn
|
||||
></q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
unelevated
|
||||
dense
|
||||
size="md"
|
||||
copy="copy"
|
||||
@click="copyText(props.row.id)"
|
||||
><q-tooltip>Click to copy</q-tooltip
|
||||
>${props.row.id.substring(0,6)}...</q-btn
|
||||
>
|
||||
</q-td>
|
||||
|
||||
|
||||
</q-tr>
|
||||
</template>
|
||||
|
||||
|
|
@ -151,11 +164,11 @@
|
|||
<q-dialog v-model="urlDialog.show" position="top">
|
||||
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
||||
<q-responsive :ratio="1" class="q-mx-xl q-mb-md">
|
||||
<lnbits-qrcode :value="urlDialog.data.shareUrl"></lnbits-qrcode>
|
||||
<lnbits-qrcode :value="urlDialog.data.lnurlpay"></lnbits-qrcode>
|
||||
</q-responsive>
|
||||
<div class="text-center q-mb-xl">
|
||||
<p style="word-break: break-all">
|
||||
<strong>${ urlDialog.data.name }</strong><br />${
|
||||
<strong>${ urlDialog.data.lnurlpay }</strong><br />${
|
||||
urlDialog.data.shareUrl }
|
||||
</p>
|
||||
</div>
|
||||
|
|
@ -163,7 +176,7 @@
|
|||
<q-btn
|
||||
outline
|
||||
color="grey"
|
||||
@click="copyText(urlDialog.data.shareUrl, 'Temp URL copied to clipboard!')"
|
||||
@click="copyText(urlDialog.data.lnurlpay, 'Temp URL copied to clipboard!')"
|
||||
>Copy URL</q-btn
|
||||
>
|
||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
|
||||
|
|
@ -199,18 +212,6 @@
|
|||
align: 'left',
|
||||
label: 'Wallet',
|
||||
field: 'wallet'
|
||||
},
|
||||
{
|
||||
name: 'lnurlwithdrawamount',
|
||||
align: 'left',
|
||||
label: 'LNURL Withdraw amount',
|
||||
field: 'lnurlwithdrawamount'
|
||||
},
|
||||
{
|
||||
name: 'lnurlpayamount',
|
||||
align: 'left',
|
||||
label: 'LNURL Pay amount',
|
||||
field: 'lnurlpayamount'
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
|
|
@ -379,141 +380,6 @@
|
|||
disabled: false
|
||||
}
|
||||
},
|
||||
deleteItem(id) {
|
||||
const [tempId, itemId] = id.split(':')
|
||||
const temp = _.findWhere(this.temps, {id: tempId})
|
||||
const wallet = _.findWhere(this.g.user.wallets, {
|
||||
id: temp.wallet
|
||||
})
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete this item?')
|
||||
.onOk(() => {
|
||||
temp.itemsMap.delete(id)
|
||||
const data = {
|
||||
items: [...temp.itemsMap.values()]
|
||||
}
|
||||
this.updateTempItems(temp.id, wallet, data)
|
||||
})
|
||||
},
|
||||
addItems() {
|
||||
const temp = _.findWhere(this.temps, {id: this.formDialog.data.temp})
|
||||
const wallet = _.findWhere(this.g.user.wallets, {
|
||||
id: temp.wallet
|
||||
})
|
||||
if (this.formDialog.data.id) {
|
||||
temp.itemsMap.set(this.formDialog.data.id, this.formDialog.data)
|
||||
}
|
||||
const data = {
|
||||
items: this.formDialog.data.id
|
||||
? [...temp.itemsMap.values()]
|
||||
: [...temp.items, this.formDialog.data]
|
||||
}
|
||||
this.updateTempItems(temp.id, wallet, data)
|
||||
},
|
||||
deleteAllItems(tempId) {
|
||||
const temp = _.findWhere(this.temps, {id: tempId})
|
||||
const wallet = _.findWhere(this.g.user.wallets, {
|
||||
id: temp.wallet
|
||||
})
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete ALL items?')
|
||||
.onOk(() => {
|
||||
temp.itemsMap.clear()
|
||||
const data = {
|
||||
items: []
|
||||
}
|
||||
this.updateTempItems(temp.id, wallet, data)
|
||||
})
|
||||
},
|
||||
updateTempItems(tempId, wallet, data) {
|
||||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
`/temp/api/v1/temps/${tempId}/items`,
|
||||
wallet.adminkey,
|
||||
data
|
||||
)
|
||||
.then(response => {
|
||||
this.temps = _.reject(this.temps, obj => {
|
||||
return obj.id == tempId
|
||||
})
|
||||
this.temps.push(mapTemp(response.data))
|
||||
this.closeformDialog()
|
||||
})
|
||||
.catch(error => {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
exportJSON(tempId) {
|
||||
const temp = _.findWhere(this.temps, {id: tempId})
|
||||
const data = [...temp.items]
|
||||
const filename = `items_${temp.id}.json`
|
||||
const json = JSON.stringify(data, null, 2)
|
||||
let status = Quasar.utils.exportFile(filename, json)
|
||||
if (status !== true) {
|
||||
this.$q.notify({
|
||||
message: 'Browser denied file download...',
|
||||
color: 'negative'
|
||||
})
|
||||
}
|
||||
},
|
||||
importJSON(tempId) {
|
||||
try {
|
||||
let input = document.getElementById('import')
|
||||
input.click()
|
||||
input.onchange = e => {
|
||||
let file = e.target.files[0]
|
||||
let reader = new FileReader()
|
||||
reader.readAsText(file, 'UTF-8')
|
||||
reader.onload = async readerEvent => {
|
||||
try {
|
||||
let content = readerEvent.target.result
|
||||
let data = JSON.parse(content).filter(
|
||||
obj => obj.title && obj.price
|
||||
)
|
||||
if (!data.length) {
|
||||
throw new Error('Invalid JSON or missing data.')
|
||||
}
|
||||
this.openFileDataDialog(tempId, data)
|
||||
} catch (error) {
|
||||
this.$q.notify({
|
||||
message: `Error importing file. ${error.message}`,
|
||||
color: 'negative'
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.$q.notify({
|
||||
message: 'Error importing file',
|
||||
color: 'negative'
|
||||
})
|
||||
}
|
||||
},
|
||||
openFileDataDialog(tempId, data) {
|
||||
const temp = _.findWhere(this.temps, {id: tempId})
|
||||
const wallet = _.findWhere(this.g.user.wallets, {
|
||||
id: temp.wallet
|
||||
})
|
||||
data.forEach(item => {
|
||||
item.formattedPrice = LNbits.utils.formatCurrency(
|
||||
Number(item.price).toFixed(2),
|
||||
temp.currency
|
||||
)
|
||||
})
|
||||
this.fileDataDialog.data = data
|
||||
this.fileDataDialog.count = data.length
|
||||
this.fileDataDialog.show = true
|
||||
this.fileDataDialog.import = () => {
|
||||
let updatedData = {
|
||||
items: [...temp.items, ...data]
|
||||
}
|
||||
this.updateTempItems(temp.id, wallet, updatedData)
|
||||
this.fileDataDialog.data = {}
|
||||
this.fileDataDialog.show = false
|
||||
}
|
||||
},
|
||||
openUrlDialog(id) {
|
||||
this.urlDialog.data = _.findWhere(this.temps, {id})
|
||||
this.urlDialog.show = true
|
||||
|
|
@ -522,6 +388,7 @@
|
|||
created: function () {
|
||||
if (this.g.user.wallets.length) {
|
||||
this.getTemps()
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue