Add "clear today" functionality

to move a transaction to today and mark it cleared in one step

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-02-09 13:15:14 +01:00
parent d101c24b85
commit 00ecb36ab8
Signed by: luzifer
SSH Key Fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E

View File

@ -109,6 +109,16 @@
Move to Today
</button>
</li>
<li>
<button
class="dropdown-item"
:disabled="selectedTx.length < 1"
@click="clearToday"
>
<i class="fas fa-fw fa-copyright mr-1" />
Clear Today
</button>
</li>
<li>
<button
v-shortkey="['del']"
@ -484,6 +494,22 @@ export default {
methods: {
classFromNumber,
clearToday() {
return this.patchSelected([
{
op: 'replace',
path: '/time',
value: new Date(new Date().toISOString()
.split('T')[0]),
},
{
op: 'replace',
path: '/cleared',
value: true,
},
])
},
deleteSelected() {
const actions = []
for (const id of this.selectedTx) {
@ -536,22 +562,26 @@ export default {
},
moveToToday() {
return this.patchSelected([
{
op: 'replace',
path: '/time',
value: new Date(new Date().toISOString()
.split('T')[0]),
},
])
},
patchSelected(patchset = []) {
const actions = []
for (const id of this.selectedTx) {
actions.push(fetch(`/api/transactions/${id}`, {
body: JSON.stringify([
{
op: 'replace',
path: '/time',
value: new Date(new Date().toISOString()
.split('T')[0]),
},
]),
body: JSON.stringify(patchset),
method: 'PATCH',
}))
}
Promise.all(actions)
return Promise.all(actions)
.then(() => {
this.$emit('update-accounts')
this.fetchTransactions()