new sw show template

This commit is contained in:
2026-01-28 18:53:14 +01:00
parent b6466061bd
commit 123af105f4
10 changed files with 125 additions and 64 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ func NewRootController() *RootController {
return &RootController{}
}
func (c *RootController) index(w http.ResponseWriter, r *http.Request) {
func (c *RootController) Index(w http.ResponseWriter, r *http.Request) {
tmpl, err := template_utils.GetTemplate("root_index", "http/views/shared/layout.html", "http/views/root/index.html")
if err != nil {
+5 -26
View File
@@ -17,7 +17,7 @@ func NewSoftwareController(software_service domain.SoftwareServiceInterface) *So
return &SoftwareController{softwareService: software_service}
}
func (c *SoftwareController) index(w http.ResponseWriter, r *http.Request) {
func (c *SoftwareController) Index(w http.ResponseWriter, r *http.Request) {
softwares, err := c.softwareService.List()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -33,41 +33,20 @@ func (c *SoftwareController) index(w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w, softwares)
}
type SoftwareShowData struct {
Software *domain.Software
LatestRelease *domain.Release
}
func (c *SoftwareController) show(w http.ResponseWriter, r *http.Request) {
func (c *SoftwareController) Show(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
software, err := c.softwareService.GetByName(name)
data, err := c.softwareService.GetForShowByName(name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if software == nil {
http.NotFound(w, r)
return
}
latest_release, err := c.softwareService.GetLatestRelease(software.Name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if latest_release == nil {
http.NotFound(w, r)
return
}
tmpl, err := template_utils.GetTemplate("software_show", "http/views/shared/layout.html", "http/views/software/show.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl.Execute(w, SoftwareShowData{
Software: software,
LatestRelease: latest_release,
})
tmpl.Execute(w, data)
}
+1 -1
View File
@@ -15,7 +15,7 @@ func NewSoftwareUpdaterController(service domain.SoftwareUpdaterServiceInterface
return &SoftwareUpdaterController{service: service}
}
func (c *SoftwareUpdaterController) update(w http.ResponseWriter, r *http.Request) {
func (c *SoftwareUpdaterController) Update(w http.ResponseWriter, r *http.Request) {
secret := r.URL.Query().Get("secret")
if secret != os.Getenv("UPDATE_SECRET") {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
+4 -4
View File
@@ -33,11 +33,11 @@ func NewRouter(
func (r *Router) Init() *chi.Mux {
router := chi.NewRouter()
router.Get("/", r.rootController.index)
router.Get("/software", r.softwareController.index)
router.Get("/software/{name}", r.softwareController.show)
router.Get("/", r.rootController.Index)
router.Get("/software", r.softwareController.Index)
router.Get("/software/{name}", r.softwareController.Show)
router.Get("/update", r.softwareUpdaterController.update)
router.Get("/update", r.softwareUpdaterController.Update)
router.Get("/download/{name}/source", r.downloadController.GetLatestSource)
router.Get("/download/{name}/cartridge", r.downloadController.GetLatestCartridge)
router.Get("/download/{name}/{version}/source", r.downloadController.GetSource)
+8 -21
View File
@@ -2,27 +2,14 @@
<h1 class="my-4">Softwares</h1>
<div class="row">
{{range .}}
<div class="col-12 mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">{{.Title}}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{.Author}}</h6>
<p class="card-text">{{.Desc}}</p>
<p class="card-text"><strong>Version:</strong> {{.LatestRelease.Version}}</p>
<p class="card-text"><strong>License:</strong> {{.License}}</p>
<p class="card-text"><a href="{{.Site}}" target="_blank">Website</a></p>
</div>
<div class="card-footer">
<div class="btn-group d-flex justify-content-end" role="group" aria-label="Operations">
<a href="/download/{{.Name}}/source" class="btn btn-primary btn-sm">Source</a>
<a href="/download/{{.Name}}/cartridge" class="btn btn-primary btn-sm">Cartridge</a>
<a href="/software/{{.Name}}" class="btn btn-primary btn-sm">Releases</a>
<a href="/play/{{.Name}}/{{.LatestRelease.Version}}" class="btn btn-primary btn-sm">Play</a>
</div>
</div>
</div>
<ul>
{{range .}}
<li>
<a href="/software/{{.Name}}">{{.Title}}</a>
</li>
{{end}}
</ul>
</div>
{{end}}
</div>
{{end}}
{{end}}
+40 -7
View File
@@ -1,8 +1,39 @@
{{define "content"}}
<h1 class="my-4">Releases for {{.Software.Title}}</h1>
<div class="row">
{{range .Software.Releases}}
<div class="col-12 mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">{{.Software.Title}}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{.Software.Author}}</h6>
<p class="card-text">{{.Software.Desc}}</p>
<p class="card-text"><strong>Version:</strong> {{.LatestRelease.Version}}</p>
<p class="card-text"><strong>License:</strong> {{.Software.License}}</p>
<p class="card-text"><a href="{{.Software.Site}}" target="_blank">Website</a></p>
</div>
<div class="card-footer">
<div class="btn-group d-flex justify-content-end" role="group" aria-label="Operations">
<a href="/download/{{.Software.Name}}/source" class="btn btn-primary btn-sm">Source</a>
<a href="/download/{{.Software.Name}}/cartridge" class="btn btn-primary btn-sm">Cartridge</a>
<a href="/software/{{.Software.Name}}" class="btn btn-primary btn-sm">Releases</a>
<a href="/play/{{.Software.Name}}/{{.LatestRelease.Version}}" class="btn btn-primary btn-sm">Play</a>
</div>
</div>
</div>
</div>
</div>
EEEE
{{if .WebPlayableRelease}}
<h3>Play</h3>
<div class="mb-4">
<div class="ratio ratio-4x3" style="max-width: 960px; margin: 0 auto;">
<iframe id="gameFrame" src="/play/{{.Software.Name}}/{{.WebPlayableRelease.Version}}/content/index.html"
frameborder="0" allowfullscreen></iframe>
</div>
</div>
{{end}}
<h3>Releases</h3>
<div class="row">
{{range .Releases}}
<div class="col-12 mb-4">
<div class="card h-100">
<div class="card-body">
@@ -12,10 +43,12 @@
<div class="card-footer">
<div class="btn-group d-flex justify-content-center" role="group" aria-label="Operations">
{{if .HTMLFolderPath}}
<a href="/play/{{$.Software.Name}}/{{.Version}}" class="btn btn-success btn-sm">Play</a>
<a href="/play/{{$.Software.Name}}/{{.Version}}" class="btn btn-success btn-sm">Play</a>
{{end}}
<a href="/download/{{$.Software.Name}}/{{.Version}}/source" class="btn btn-primary btn-sm">Source</a>
<a href="/download/{{$.Software.Name}}/{{.Version}}/cartridge" class="btn btn-primary btn-sm">Cartridge</a>
<a href="/download/{{$.Software.Name}}/{{.Version}}/source"
class="btn btn-primary btn-sm">Source</a>
<a href="/download/{{$.Software.Name}}/{{.Version}}/cartridge"
class="btn btn-primary btn-sm">Cartridge</a>
</div>
</div>
</div>
@@ -24,4 +57,4 @@
</div>
<p><a href="/" class="btn btn-primary">Back to Softwares</a></p>
{{end}}
{{end}}