mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-14 23:12:42 +02:00
improve and finish basic UI.
This commit is contained in:
@ -133,7 +133,7 @@
|
|||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<q-dialog v-model="formDialog.show" position="top" @hide="closeFormDialog">
|
<q-dialog v-model="formDialog.show" @hide="closeFormDialog">
|
||||||
<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="sendFormData" class="q-gutter-md">
|
<q-form @submit="sendFormData" class="q-gutter-md">
|
||||||
<q-select
|
<q-select
|
||||||
|
@ -15,6 +15,9 @@ async def lnurl_response(item_id):
|
|||||||
if not item:
|
if not item:
|
||||||
return jsonify({"status": "ERROR", "reason": "Item not found."})
|
return jsonify({"status": "ERROR", "reason": "Item not found."})
|
||||||
|
|
||||||
|
if not item.enabled:
|
||||||
|
return jsonify({"status": "ERROR", "reason": "Item disabled."})
|
||||||
|
|
||||||
rate = await get_fiat_rate(item.unit) if item.unit != "sat" else 1
|
rate = await get_fiat_rate(item.unit) if item.unit != "sat" else 1
|
||||||
price_msat = item.price * 1000 * rate
|
price_msat = item.price * 1000 * rate
|
||||||
|
|
||||||
|
@ -26,24 +26,31 @@ new Vue({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async imageAdded(file) {
|
openNewDialog() {
|
||||||
|
this.itemDialog.show = true
|
||||||
|
this.itemDialog.data = {...defaultItemData}
|
||||||
|
},
|
||||||
|
openUpdateDialog(itemId) {
|
||||||
|
this.itemDialog.show = true
|
||||||
|
let item = this.offlineshop.items.find(item => item.id === itemId)
|
||||||
|
this.itemDialog.data = item
|
||||||
|
},
|
||||||
|
imageAdded(file) {
|
||||||
|
let blobURL = URL.createObjectURL(file)
|
||||||
let image = new Image()
|
let image = new Image()
|
||||||
image.src = URL.createObjectURL(file)
|
image.src = blobURL
|
||||||
let canvas = document.getElementById('uploading-image')
|
|
||||||
image.onload = async () => {
|
image.onload = async () => {
|
||||||
|
let canvas = document.createElement('canvas')
|
||||||
canvas.setAttribute('width', 300)
|
canvas.setAttribute('width', 300)
|
||||||
canvas.setAttribute('height', 300)
|
canvas.setAttribute('height', 300)
|
||||||
await pica.resize(image, canvas)
|
await pica.resize(image, canvas)
|
||||||
this.itemDialog.data.image = canvas.toDataURL()
|
this.itemDialog.data.image = canvas.toDataURL()
|
||||||
|
this.itemDialog = {...this.itemDialog}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
imageCleared() {
|
imageCleared() {
|
||||||
this.itemDialog.data.image = null
|
this.itemDialog.data.image = null
|
||||||
let canvas = document.getElementById('uploading-image')
|
this.itemDialog = {...this.itemDialog}
|
||||||
canvas.setAttribute('height', 0)
|
|
||||||
canvas.setAttribute('width', 0)
|
|
||||||
let ctx = canvas.getContext('2d')
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
||||||
},
|
},
|
||||||
disabledAddItemButton() {
|
disabledAddItemButton() {
|
||||||
return (
|
return (
|
||||||
@ -73,34 +80,44 @@ new Vue({
|
|||||||
LNbits.utils.notifyApiError(err)
|
LNbits.utils.notifyApiError(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addItem() {
|
async sendItem() {
|
||||||
let {name, image, description, price, unit} = this.itemDialog.data
|
let {id, name, image, description, price, unit} = this.itemDialog.data
|
||||||
|
const data = {
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
image,
|
||||||
|
price,
|
||||||
|
unit
|
||||||
|
}
|
||||||
|
|
||||||
LNbits.api
|
try {
|
||||||
.request(
|
if (id) {
|
||||||
'POST',
|
await LNbits.api.request(
|
||||||
'/offlineshop/api/v1/offlineshop/items',
|
'PUT',
|
||||||
this.selectedWallet.inkey,
|
'/offlineshop/api/v1/offlineshop/items/' + id,
|
||||||
{
|
this.selectedWallet.inkey,
|
||||||
name,
|
data
|
||||||
description,
|
)
|
||||||
image,
|
} else {
|
||||||
price,
|
await LNbits.api.request(
|
||||||
unit
|
'POST',
|
||||||
}
|
'/offlineshop/api/v1/offlineshop/items',
|
||||||
)
|
this.selectedWallet.inkey,
|
||||||
.then(response => {
|
data
|
||||||
|
)
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
message: `Item '${this.itemDialog.data.name}' added.`,
|
message: `Item '${this.itemDialog.data.name}' added.`,
|
||||||
timeout: 700
|
timeout: 700
|
||||||
})
|
})
|
||||||
this.loadShop()
|
}
|
||||||
this.itemsDialog.show = false
|
} catch (err) {
|
||||||
this.itemsDialog.data = {...defaultItemData}
|
LNbits.utils.notifyApiError(err)
|
||||||
})
|
return
|
||||||
.catch(err => {
|
}
|
||||||
LNbits.utils.notifyApiError(err)
|
|
||||||
})
|
this.loadShop()
|
||||||
|
this.itemDialog.show = false
|
||||||
|
this.itemDialog.data = {...defaultItemData}
|
||||||
},
|
},
|
||||||
toggleItem(itemId) {
|
toggleItem(itemId) {
|
||||||
let item = this.offlineshop.items.find(item => item.id === itemId)
|
let item = this.offlineshop.items.find(item => item.id === itemId)
|
||||||
|
@ -9,10 +9,7 @@
|
|||||||
<h5 class="text-subtitle1 q-my-none">Items</h5>
|
<h5 class="text-subtitle1 q-my-none">Items</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="col q-ml-lg">
|
<div class="col q-ml-lg">
|
||||||
<q-btn
|
<q-btn unelevated color="deep-purple" @click="openNewDialog()"
|
||||||
unelevated
|
|
||||||
color="deep-purple"
|
|
||||||
@click="itemDialog.show = true"
|
|
||||||
>Add new item</q-btn
|
>Add new item</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@ -51,20 +48,27 @@
|
|||||||
target="_blank"
|
target="_blank"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td auto-width>{{ props.row.name }}</q-td>
|
<q-td auto-width class="text-center">{{ props.row.name }}</q-td>
|
||||||
<q-td auto-width> {{ props.row.description }} </q-td>
|
<q-td auto-width> {{ props.row.description }} </q-td>
|
||||||
<q-td class="text-right" auto-width>
|
<q-td class="text-center" auto-width>
|
||||||
<q-img
|
<img
|
||||||
v-if="props.row.image"
|
v-if="props.row.image"
|
||||||
:src="props.row.image"
|
:src="props.row.image"
|
||||||
:ratio="1"
|
style="height: 1.5em"
|
||||||
style="height: 1em"
|
|
||||||
/>
|
/>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td class="text-center" auto-width>
|
<q-td class="text-center" auto-width>
|
||||||
{{ props.row.price }} {{ props.row.unit }}
|
{{ props.row.price }} {{ props.row.unit }}
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
dense
|
||||||
|
size="xs"
|
||||||
|
@click="openUpdateDialog(props.row.id)"
|
||||||
|
icon="edit"
|
||||||
|
color="light-blue"
|
||||||
|
></q-btn>
|
||||||
<q-btn
|
<q-btn
|
||||||
unelevated
|
unelevated
|
||||||
dense
|
dense
|
||||||
@ -113,10 +117,10 @@
|
|||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<q-dialog v-model="itemDialog.show" position="top">
|
<q-dialog v-model="itemDialog.show">
|
||||||
<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-card-section>
|
<q-card-section>
|
||||||
<q-form @submit="addItem" class="q-gutter-md">
|
<q-form @submit="sendItem" class="q-gutter-md">
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
@ -136,12 +140,15 @@
|
|||||||
dense
|
dense
|
||||||
capture="environment"
|
capture="environment"
|
||||||
accept="image/jpeg, image/png"
|
accept="image/jpeg, image/png"
|
||||||
:max-file-size="1048576"
|
:max-file-size="3*1024**2"
|
||||||
label="Small image (optional)"
|
label="Small image (optional)"
|
||||||
clearable
|
clearable
|
||||||
@input="imageAdded"
|
@input="imageAdded"
|
||||||
@clear="imageCleared"
|
@clear="imageCleared"
|
||||||
>
|
>
|
||||||
|
<template v-if="itemDialog.data.image" v-slot:before>
|
||||||
|
<img style="height: 1em" :src="itemDialog.data.image" />
|
||||||
|
</template>
|
||||||
<template v-if="itemDialog.data.image" v-slot:append>
|
<template v-if="itemDialog.data.image" v-slot:append>
|
||||||
<q-icon
|
<q-icon
|
||||||
name="cancel"
|
name="cancel"
|
||||||
@ -150,7 +157,6 @@
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</q-file>
|
</q-file>
|
||||||
<canvas id="uploading-image"></canvas>
|
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
@ -175,8 +181,10 @@
|
|||||||
color="deep-purple"
|
color="deep-purple"
|
||||||
:disable="disabledAddItemButton()"
|
:disable="disabledAddItemButton()"
|
||||||
type="submit"
|
type="submit"
|
||||||
>Add item</q-btn
|
|
||||||
>
|
>
|
||||||
|
{% raw %}{{ itemDialog.data.id ? 'Update' : 'Add' }}{% endraw %}
|
||||||
|
Item
|
||||||
|
</q-btn>
|
||||||
</div>
|
</div>
|
||||||
<div class="col q-ml-lg">
|
<div class="col q-ml-lg">
|
||||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
||||||
|
Reference in New Issue
Block a user