list marketplaces with stalls in index.html
This commit is contained in:
parent
807eb59192
commit
6a5c0bd8ee
3 changed files with 135 additions and 3 deletions
|
|
@ -201,6 +201,13 @@ async def get_diagonalley_stalls(wallet_ids: Union[str, List[str]]) -> List[Stal
|
|||
)
|
||||
return [Stalls(**row) for row in rows]
|
||||
|
||||
async def get_diagonalley_stalls_by_ids(stall_ids: Union[str, List[str]]) -> List[Stalls]:
|
||||
q = ",".join(["?"] * len(stall_ids))
|
||||
rows = await db.fetchall(
|
||||
f"SELECT * FROM diagonalley.stalls WHERE id IN ({q})", (*stall_ids,)
|
||||
)
|
||||
return [Stalls(**row) for row in rows]
|
||||
|
||||
|
||||
async def delete_diagonalley_stall(stall_id: str) -> None:
|
||||
await db.execute("DELETE FROM diagonalley.stalls WHERE id = ?", (stall_id,))
|
||||
|
|
@ -346,9 +353,11 @@ async def get_diagonalley_market(market_id: str) -> Optional[Market]:
|
|||
async def get_diagonalley_market_stalls(market_id: str):
|
||||
rows = await db.fetchall(
|
||||
"SELECT * FROM diagonalley.market_stalls WHERE marketid = ?", (market_id,)
|
||||
)
|
||||
)
|
||||
|
||||
return [{**row} for row in rows]
|
||||
ids = [row["stallid"] for row in rows]
|
||||
|
||||
return await get_diagonalley_stalls_by_ids(ids)
|
||||
|
||||
|
||||
async def create_diagonalley_market(data: CreateMarket):
|
||||
|
|
|
|||
|
|
@ -669,6 +669,80 @@
|
|||
</q-card-section>
|
||||
</q-card>
|
||||
|
||||
<q-card v-if="markets.length">
|
||||
<!-- MARKETPLACES TABLE -->
|
||||
<q-card-section>
|
||||
<div class="row items-center no-wrap q-mb-md">
|
||||
<div class="col">
|
||||
<h5 class="text-subtitle1 q-my-none">Marketplaces</h5>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<q-btn flat color="grey" @click="exportStallsCSV"
|
||||
>Export to CSV</q-btn
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<q-table
|
||||
dense
|
||||
flat
|
||||
:data="markets"
|
||||
row-key="id"
|
||||
:columns="marketTable.columns"
|
||||
:pagination.sync="marketTable.pagination"
|
||||
>
|
||||
{% raw %}
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
<q-th auto-width></q-th>
|
||||
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
||||
{{ col.label }}
|
||||
</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-btn
|
||||
unelevated
|
||||
dense
|
||||
size="xs"
|
||||
icon="storefront"
|
||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
type="a"
|
||||
:href="'/diagonalley/' + props.row.id"
|
||||
target="_blank"
|
||||
></q-btn>
|
||||
<q-tooltip> Link to pass to stall relay </q-tooltip>
|
||||
</q-td>
|
||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||
{{ col.value }}
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
flat
|
||||
dense
|
||||
size="xs"
|
||||
@click="openStallUpdateDialog(props.row.id)"
|
||||
icon="edit"
|
||||
color="light-blue"
|
||||
></q-btn>
|
||||
<q-btn
|
||||
flat
|
||||
dense
|
||||
size="xs"
|
||||
@click="deleteStall(props.row.id)"
|
||||
icon="cancel"
|
||||
color="pink"
|
||||
></q-btn>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
{% endraw %}
|
||||
</q-table>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
|
||||
<q-card>
|
||||
<!-- ZONES TABLE -->
|
||||
<q-card-section>
|
||||
|
|
@ -817,6 +891,17 @@
|
|||
|
||||
const mapMarkets = obj => {
|
||||
obj._data = _.clone(obj)
|
||||
obj.stores = []
|
||||
LNbits.api
|
||||
.request('GET', `/diagonalley/api/v1/markets/${obj.id}/stalls`, null)
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
obj.stores = response.data.map(s => s.name).toString()
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
return obj
|
||||
}
|
||||
|
||||
|
|
@ -832,6 +917,7 @@
|
|||
products: [],
|
||||
orders: [],
|
||||
stalls: [],
|
||||
markets: [],
|
||||
zones: [],
|
||||
zoneOptions: [],
|
||||
customerKeys: [],
|
||||
|
|
@ -1015,6 +1101,31 @@
|
|||
rowsPerPage: 10
|
||||
}
|
||||
},
|
||||
marketTable: {
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
align: 'left',
|
||||
label: 'ID',
|
||||
field: 'id'
|
||||
},
|
||||
{
|
||||
name: 'name',
|
||||
align: 'left',
|
||||
label: 'Name',
|
||||
field: 'name'
|
||||
},
|
||||
{
|
||||
name: 'stores',
|
||||
align: 'left',
|
||||
label: 'Stores',
|
||||
field: 'stores'
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
rowsPerPage: 10
|
||||
}
|
||||
},
|
||||
zonesTable: {
|
||||
columns: [
|
||||
{
|
||||
|
|
@ -1517,12 +1628,14 @@
|
|||
.then(response => {
|
||||
if (response.data) {
|
||||
this.markets = response.data.map(mapMarkets)
|
||||
console.log(this.markets)
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
|
||||
openShopUpdateDialog: function (linkId) {
|
||||
var self = this
|
||||
var link = _.findWhere(self.markets, {id: linkId})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from base64 import urlsafe_b64encode
|
||||
from http import HTTPStatus
|
||||
from typing import List
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import Request
|
||||
|
|
@ -33,6 +34,7 @@ from .crud import (
|
|||
delete_diagonalley_stall,
|
||||
delete_diagonalley_zone,
|
||||
get_diagonalley_market,
|
||||
get_diagonalley_market_stalls,
|
||||
get_diagonalley_markets,
|
||||
get_diagonalley_order,
|
||||
get_diagonalley_order_details,
|
||||
|
|
@ -42,6 +44,7 @@ from .crud import (
|
|||
get_diagonalley_products,
|
||||
get_diagonalley_stall,
|
||||
get_diagonalley_stalls,
|
||||
get_diagonalley_stalls_by_ids,
|
||||
get_diagonalley_zone,
|
||||
get_diagonalley_zones,
|
||||
update_diagonalley_market,
|
||||
|
|
@ -426,7 +429,8 @@ async def api_diagonalley_stall_order(
|
|||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/markets")
|
||||
async def api_diagonalley_orders(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
async def api_diagonalley_markets(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
# await get_diagonalley_market_stalls(market_id="FzpWnMyHQMcRppiGVua4eY")
|
||||
try:
|
||||
return [
|
||||
market.dict()
|
||||
|
|
@ -436,6 +440,12 @@ async def api_diagonalley_orders(wallet: WalletTypeInfo = Depends(get_key_type))
|
|||
return {"message": "We could not retrieve the markets."}
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/markets/{market_id}/stalls")
|
||||
async def api_diagonalley_market_stalls(market_id: str):
|
||||
stall_ids = await get_diagonalley_market_stalls(market_id)
|
||||
return stall_ids
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/markets")
|
||||
@diagonalley_ext.put("/api/v1/markets/{market_id}")
|
||||
async def api_diagonalley_stall_create(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue