package views
import (
"fmt"
"git.32bit.cafe/32bitcafe/guestbook/internal/forms"
"git.32bit.cafe/32bitcafe/guestbook/internal/models"
"slices"
"strings"
"time"
)
type AdminStat struct {
WebsiteCount int64
UserCount int64
CommentCount int64
}
templ adminBase(title string, data CommonData) {
{ title } - webweav.ing
{ children... }
@commonFooter()
}
templ adminSidebar() {
}
templ AdminPanelLandingView(title string, data CommonData, stats AdminStat) {
@adminBase(title, data) {
@adminSidebar()
{ title }
Welcome to the admin panel
Users
{ fmt.Sprintf("%d", stats.UserCount) }
Websites
{ fmt.Sprintf("%d", stats.WebsiteCount) }
Comments
{ fmt.Sprintf("%d", stats.CommentCount) }
}
}
templ AdminPanelUsersView(title string, data CommonData, users []models.User, pageNum, pageSize, total int64) {
@adminBase(title, data) {
@adminSidebar()
| Username |
Joined |
Email |
for _, u := range users {
{{ url := fmt.Sprintf("/admin/users/%s", shortIdToSlug(u.ShortId)) }}
| { u.Username } |
{ u.Created.Format(time.RFC3339) } |
{ u.Email } |
}
@pagination("/admin/users", pageNum, total, pageSize)
}
}
templ AdminPanelUserMgmtDetail(csrfToken string, user models.User) {
}
templ AdminPanelUserMgmtView(title string, data CommonData, user models.User) {
@adminBase(title, data) {
@adminSidebar()
@AdminPanelUserMgmtDetail(data.CSRFToken, user)
}
}
templ AdminPanelUserMgmtEditForm(csrfToken string, form forms.AdminUserMgmtForm, user models.User, groups []models.UserGroupId) {
}
templ AdminPanelAllWebsitesView(title string, data CommonData, websites []models.Website, pageNum, pageCount, total int64) {
@adminBase(title, data) {
@adminSidebar()
| Site Name |
Owner |
URL |
Created |
Guestbook |
for _, w := range websites {
{{ detailUrl := fmt.Sprintf("/admin/websites/%s", shortIdToSlug(w.ShortId)) }}
| { w.Name } |
{ w.AuthorName } |
{ w.Url.String() } |
{ w.Created.Format(time.RFC1123) } |
{{ gbUrl := fmt.Sprintf("/websites/%s/guestbook", shortIdToSlug(w.ShortId)) }}
View |
}
@pagination("/admin/websites", pageNum, total, pageCount)
}
}
func truncateComment(s string, n int) string {
words := strings.Fields(s)
if len(words) < n {
return s
}
truncated := words[:n]
truncated = append(truncated, "...")
return strings.Join(truncated, " ")
}
templ AdminPanelWebsiteDetailView(title string, data CommonData, website models.Website, comments []models.GuestbookComment, pageNum, pageAmount, total int64) {
@adminBase(title, data) {
@adminSidebar()
| Author |
Created |
Email |
Homepage |
Comment |
for _, c := range comments {
| { c.AuthorName } |
{ c.Created.Format(time.RFC1123) } |
{ c.AuthorEmail } |
{ c.AuthorSite } |
{ truncateComment(c.CommentText, 15) } |
}
{{ url := fmt.Sprintf("/admin/websites/%s", shortIdToSlug(website.ShortId)) }}
@pagination(url, pageNum, total, pageAmount)
}
}