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

View File

@ -4,6 +4,7 @@ import (
"embed" "embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/fs" "io/fs"
"net/http" "net/http"
"os" "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) { 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) { 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 { slices.SortFunc(result, func(a, b Transaction) int {
if a[0].Date == b[0].Date { 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) return strings.Compare(a[0].Date, b[0].Date)
}) })