123 lines
2.6 KiB
Go
123 lines
2.6 KiB
Go
package frontend
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
var dashboard = template.Must(template.ParseFiles(
|
|
"frontend/htmx/contents/dash/base.html",
|
|
"frontend/htmx/contents/dash/dashboard.html"))
|
|
|
|
var inventory = template.Must(template.ParseFiles(
|
|
"frontend/htmx/contents/dash/base.html",
|
|
"frontend/htmx/contents/dash/inventory.html"))
|
|
|
|
var item = template.Must(template.ParseFiles(
|
|
"frontend/htmx/contents/dash/base.html",
|
|
"frontend/htmx/contents/dash/itemlist.html"))
|
|
|
|
var locations = template.Must(template.ParseFiles(
|
|
"frontend/htmx/contents/dash/base.html",
|
|
"frontend/htmx/contents/dash/locations.html"))
|
|
|
|
var projects = template.Must(template.ParseFiles(
|
|
"frontend/htmx/contents/dash/base.html",
|
|
"frontend/htmx/contents/dash/projects.html"))
|
|
|
|
var home = template.Must(template.ParseFiles("frontend/htmx/home.html"))
|
|
|
|
func Home(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.ServeFile(w, r, "frontend/htmx/404.html")
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "text/html")
|
|
err := home.Execute(w, struct {
|
|
Name string
|
|
}{
|
|
Name: "Home",
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
func Dashboard(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
err := dashboard.ExecuteTemplate(w, "base.html", struct {
|
|
Title string
|
|
Stats struct {
|
|
Items int
|
|
Projects int
|
|
Locations int
|
|
}
|
|
}{
|
|
Title: "Dashboard",
|
|
Stats: struct {
|
|
Items int
|
|
Projects int
|
|
Locations int
|
|
}{
|
|
Items: 1,
|
|
Projects: 1,
|
|
Locations: 3,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
func Inventory(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
err := inventory.ExecuteTemplate(w, "base.html", struct {
|
|
Title string
|
|
}{
|
|
Title: "Inventory",
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
func Items(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
err := item.ExecuteTemplate(w, "base.html", struct {
|
|
Title string
|
|
}{
|
|
Title: "Items",
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
func Locations(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
err := locations.ExecuteTemplate(w, "base.html", struct {
|
|
Title string
|
|
}{
|
|
Title: "Locations",
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
func Projects(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html")
|
|
err := projects.ExecuteTemplate(w, "base.html", struct {
|
|
Title string
|
|
}{
|
|
Title: "Projects",
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
func Assets(w http.ResponseWriter, r *http.Request) {
|
|
path := strings.TrimPrefix(r.URL.Path, "/assets/")
|
|
http.ServeFile(w, r, filepath.Join("frontend/assets", path))
|
|
}
|