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 Move to Today
</button> </button>
</li> </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> <li>
<button <button
v-shortkey="['del']" v-shortkey="['del']"
@ -484,6 +494,22 @@ export default {
methods: { methods: {
classFromNumber, 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() { deleteSelected() {
const actions = [] const actions = []
for (const id of this.selectedTx) { for (const id of this.selectedTx) {
@ -536,22 +562,26 @@ export default {
}, },
moveToToday() { moveToToday() {
const actions = [] return this.patchSelected([
for (const id of this.selectedTx) {
actions.push(fetch(`/api/transactions/${id}`, {
body: JSON.stringify([
{ {
op: 'replace', op: 'replace',
path: '/time', path: '/time',
value: new Date(new Date().toISOString() value: new Date(new Date().toISOString()
.split('T')[0]), .split('T')[0]),
}, },
]), ])
},
patchSelected(patchset = []) {
const actions = []
for (const id of this.selectedTx) {
actions.push(fetch(`/api/transactions/${id}`, {
body: JSON.stringify(patchset),
method: 'PATCH', method: 'PATCH',
})) }))
} }
Promise.all(actions) return Promise.all(actions)
.then(() => { .then(() => {
this.$emit('update-accounts') this.$emit('update-accounts')
this.fetchTransactions() this.fetchTransactions()