Compare commits
2 Commits
b8323f731f
...
518909b7f7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
518909b7f7 | ||
|
|
d69de4da11 |
@@ -1,19 +1,24 @@
|
|||||||
<html>
|
<html>
|
||||||
<header>
|
<header>
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
|
||||||
|
<style>
|
||||||
|
input[type="text"] {
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
</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) {
|
||||||
@@ -83,8 +88,73 @@
|
|||||||
const xactionJSON = atob(row.attributes.transaction.value)
|
const xactionJSON = atob(row.attributes.transaction.value)
|
||||||
const xaction = JSON.parse(xactionJSON)
|
const xaction = JSON.parse(xactionJSON)
|
||||||
console.log(xaction)
|
console.log(xaction)
|
||||||
row.innerHTML = `<td colspan="3"></td>`
|
|
||||||
TODO
|
row.attributes.onclick = ""
|
||||||
|
row.onclick = ""
|
||||||
|
row.style = ""
|
||||||
|
console.log(row)
|
||||||
|
|
||||||
|
var result = `<td colspan="3">`
|
||||||
|
result += `<form method="modal">`
|
||||||
|
result += ` <div>`
|
||||||
|
result += ` <label for="date">Date</label>`
|
||||||
|
result += ` <input type="text" name="date" value='${xaction[0].Date}' style="width: 100%;"/>`
|
||||||
|
result += ` </div>`
|
||||||
|
result += ` <div>`
|
||||||
|
result += ` <label for="description">Description</label>`
|
||||||
|
result += ` <input type="text" name="description" value='${xaction[0].Description}' style="width: 100%;"/>`
|
||||||
|
result += ` </div>`
|
||||||
|
|
||||||
|
for (var i in xaction) {
|
||||||
|
var delta = xaction[i]
|
||||||
|
result += `<hr>`
|
||||||
|
result += `<div style="display: flex; flex-direction: row; width: 100%; margin-top: 1em;">`
|
||||||
|
result += ` <div style="flex-grow: 1; margin-left: 1em; margin-right: 1em;">`
|
||||||
|
result += ` <label for="name${i}">Name${i}</label>`
|
||||||
|
result += ` <input type="text" name="name${i}" value='${delta.Name}' style="width: 100%;"/>`
|
||||||
|
result += ` </div>`
|
||||||
|
result += ` <div style="margin-left: 1em; margin-right: 1em;">`
|
||||||
|
result += ` <label for="value${i}">Value${i}</label>`
|
||||||
|
result += ` <input type="text" name="value${i}" value='${delta.Value}' style="width: 100%;"/>`
|
||||||
|
result += ` </div>`
|
||||||
|
result += ` <input type="button" name="submit${i}" value="Submit${i}" onclick="submitEdit(this); return false;" delta="${btoa(JSON.stringify(delta))}"/>`
|
||||||
|
result += `</div>`
|
||||||
|
}
|
||||||
|
|
||||||
|
result += `</form`
|
||||||
|
result += `</td>`
|
||||||
|
|
||||||
|
row.innerHTML = result
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitEdit(btn) {
|
||||||
|
const old = JSON.parse(atob(btn.attributes.delta.value))
|
||||||
|
const now = JSON.parse(atob(btn.attributes.delta.value))
|
||||||
|
|
||||||
|
const idx = btn.name.split("submit")[1]
|
||||||
|
const form = btn.parentElement.parentElement
|
||||||
|
|
||||||
|
now.Value = parseFloat(form[`value${idx}`].value)
|
||||||
|
now.Name = form[`name${idx}`].value
|
||||||
|
now.Description = form[`description`].value
|
||||||
|
now.Date = form[`date`].value
|
||||||
|
|
||||||
|
var different = false
|
||||||
|
for(var k in old) {
|
||||||
|
different = different || old[k] != now[k]
|
||||||
|
}
|
||||||
|
if (!different) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http("PUT", "/api/amend", (body, status) => {
|
||||||
|
if (status != 200)
|
||||||
|
throw(`Unexpected status ${status}: ${body}`)
|
||||||
|
load()
|
||||||
|
}, JSON.stringify({
|
||||||
|
old: old,
|
||||||
|
now: now,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function stage(who, contributesToHouse) {
|
function stage(who, contributesToHouse) {
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user