Compare commits

...

2 Commits

Author SHA1 Message Date
bel
8fd1a4fedb add helper buttons to Stage Zach/Bel Charge/Payment
All checks were successful
cicd / ci (push) Successful in 46s
2023-10-29 10:37:03 -06:00
bel
566b3ad571 ledger.Files.?etLastNLines trims empty lines 2023-10-29 10:36:45 -06:00
2 changed files with 32 additions and 2 deletions

View File

@@ -80,7 +80,7 @@
function loadLastNLines(lastNLines) {
var result = `<form onsubmit="setLastNLines(this); return false;" action="#">`
result += ` <div>${f}</div>`
result += ` <textarea name="lastNLines" style="height: 30em;">`
result += ` <textarea id="lastNLinesTextarea" name="lastNLines" style="height: 30em;">`
for (var k in lastNLines) {
result += lastNLines[k] + "\n"
}
@@ -89,6 +89,22 @@
result += `</form>`
document.getElementById("lastNLines").innerHTML = result
}
function stage(who, contributesToHouse) {
var benefactor = who
var beneficiary = "AssetAccount:Chase:5876"
if (!contributesToHouse) {
var tmp = beneficiary
beneficiary = benefactor
benefactor = tmp
}
const zeroPad = (num, places) => String(num).padStart(places, '0')
var d = new Date()
const today = `${d.getFullYear()}-${zeroPad(1+d.getMonth(), 2)}-${zeroPad(d.getDate(), 2)}`
console.log(`@${today} ${benefactor} gave to ${beneficiary}`)
document.getElementById("lastNLinesTextarea").value += `\n${today} TODO moolah2`
document.getElementById("lastNLinesTextarea").value += `\n ${beneficiary} $0.00`
document.getElementById("lastNLinesTextarea").value += `\n ${benefactor}`
}
</script>
</header>
<body onload="init();" style="min-width: 1024px;">
@@ -104,6 +120,16 @@
</details>
<details open>
<summary>Edit</summary>
<div style="display:flex; flex-direction:row; width:100%; justify-content:space-between;">
<div>
<input type="button" onclick="stage('AssetAccount:Zach', true)" value="Stage Zach's Payment"/>
<input type="button" onclick="stage('AssetAccount:Zach', false)" value="Stage Zach's Charge"/>
</div>
<div>
<input type="button" onclick="stage('AssetAccount:Bel', true)" value="Stage Bel's Payment"/>
<input type="button" onclick="stage('AssetAccount:Bel', false)" value="Stage Bel's Charge"/>
</div>
</div>
<div id="lastNLinesStatus">
</div>
<div id="lastNLines">

View File

@@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"sort"
"strings"
"unicode"
)
@@ -54,6 +55,9 @@ func (files Files) TempSetLastNLines(n int, lines []string) error {
return "", err
}
for i := range lines {
if len(strings.TrimSpace(lines[i])) == 0 {
continue
}
if _, err := fmt.Fprintln(w, lines[i]); err != nil {
return "", err
}
@@ -87,7 +91,7 @@ func peekLastNLines(w io.Writer, r *bufio.Reader, n int) ([]string, error) {
lastNLines := make([]string, 0, n)
for {
line, err := r.ReadBytes('\n')
if len(line) > 0 {
if len(bytes.TrimSpace(line)) > 0 {
lastNLines = append(lastNLines, string(bytes.TrimRight(line, "\n")))
for i := 0; i < len(lastNLines)-n; i++ {
fmt.Fprintln(w, lastNLines[i])