From 80508001c7a91560f4ee72698a3f95f9aff20cd2 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 14 Apr 2024 00:31:24 +0200 Subject: [PATCH] generate elem with go --- example/webui/elements.go | 27 ++++++++++----- example/webui/views/agents.html | 4 +-- example/webui/views/knowledgebase.html | 44 +----------------------- example/webui/views/partials/header.html | 37 ++++++++++++++++++++ example/webui/views/settings.html | 9 +++++ go.mod | 11 +++--- go.sum | 2 ++ 7 files changed, 75 insertions(+), 59 deletions(-) diff --git a/example/webui/elements.go b/example/webui/elements.go index 7bc363f..7d6bf23 100644 --- a/example/webui/elements.go +++ b/example/webui/elements.go @@ -3,24 +3,33 @@ package main import ( "fmt" "strings" + + elem "github.com/chasefleming/elem-go" + "github.com/chasefleming/elem-go/attrs" ) -// TODO: switch to https://github.com/chasefleming/elem-go - func chatDiv(content string, color string) string { - return fmt.Sprintf(`
%s
`, color, htmlIfy(content)) + div := elem.Div(attrs.Props{ + // attrs.ID: "container", + attrs.Class: fmt.Sprintf("p-2 my-2 rounded bg-%s-600", color), + }, + elem.Raw(htmlIfy(content)), + ) + return div.Render() } func loader() string { - return `
` + return elem.Div(attrs.Props{ + attrs.Class: "loader", + }).Render() } func disabledElement(id string, disabled bool) string { - if disabled { - return `` - } - - return `` + return elem.Script(nil, + elem.If(disabled, + elem.Raw(`document.getElementById('`+id+`').disabled = true`), + elem.Raw(`document.getElementById('`+id+`').disabled = false`), + )).Render() } func htmlIfy(s string) string { diff --git a/example/webui/views/agents.html b/example/webui/views/agents.html index 6ff957b..f0ba95b 100644 --- a/example/webui/views/agents.html +++ b/example/webui/views/agents.html @@ -69,12 +69,12 @@ - - diff --git a/example/webui/views/knowledgebase.html b/example/webui/views/knowledgebase.html index 1e896c5..7f68770 100644 --- a/example/webui/views/knowledgebase.html +++ b/example/webui/views/knowledgebase.html @@ -3,50 +3,8 @@ KnowledgeBase {{template "views/partials/header"}} - - - - - + {{template "views/partials/menu"}}

Knowledgebase (items: {{.KnowledgebaseItemsCount}})

diff --git a/example/webui/views/partials/header.html b/example/webui/views/partials/header.html index cbba1da..b957e80 100644 --- a/example/webui/views/partials/header.html +++ b/example/webui/views/partials/header.html @@ -10,4 +10,41 @@ body { font-family: 'Roboto', sans-serif; } + .section-box { + background-color: #2a2a2a; /* Darker background for the form */ + padding: 20px; + margin-bottom: 20px; + border-radius: 10px; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + } + + body { + background-color: #1a1a1a; /* Lighter overall background */ + color: #ffffff; + font-family: sans-serif; + padding: 20px; + } + + input, button { + width: 100%; + padding: 10px; + margin-top: 5px; + border-radius: 5px; + border: none; + } + + input[type="text"], input[type="file"] { + background-color: #333333; + color: white; + } + + button { + background-color: #4a76a8; /* Blue color for buttons */ + color: white; + cursor: pointer; + } + + button:hover { + background-color: #5a86b8; + } \ No newline at end of file diff --git a/example/webui/views/settings.html b/example/webui/views/settings.html index 4d70ffe..dea2e65 100644 --- a/example/webui/views/settings.html +++ b/example/webui/views/settings.html @@ -50,6 +50,15 @@
+
+ + +
+

Export

Export diff --git a/go.mod b/go.mod index 6aa1e11..426f325 100644 --- a/go.mod +++ b/go.mod @@ -6,27 +6,31 @@ toolchain go1.22.2 require ( github.com/bwmarrin/discordgo v0.28.1 + github.com/chasefleming/elem-go v0.25.0 github.com/donseba/go-htmx v1.8.0 + github.com/dslipak/pdf v0.0.2 github.com/go-telegram/bot v1.2.1 github.com/gofiber/fiber/v2 v2.52.4 + github.com/gofiber/template/html/v2 v2.1.1 github.com/google/go-github/v61 v61.0.0 github.com/onsi/ginkgo/v2 v2.15.0 github.com/onsi/gomega v1.31.1 + github.com/oxffaa/gopher-parse-sitemap v0.0.0-20191021113419-005d2eb1def4 + github.com/philippgille/chromem-go v0.5.0 github.com/sap-nocops/duckduckgogo v0.0.0-20201102135645-176990152850 github.com/sashabaranov/go-openai v1.18.3 github.com/slack-go/slack v0.12.5 github.com/valyala/fasthttp v1.52.0 + jaytaylor.com/html2text v0.0.0-20230321000545-74c2419ad056 ) require ( github.com/PuerkitoBio/goquery v1.6.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/andybalholm/cascadia v1.1.0 // indirect - github.com/dslipak/pdf v0.0.2 // indirect github.com/go-logr/logr v1.3.0 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gofiber/template v1.8.3 // indirect - github.com/gofiber/template/html/v2 v2.1.1 // indirect github.com/gofiber/utils v1.1.0 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-querystring v1.1.0 // indirect @@ -38,8 +42,6 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/oxffaa/gopher-parse-sitemap v0.0.0-20191021113419-005d2eb1def4 // indirect - github.com/philippgille/chromem-go v0.5.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/stretchr/testify v1.9.0 // indirect @@ -51,5 +53,4 @@ require ( golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.16.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - jaytaylor.com/html2text v0.0.0-20230321000545-74c2419ad056 // indirect ) diff --git a/go.sum b/go.sum index ccd2ce3..2442764 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5z github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4= github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= +github.com/chasefleming/elem-go v0.25.0 h1:LYzr1auk39Bh3bdKloArOFV7sOBnOfSOKxsg58eWL0Q= +github.com/chasefleming/elem-go v0.25.0/go.mod h1:hz73qILBIKnTgOujnSMtEj20/epI+f6vg71RUilJAA4= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=