transactions.html can edit though needs some kinda user feedback of the changed row or something...
cicd / ci (push) Successful in 1m28s Details

main
bel 2024-07-21 08:31:37 -06:00
parent d69de4da11
commit 518909b7f7
3 changed files with 32 additions and 10 deletions

View File

@ -8,17 +8,17 @@
</style>
<script>
function http(method, remote, callback, body) {
var xmlhttp = new XMLHttpRequest();
var xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
callback(xmlhttp.responseText, xmlhttp.status)
}
};
xmlhttp.open(method, remote, true);
}
xmlhttp.open(method, remote, true)
if (typeof body == "undefined") {
body = null
}
xmlhttp.send(body);
xmlhttp.send(body)
}
function callback(responseBody, responseStatus) {
@ -134,12 +134,16 @@
const idx = btn.name.split("submit")[1]
const form = btn.parentElement.parentElement
now.Value = form[`value${idx}`].value
now.Value = parseFloat(form[`value${idx}`].value)
now.Name = form[`name${idx}`].value
now.Description = form[`description`].value
now.Date = form[`date`].value
if (JSON.stringify(old) === JSON.stringify(now)) {
var different = false
for(var k in old) {
different = different || old[k] != now[k]
}
if (!different) {
return
}
@ -147,10 +151,10 @@
if (status != 200)
throw(`Unexpected status ${status}: ${body}`)
load()
}, {
}, JSON.stringify({
old: old,
now: now,
})
}))
}
function stage(who, contributesToHouse) {

View File

@ -4,6 +4,7 @@ import (
"embed"
"encoding/json"
"fmt"
"io"
"io/fs"
"net/http"
"os"
@ -110,7 +111,21 @@ func (router Router) APITransactions(w http.ResponseWriter, r *http.Request) {
}
func (router Router) APIAmend(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusNotImplemented), http.StatusNotImplemented)
b, _ := io.ReadAll(r.Body)
var req struct {
Old ledger.Delta
Now ledger.Delta
}
if err := json.Unmarshal(b, &req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := router.files.Amend(req.Old, req.Now); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
func (router Router) APIReg(w http.ResponseWriter, r *http.Request) {

View File

@ -31,7 +31,10 @@ func (deltas Deltas) Transactions() Transactions {
slices.SortFunc(result, func(a, b Transaction) int {
if a[0].Date == b[0].Date {
return strings.Compare(a[0].Transaction, b[0].Transaction)
if a[0].Description == b[0].Description {
return strings.Compare(a[0].Transaction, b[0].Transaction)
}
return strings.Compare(a[0].Description, b[0].Description)
}
return strings.Compare(a[0].Date, b[0].Date)
})