[Project base]

This commit is contained in:
xoy 2025-02-18 19:45:28 +01:00
parent 6a5ee11de1
commit 0ae6f5c00a
11 changed files with 217 additions and 12 deletions

20
main.go
View file

@ -18,6 +18,7 @@ func main() {
navItems := []NavItem{ navItems := []NavItem{
NewNavItem("Suche", "/search"), NewNavItem("Suche", "/search"),
NewNavItem("Verwaltung", "/admin"),
} }
app.Get("/", func(c *fiber.Ctx) error { app.Get("/", func(c *fiber.Ctx) error {
@ -25,6 +26,8 @@ func main() {
"Title": "Suche", "Title": "Suche",
"Stylenames": NewStyleItemList("colors", "main", "search"), "Stylenames": NewStyleItemList("colors", "main", "search"),
"NavItems": navItems, "NavItems": navItems,
"ActivePage": "/search",
"SearchResultCount": -1,
}) })
}) })
@ -33,6 +36,8 @@ func main() {
"Title": "Suche", "Title": "Suche",
"Stylenames": NewStyleItemList("colors", "main", "search"), "Stylenames": NewStyleItemList("colors", "main", "search"),
"NavItems": navItems, "NavItems": navItems,
"ActivePage": "/search",
"SearchResultCount": -1,
}) })
}) })
@ -41,8 +46,23 @@ func main() {
"Title": "Suche", "Title": "Suche",
"Stylenames": NewStyleItemList("colors", "main", "search"), "Stylenames": NewStyleItemList("colors", "main", "search"),
"NavItems": navItems, "NavItems": navItems,
"ActivePage": "/search",
"SearchResultCount": 0,
}) })
}) })
app.Get("/admin", func(c *fiber.Ctx) error {
return c.Render("admin/tables", fiber.Map{
"Title": "Verwaltung",
"Stylenames": NewStyleItemList("colors", "main", "admin"),
"NavItems": navItems,
"ActivePage": "/admin",
})
})
app.Get("/admin/locations/overview", func(c *fiber.Ctx) error {
return c.Render("admin/overview")
})
log.Fatal(app.Listen(":3000")) log.Fatal(app.Listen(":3000"))
} }

0
static/css/admin.css Normal file
View file

View file

