Compare commits
2 commits
05be8548fe
...
b36ca0d635
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b36ca0d635 | ||
|
|
8d6ec8b4ff |
9 changed files with 154 additions and 1 deletions
3
go.mod
3
go.mod
|
|
@ -5,8 +5,11 @@ go 1.23.0
|
|||
require (
|
||||
git.gibonuddevalla.se/go/dbschema v1.3.1
|
||||
git.gibonuddevalla.se/go/wrappederror v0.3.5
|
||||
github.com/derektata/lorem v0.0.2
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jmoiron/sqlx v1.4.0
|
||||
github.com/lib/pq v1.10.9
|
||||
)
|
||||
|
||||
require golang.org/x/text v0.11.0 // indirect
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -4,6 +4,8 @@ git.gibonuddevalla.se/go/dbschema v1.3.1 h1:TGPvbNO/u7IK5TU0HT92mVzqdF179lLCfdTx
|
|||
git.gibonuddevalla.se/go/dbschema v1.3.1/go.mod h1:BNw3q/574nXbGoeWyK+tLhRfggVkw2j2aXZzrBKC3ig=
|
||||
git.gibonuddevalla.se/go/wrappederror v0.3.5 h1:/EzrdXETlZfNpS6TcK1Ix6BaV+Fl7qcGoxUM0GkrIN8=
|
||||
git.gibonuddevalla.se/go/wrappederror v0.3.5/go.mod h1:j4w320Hk1wvhOPjUaK4GgLvmtnjUUM5yVu6JFO1OCSc=
|
||||
github.com/derektata/lorem v0.0.2 h1:6esAdZDRz+hHiGO8AWxvDf2CwEb1wV7oi6pRWikG+Os=
|
||||
github.com/derektata/lorem v0.0.2/go.mod h1:4elDc+N81tciTDNFVCO3TxJKM+HRVJLszBcG00iREcA=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||
|
|
@ -16,3 +18,5 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
|||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
|
|
|
|||
13
main.go
13
main.go
|
|
@ -25,10 +25,11 @@ import (
|
|||
|
||||
const VERSION = "v1"
|
||||
const CONTEXT_USER = 1
|
||||
const SYNC_PAGINATION = 250
|
||||
const SYNC_PAGINATION = 100
|
||||
|
||||
var (
|
||||
FlagGenerate bool
|
||||
FlagLoremIpsum bool
|
||||
FlagDev bool
|
||||
FlagConfig string
|
||||
FlagCreateUser string
|
||||
|
|
@ -60,6 +61,7 @@ func init() { // {{{
|
|||
flag.StringVar(&FlagConfig, "config", cfgFilename, "Configuration file")
|
||||
flag.BoolVar(&FlagDev, "dev", false, "Use local files instead of embedded files")
|
||||
flag.BoolVar(&FlagGenerate, "generate", false, "Generate test data")
|
||||
flag.BoolVar(&FlagLoremIpsum, "lorem-ipsum", false, "Replace all G- nodes with lorem ipsum paragraphs")
|
||||
flag.StringVar(&FlagCreateUser, "create-user", "", "Username for creating a new user")
|
||||
flag.StringVar(&FlagChangePassword, "change-password", "", "Change the password for the given username")
|
||||
flag.Parse()
|
||||
|
|
@ -99,6 +101,15 @@ func main() { // {{{
|
|||
return
|
||||
}
|
||||
|
||||
if FlagLoremIpsum {
|
||||
err := LoremIpsum()
|
||||
if err != nil {
|
||||
fmt.Printf("%s\n", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// A new user?
|
||||
if FlagCreateUser != "" {
|
||||
createNewUser(FlagCreateUser)
|
||||
|
|
|
|||
36
node.go
36
node.go
|
|
@ -4,9 +4,11 @@ import (
|
|||
// External
|
||||
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/derektata/lorem/ipsum"
|
||||
|
||||
// Standard
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -285,6 +287,40 @@ func NodeCrumbs(nodeUUID string) (nodes []Node, err error) { // {{{
|
|||
return
|
||||
} // }}}
|
||||
|
||||
func LoremIpsum() (err error) {
|
||||
var numNodesRow *sql.Row
|
||||
var numNodes int
|
||||
numNodesRow = db.QueryRow(`SELECT COUNT(id) FROM node WHERE name LIKE 'G-%'`)
|
||||
err = numNodesRow.Scan(&numNodes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var rows *sql.Rows
|
||||
rows, err = db.Query(`SELECT id FROM node WHERE name LIKE 'G-%'`)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
lipsum := lorem.NewGenerator()
|
||||
var id, counter int
|
||||
for rows.Next() {
|
||||
counter++
|
||||
if counter&100 == 0 {
|
||||
fmt.Printf("%04d\n", counter)
|
||||
}
|
||||
err = rows.Scan(&id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
db.Exec(`UPDATE node SET content=$2 WHERE id=$1`, id, lipsum.GenerateParagraphs(2))
|
||||
}
|
||||
fmt.Printf("%04d\n", counter)
|
||||
return
|
||||
}
|
||||
|
||||
func TestData() (err error) {
|
||||
for range 8 {
|
||||
hash1, name1, _ := generateOneTestNode("", "G")
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ html {
|
|||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 32px;
|
||||
gap: 8px;
|
||||
}
|
||||
#tree .node {
|
||||
display: grid;
|
||||
|
|
|
|||
67
static/images/icon_search.svg
Normal file
67
static/images/icon_search.svg
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="413.48245"
|
||||
height="413.47971"
|
||||
viewBox="0 0 109.40056 109.39984"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="1.4 (e7c3feb, 2024-10-09)"
|
||||
sodipodi:docname="icon_search.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#8b8b8b"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.70710678"
|
||||
inkscape:cx="206.47518"
|
||||
inkscape:cy="207.18229"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:window-width="2190"
|
||||
inkscape:window-height="1404"
|
||||
inkscape:window-x="1463"
|
||||
inkscape:window-y="16"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:showpageshadow="true"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d6d6d6"
|
||||
showborder="true" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-38.102322,-96.575592)">
|
||||
<title
|
||||
id="title1">magnify</title>
|
||||
<path
|
||||
d="m 78.736803,96.575592 a 40.634474,40.634474 0 0 1 40.634477,40.634438 c 0,10.06486 -3.68838,19.31694 -9.75227,26.44372 l 1.68795,1.68701 h 4.93863 l 31.2573,31.25736 -9.37719,9.37731 -31.25729,-31.25737 v -4.93863 l -1.68795,-1.68701 c -7.126666,6.06378 -16.378815,9.75204 -26.443681,9.75204 A 40.634474,40.634474 0 0 1 38.102322,137.21003 40.634474,40.634474 0 0 1 78.736803,96.575592 m 0,12.502758 c -15.628636,0 -28.131559,12.50299 -28.131559,28.13168 0,15.62868 12.502923,28.13144 28.131559,28.13144 15.628635,0 28.131557,-12.50276 28.131557,-28.13144 0,-15.62869 -12.502922,-28.13168 -28.131557,-28.13168 z"
|
||||
id="path1"
|
||||
style="stroke-width:6.25145;fill:#ffffff" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
|
|
@ -242,6 +242,35 @@ export class NodeStore {
|
|||
req.onerror = (event) => reject(event.target.error)
|
||||
})
|
||||
}//}}}
|
||||
async search(searchfor, parent) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const trx = this.db.transaction('nodes', 'readonly')
|
||||
const nodeStore = trx.objectStore('nodes')
|
||||
const index = nodeStore.index('byParent')
|
||||
const req = index.getAll(parent)
|
||||
req.onsuccess = async (event) => {
|
||||
let nodes = []
|
||||
for (const i in event.target.result) {
|
||||
const nodeData = event.target.result[i]
|
||||
const children = await this.search(searchfor, nodeData.UUID)
|
||||
|
||||
// Data is searched for the provided text.
|
||||
// TODO: implement an array of words to search?
|
||||
if (nodeData.Content.toLowerCase().includes(searchfor))
|
||||
nodes.push({
|
||||
uuid: nodeData.UUID,
|
||||
name: nodeData.Name,
|
||||
ancestry: await this.getNodeAncestry(nodeData, []),
|
||||
})
|
||||
|
||||
nodes = nodes.concat(children)
|
||||
}
|
||||
resolve(nodes)
|
||||
return
|
||||
}
|
||||
req.onerror = (event) => reject(event.target.error)
|
||||
})
|
||||
}//}}}
|
||||
|
||||
async add(records) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ class Tree extends Component {
|
|||
<div id="tree" ref=${this.treeDiv} tabindex="0">
|
||||
<div id="logo" onclick=${() => _notes2.current.goToNode(ROOT_NODE)}><img src="/images/${_VERSION}/logo.svg" /></div>
|
||||
<div class="icons">
|
||||
<img src="/images/${_VERSION}/icon_search.svg" style="height: 22px" onclick=${()=>_sync.run()} />
|
||||
<img src="/images/${_VERSION}/icon_refresh.svg" onclick=${()=>_sync.run()} />
|
||||
</div>
|
||||
${renderedTreeTrunk}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ html {
|
|||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 32px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.node {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue