add method to set default values for handler
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 11m53s
Gitea Actions Demo / build-and-test (push) Failing after 16m45s

This commit is contained in:
Thomas Peetz
2026-10-25 01:23:54 +02:00
parent 74cda6c72d
commit 05555a7750
5 changed files with 29 additions and 17 deletions
+15
View File
@@ -1,5 +1,9 @@
package globals
import (
"github.com/gin-gonic/gin"
)
var (
Secret = []byte("secret")
@@ -9,3 +13,14 @@ var (
)
const UserKey = "user"
func GetDefaultValues(user interface{}, message string) gin.H {
values := gin.H{
"title": "Kontor MediaFiles",
"version": Version,
"message": message,
"user": user,
}
return values
}
+5 -9
View File
@@ -117,15 +117,11 @@ func (handler *MediaLoFiHandler) ListPage(c *gin.Context) {
return
}
logger.Info("MediaLoFiHandler#ListPage", "lofis count", len(lofis))
c.HTML(http.StatusOK, "lofi", gin.H{
"title": "Kontor MediaFiles",
"version": "0.4.0",
"message": "MediaFiles...",
"lofis": lofis,
"user": user,
"isReview": review,
"isDownload": download,
})
data := globals.GetDefaultValues(user, "MediaFiles...")
data["lofis"] = lofis
data["isReview"] = review
data["isDownload"] = download
c.HTML(http.StatusOK, "lofi", data)
}
func (handler *MediaLoFiHandler) EditPage(c *gin.Context) {
+5 -7
View File
@@ -42,11 +42,9 @@ func (handler *MediaVideoHandler) ListPage(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.HTML(http.StatusOK, "mediavideos", gin.H{
"title": "Kontor MediaFiles",
"version": "0.4.0",
"message": "MediaFiles...",
"mediavideos": videos,
"user": user,
})
data := globals.GetDefaultValues(user, "MediaFiles...")
data["title"] = "Kontor MediaFiles"
data["mediavideos"] = videos
c.HTML(http.StatusOK, "mediavideos", data)
}
+2
View File
@@ -60,6 +60,8 @@ func New(admin *handlers.AdminHandler, bookshelf *handlers.BookshelfHandler, com
m.GET("/articles", media.MediaFileHandler.ListPage)
m.GET("/media-files", media.MediaFileHandler.ListPage)
m.GET("/files", media.MediaFileHandler.ListPage)
m.GET("/videos", media.MediaVideoHandler.ListPage)
m.GET("/media-videos", media.MediaVideoHandler.ListPage)
m.GET("/media-lofis", media.MediaLoFiHandler.ListPage)
m.GET("/media-lofis/:id/edit", media.MediaLoFiHandler.EditPage)
m.POST("/media-lofis/:id/edit", media.MediaLoFiHandler.UpdatePage)