mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 20:36:16 +02:00
UI to change the wordlist.
This commit is contained in:
@@ -32,6 +32,13 @@ async def get_or_create_shop_by_wallet(wallet: str) -> Optional[Shop]:
|
|||||||
return Shop(**dict(row)) if row else None
|
return Shop(**dict(row)) if row else None
|
||||||
|
|
||||||
|
|
||||||
|
async def set_wordlist(shop: int, wordlist: str) -> Optional[Shop]:
|
||||||
|
await db.execute(
|
||||||
|
"UPDATE shops SET wordlist = ? WHERE id = ?", (wordlist, shop),
|
||||||
|
)
|
||||||
|
return await get_shop(shop)
|
||||||
|
|
||||||
|
|
||||||
async def add_item(shop: int, name: str, description: str, image: Optional[str], price: int, unit: str,) -> int:
|
async def add_item(shop: int, name: str, description: str, image: Optional[str], price: int, unit: str,) -> int:
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
"""
|
"""
|
||||||
|
@@ -85,6 +85,25 @@ new Vue({
|
|||||||
LNbits.utils.notifyApiError(err)
|
LNbits.utils.notifyApiError(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
async updateWordlist() {
|
||||||
|
try {
|
||||||
|
await LNbits.api.request(
|
||||||
|
'PUT',
|
||||||
|
'/offlineshop/api/v1/offlineshop/wordlist',
|
||||||
|
this.selectedWallet.inkey,
|
||||||
|
{wordlist: this.offlineshop.wordlist}
|
||||||
|
)
|
||||||
|
this.$q.notify({
|
||||||
|
message: `Wordlist updated. Counter reset.`,
|
||||||
|
timeout: 700
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
LNbits.utils.notifyApiError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loadShop()
|
||||||
|
},
|
||||||
async sendItem() {
|
async sendItem() {
|
||||||
let {id, name, image, description, price, unit} = this.itemDialog.data
|
let {id, name, image, description, price, unit} = this.itemDialog.data
|
||||||
const data = {
|
const data = {
|
||||||
|
@@ -90,6 +90,10 @@
|
|||||||
|
|
||||||
<q-card class="q-pa-sm col-5">
|
<q-card class="q-pa-sm col-5">
|
||||||
<q-card-section class="q-pa-none text-center">
|
<q-card-section class="q-pa-none text-center">
|
||||||
|
<div class="row">
|
||||||
|
<h5 class="text-subtitle1 q-my-none">Wallet Shop</h5>
|
||||||
|
</div>
|
||||||
|
|
||||||
<q-form class="q-gutter-md">
|
<q-form class="q-gutter-md">
|
||||||
<q-select
|
<q-select
|
||||||
filled
|
filled
|
||||||
@@ -114,6 +118,29 @@
|
|||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
||||||
|
<q-card class="q-pa-sm col-5">
|
||||||
|
<q-card-section class="q-pa-none text-center">
|
||||||
|
<div class="row">
|
||||||
|
<h5 class="text-subtitle1 q-my-none">Wordlist</h5>
|
||||||
|
</div>
|
||||||
|
<q-form class="q-gutter-md q-y-md" @submit="updateWordlist">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col q-mx-lg">
|
||||||
|
<q-input v-model="offlineshop.wordlist" dense filled autogrow />
|
||||||
|
</div>
|
||||||
|
<div class="col q-mx-lg">
|
||||||
|
<q-btn unelevated color="deep-purple" type="submit">
|
||||||
|
Update Wordlist
|
||||||
|
</q-btn>
|
||||||
|
<q-btn @click="loadShop" flat color="grey" class="q-ml-auto"
|
||||||
|
>Reset</q-btn
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-form>
|
||||||
|
</q-card-section>
|
||||||
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 col-md-5 q-gutter-y-md">
|
<div class="col-12 col-md-5 q-gutter-y-md">
|
||||||
|
@@ -7,11 +7,13 @@ from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
|||||||
from . import offlineshop_ext
|
from . import offlineshop_ext
|
||||||
from .crud import (
|
from .crud import (
|
||||||
get_or_create_shop_by_wallet,
|
get_or_create_shop_by_wallet,
|
||||||
|
set_wordlist,
|
||||||
add_item,
|
add_item,
|
||||||
update_item,
|
update_item,
|
||||||
get_items,
|
get_items,
|
||||||
delete_item_from_shop,
|
delete_item_from_shop,
|
||||||
)
|
)
|
||||||
|
from .models import ShopCounter
|
||||||
|
|
||||||
|
|
||||||
@offlineshop_ext.route("/api/v1/offlineshop", methods=["GET"])
|
@offlineshop_ext.route("/api/v1/offlineshop", methods=["GET"])
|
||||||
@@ -70,3 +72,24 @@ async def api_delete_item(item_id):
|
|||||||
shop = await get_or_create_shop_by_wallet(g.wallet.id)
|
shop = await get_or_create_shop_by_wallet(g.wallet.id)
|
||||||
await delete_item_from_shop(shop.id, item_id)
|
await delete_item_from_shop(shop.id, item_id)
|
||||||
return "", HTTPStatus.NO_CONTENT
|
return "", HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
|
@offlineshop_ext.route("/api/v1/offlineshop/wordlist", methods=["PUT"])
|
||||||
|
@api_check_wallet_key("invoice")
|
||||||
|
@api_validate_post_request(
|
||||||
|
schema={"wordlist": {"type": "string", "empty": True, "nullable": True, "required": True},}
|
||||||
|
)
|
||||||
|
async def api_set_wordlist():
|
||||||
|
wordlist = g.data["wordlist"].split("\n") if g.data["wordlist"] else None
|
||||||
|
wordlist = [word.strip() for word in wordlist if word.strip()]
|
||||||
|
|
||||||
|
shop = await get_or_create_shop_by_wallet(g.wallet.id)
|
||||||
|
if not shop:
|
||||||
|
return "", HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
|
updated_shop = await set_wordlist(shop.id, "\n".join(wordlist))
|
||||||
|
if not updated_shop:
|
||||||
|
return "", HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
|
ShopCounter.reset(updated_shop)
|
||||||
|
return "", HTTPStatus.OK
|
||||||
|
Reference in New Issue
Block a user