@ -25,7 +25,11 @@ a:visited {
header, footer { header, footer {
background-color: var(--bg-light); background-color: var(--bg-light);
height: 100px; height: 150px;
}
footer {
height: 50px;
} }
header { header {
@ -38,11 +42,14 @@ header > h1 {
padding: 0; padding: 0;
margin: 0; margin: 0;
text-align: center; text-align: center;
font-size: 4.5em;
} }
header > nav, footer > nav { :is(header, footer) > nav {
display: flex; display: flex;
justify-content: center; justify-content: center;
gap: 20px;
font-size: 1.5em;
} }
footer > nav { footer > nav {
@ -54,6 +61,26 @@ footer > nav > a {
margin: auto; margin: auto;
} }
:is(header, footer) > nav > a::before {
content: '< ';
}
:is(header, footer) > nav > a::after {
content: ' >';
}
:is(header, footer) > nav > a:is(:hover, .active)::before {
content: '\00a0>';
}
:is(header, footer) > nav > a:is(:hover, .active)::after {
content: '<\00a0';
}
:is(header, footer) > nav > a:visited {
color: var(--link);
}
main { main {
min-height: calc(100vh - 200px); min-height: calc(100vh - 200px);
} }

View file

@ -0,0 +1,54 @@
main {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 50px;
}
main > form {
display: flex;
margin-bottom: 50px;
}
main > form > input {
width: 420px;
height: 50px;
border-radius: 0px;
border-bottom-left-radius: 25px;
border-top-left-radius: 25px;
border: none;
font-size: 24px;
padding: 0 10px 0 10px;
background-color: var(--bg-light);
color: var(--fg);
border-right: 2px solid var(--bg-border);
}
main > form > input:focus {
outline: none;
}
main > form > button {
width: 50px;
height: 50px;
border: none;
border-radius: 0px;
border-bottom-right-radius: 25px;
border-top-right-radius: 25px;
cursor: pointer;
background-color: var(--bg-light);
font-size: 24px;
}
main > table {
width: 800px;
border-collapse: collapse;
background-color: var(--bg-light);
}
main > table tr :is(td, th) {
border: 2px solid var(--bg-border);
padding: 5px;
text-align: center;
}

View file

@ -1,5 +1,7 @@
package main package main
// Web
type NavItem struct { type NavItem struct {
Caption string Caption string
Destination string Destination string
@ -14,3 +16,16 @@ type Stylename string
func NewStyleItemList(stylenames ...Stylename) []Stylename { func NewStyleItemList(stylenames ...Stylename) []Stylename {
return stylenames return stylenames
} }
// Database
type Location struct {
id int
parent int
Name string
Description string
}
func (l *Location) GetParent() *Location {
return nil
}

16
views/admin/edit.html Normal file
View file

@ -0,0 +1,16 @@
{{template "partials/base-top" .}}
<form action="/admin/{{ .Table }}/edit" method="post">
{{ range .InputFields }}
<label for="{{ .Id }}">{{ .Label }}</label>
<input type="{{ .Type }}" name="{{ .Name }}" id="{{ .Id }}">
{{ end }}
<input type="hidden" name="doEdit">
<input type="hidden" name="id" value="{{ .RowId }}">
<div class="form-footer">
<button type="submit">💾</button>
<a href="/admin/{{ .Table }}/overview"></a>
</div>
</form>
{{template "partials/base-bottom" .}}

28
views/admin/overview.html Normal file
View file

@ -0,0 +1,28 @@
{{template "partials/base-top" .}}
<table>
<tr>
{{ range .Columns }}
<th>{{ . }}</th>
{{ end }}
</tr>
{{ range .Rows }}
<tr>
{{ range .Columns }}
<td>{{ . }}</td>
{{ end }}
<td>
<form action="/admin/{{ .Table }}/edit">
<input type="hidden" name="id" value="{{ .Id }}">
<button type="submit"></button>
</form>
<form action="/admin/{{ .Table }}/delete">
<input type="hidden" name="id" value="{{ .Id }}">
<button type="submit"></button>
</form>
</td>
</tr>
{{ end }}
</table>
{{template "partials/base-bottom" .}}

7
views/admin/tables.html Normal file
View file

@ -0,0 +1,7 @@
{{template "partials/base-top" .}}
{{ range .Tables }}
<a href="/admin/{{ .Table }}/overview">{{ .Caption }}</a>
{{ end }}
{{template "partials/base-bottom" .}}

9
views/alert.html Normal file
View file

@ -0,0 +1,9 @@
{{template "partials/base-top" .}}
<div class="message-box">
<h2 class="title">{{ .Title }}</h2>
<p class="message">{{ .Message }}</p>
<a href="/admin/{{ .Table }}/overview">🆗</a>
</div>
{{template "partials/base-bottom" .}}

View file

@ -13,7 +13,7 @@
<h1>fisch</h1> <h1>fisch</h1>
<nav> <nav>
{{ range .NavItems }} {{ range .NavItems }}
<a href="{{ .Destination }}">{{ .Caption }}</a> <a href="{{ .Destination }}" {{ if eq .Destination $.ActivePage }} class="active" {{ end }}>{{ .Caption }}</a>
{{ end }} {{ end }}
</nav> </nav>
</header> </header>

View file

@ -5,4 +5,33 @@
<button type="submit">🔍</button> <button type="submit">🔍</button>
</form> </form>
{{ if eq .SearchResultCount -1 }}
{{ else }}
{{ if gt .SearchResultCount 0 }}
<table>
<tr>
<th>Ort</th>
<th>Kistenbezeichnung</th>
<th>Möglicher Inhalt</th>
</tr>
<tr>
<td>A</td>
<td>A</td>
<td>A</td>
</tr>
</table>
{{ else }}
<p>Keine Ergebnisse gefunden.</p>
{{ end }}
{{ end }}
{{template "partials/base-bottom" .}} {{template "partials/base-bottom" .}}