formatted

This commit is contained in:
ben 2022-12-14 00:06:36 +00:00
parent f506b010f6
commit 75e6252d23
6 changed files with 62 additions and 51 deletions

View File

@ -2,7 +2,6 @@ from typing import List
from . import db from . import db
from .models import Target from .models import Target
from loguru import logger
async def get_targets(source_wallet: str) -> List[Target]: async def get_targets(source_wallet: str) -> List[Target]:
@ -13,7 +12,6 @@ async def get_targets(source_wallet: str) -> List[Target]:
async def set_targets(source_wallet: str, targets: List[Target]): async def set_targets(source_wallet: str, targets: List[Target]):
logger.debug(targets)
async with db.connect() as conn: async with db.connect() as conn:
await conn.execute( await conn.execute(
"DELETE FROM splitpayments.targets WHERE source = ?", (source_wallet,) "DELETE FROM splitpayments.targets WHERE source = ?", (source_wallet,)
@ -25,5 +23,11 @@ async def set_targets(source_wallet: str, targets: List[Target]):
(source, wallet, percent, tag, alias) (source, wallet, percent, tag, alias)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
""", """,
(source_wallet, target.wallet, target.percent, target.tag, target.alias), (
source_wallet,
target.wallet,
target.percent,
target.tag,
target.alias,
),
) )

View File

@ -1,5 +1,6 @@
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
async def m001_initial(db): async def m001_initial(db):
""" """
Initial split payment table. Initial split payment table.
@ -92,7 +93,7 @@ async def m003_add_id_and_tag(db):
) )
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
""", """,
(urlsafe_short_hash(), row[0], row[1], row[2], '', row[3]), (urlsafe_short_hash(), row[0], row[1], row[2], "", row[3]),
) )
await db.execute("DROP TABLE splitpayments.splitpayments_old") await db.execute("DROP TABLE splitpayments.splitpayments_old")

View File

@ -10,7 +10,11 @@ function hashTargets(targets) {
} }
function isTargetComplete(target) { function isTargetComplete(target) {
return target.wallet && target.wallet.trim() !== '' && (target.percent > 0 || target.tag != '') return (
target.wallet &&
target.wallet.trim() !== '' &&
(target.percent > 0 || target.tag != '')
)
} }
new Vue({ new Vue({
@ -20,9 +24,11 @@ new Vue({
return { return {
selectedWallet: null, selectedWallet: null,
currentHash: '', // a string that must match if the edit data is unchanged currentHash: '', // a string that must match if the edit data is unchanged
targets: [{ targets: [
method: "split" {
}] method: 'split'
}
]
} }
}, },
computed: { computed: {
@ -43,8 +49,7 @@ new Vue({
this.targets.splice(index, 1) this.targets.splice(index, 1)
console.log(this.targets) console.log(this.targets)
this.$q.notify({ this.$q.notify({
message: message: 'Removed item. You must click to save manually.',
'Removed item. You must click to save manually.',
timeout: 500 timeout: 500
}) })
}, },
@ -62,16 +67,13 @@ new Vue({
this.currentHash = hashTargets(response.data) this.currentHash = hashTargets(response.data)
this.targets = response.data.concat({}) this.targets = response.data.concat({})
for (let i = 0; i < this.targets.length; i++) { for (let i = 0; i < this.targets.length; i++) {
if(this.targets[i].tag.length > 0){ if (this.targets[i].tag.length > 0) {
this.targets[i].method = "tag" this.targets[i].method = 'tag'
} else if (this.targets[i].percent.length > 0) {
this.targets[i].method = 'split'
} else {
this.targets[i].method = ''
} }
else if (this.targets[i].percent.length > 0){
this.targets[i].method = "split"
}
else{
this.targets[i].method = ""
}
} }
}) })
}, },
@ -80,11 +82,10 @@ new Vue({
this.getTargets() this.getTargets()
}, },
clearChanged(index) { clearChanged(index) {
if(this.targets[index].method == 'split'){ if (this.targets[index].method == 'split') {
this.targets[index].tag = null this.targets[index].tag = null
this.targets[index].method = 'split' this.targets[index].method = 'split'
} } else {
else{
this.targets[index].percent = null this.targets[index].percent = null
this.targets[index].method = 'tag' this.targets[index].method = 'tag'
} }
@ -94,7 +95,7 @@ new Vue({
if (this.targets[index].percent) { if (this.targets[index].percent) {
if (this.targets[index].percent > 100) this.targets[index].percent = 100 if (this.targets[index].percent > 100) this.targets[index].percent = 100
if (this.targets[index].percent < 0) this.targets[index].percent = 0 if (this.targets[index].percent < 0) this.targets[index].percent = 0
this.targets[index].tag = "" this.targets[index].tag = ''
} }
// not percentage // not percentage
@ -153,10 +154,9 @@ new Vue({
}, },
saveTargets() { saveTargets() {
for (let i = 0; i < this.targets.length; i++) { for (let i = 0; i < this.targets.length; i++) {
if (this.targets[i].tag != ''){ if (this.targets[i].tag != '') {
this.targets[i].percent = 0 this.targets[i].percent = 0
} } else {
else{
this.targets[i].tag = '' this.targets[i].tag = ''
} }
} }
@ -168,7 +168,12 @@ new Vue({
{ {
targets: this.targets targets: this.targets
.filter(isTargetComplete) .filter(isTargetComplete)
.map(({wallet, percent, tag, alias}) => ({wallet, percent, tag, alias})) .map(({wallet, percent, tag, alias}) => ({
wallet,
percent,
tag,
alias
}))
} }
) )
.then(response => { .then(response => {

View File

@ -77,5 +77,3 @@ async def on_invoice_paid(payment: Payment) -> None:
extra={"tag": "splitpayments"}, extra={"tag": "splitpayments"},
) )
logger.debug(f"paid split invoice: {checking_id}") logger.debug(f"paid split invoice: {checking_id}")

View File

@ -53,7 +53,6 @@
emit-value emit-value
></q-input> ></q-input>
<q-toggle <q-toggle
:false-value="'split'" :false-value="'split'"
:true-value="'tag'" :true-value="'tag'"
@ -97,7 +96,14 @@
> >
<q-tooltip>Add more</q-tooltip> <q-tooltip>Add more</q-tooltip>
</q-btn> </q-btn>
<q-btn v-if="t < targets.length - 1" @click="clearTarget(t)" round color="red" size="5px" icon="close"></q-btn> <q-btn
v-if="t < targets.length - 1"
@click="clearTarget(t)"
round
color="red"
size="5px"
icon="close"
></q-btn>
</div> </div>
<div class="row justify-evenly q-pa-lg"> <div class="row justify-evenly q-pa-lg">
<div> <div>

View File

@ -11,8 +11,6 @@ from . import splitpayments_ext
from .crud import get_targets, set_targets from .crud import get_targets, set_targets
from .models import Target, TargetPut from .models import Target, TargetPut
from loguru import logger
@splitpayments_ext.get("/api/v1/targets") @splitpayments_ext.get("/api/v1/targets")
async def api_targets_get(wallet: WalletTypeInfo = Depends(require_admin_key)): async def api_targets_get(wallet: WalletTypeInfo = Depends(require_admin_key)):
@ -27,7 +25,6 @@ async def api_targets_set(
body = await req.json() body = await req.json()
targets = [] targets = []
data = TargetPut.parse_obj(body["targets"]) data = TargetPut.parse_obj(body["targets"])
logger.debug(data)
for entry in data.__root__: for entry in data.__root__:
wallet = await get_wallet(entry.wallet) wallet = await get_wallet(entry.wallet)
if not wallet: if not wallet: