sw show page
This commit is contained in:
@@ -26,7 +26,7 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
version := chi.URLParam(r, "version")
|
||||
|
||||
software, err := c.softwareService.GetByNameWithReleases(name)
|
||||
software, err := c.softwareService.GetByName(name)
|
||||
if err != nil {
|
||||
if err == domain.ErrSoftwareNotFound {
|
||||
http.Error(w, "Software not found", http.StatusNotFound)
|
||||
|
||||
+29
-17
@@ -10,15 +10,15 @@ import (
|
||||
)
|
||||
|
||||
type SoftwareController struct {
|
||||
service domain.SoftwareServiceInterface
|
||||
softwareService domain.SoftwareServiceInterface
|
||||
}
|
||||
|
||||
func NewSoftwareController(service domain.SoftwareServiceInterface) *SoftwareController {
|
||||
return &SoftwareController{service: service}
|
||||
func NewSoftwareController(software_service domain.SoftwareServiceInterface) *SoftwareController {
|
||||
return &SoftwareController{softwareService: software_service}
|
||||
}
|
||||
|
||||
func (c *SoftwareController) index(w http.ResponseWriter, r *http.Request) {
|
||||
softwares, err := c.service.List()
|
||||
softwares, err := c.softwareService.List()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -33,25 +33,37 @@ func (c *SoftwareController) index(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl.Execute(w, softwares)
|
||||
}
|
||||
|
||||
func (c *SoftwareController) releases(w http.ResponseWriter, r *http.Request) {
|
||||
type SoftwareShowData struct {
|
||||
Software *domain.Software
|
||||
LatestVersion string
|
||||
}
|
||||
|
||||
func (c *SoftwareController) show(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
software, err := c.service.GetByNameWithReleases(name)
|
||||
if err != nil {
|
||||
if err == domain.ErrSoftwareNotFound {
|
||||
http.Error(w, "Software not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template_utils.GetTemplate("software_releases", "http/views/shared/layout.html", "http/views/software/releases.html")
|
||||
software, err := c.softwareService.GetByName(name)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if software == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl.Execute(w, map[string]interface{}{
|
||||
"Software": software,
|
||||
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, _ := template_utils.GetTemplate("software_show", "http/views/shared/layout.html", "http/views/software/show.html")
|
||||
tmpl.Execute(w, SoftwareShowData{
|
||||
Software: software,
|
||||
LatestVersion: latest_release.Version,
|
||||
})
|
||||
}
|
||||
|
||||
+3
-2
@@ -34,9 +34,10 @@ func (r *Router) Init() *chi.Mux {
|
||||
router := chi.NewRouter()
|
||||
|
||||
router.Get("/", r.rootController.index)
|
||||
router.Get("/softwares", r.softwareController.index)
|
||||
router.Get("/software", r.softwareController.index)
|
||||
router.Get("/software/{name}", r.softwareController.show)
|
||||
|
||||
router.Get("/update", r.softwareUpdaterController.update)
|
||||
router.Get("/releases/{name}", r.softwareController.releases)
|
||||
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)
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
<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="/releases/{{.Name}}" class="btn btn-primary btn-sm">Releases</a>
|
||||
<a href="/play/{{.Name}}" class="btn btn-primary btn-sm">Play</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>
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Version: {{.Version}}</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">Released At: {{.CreatedAt.Format "2006-01-02 15:04:05"}}</h6>
|
||||
<p class="card-subtitle mb-2 text-muted">Released At: {{.CreatedAt.Format "2006-01-02 15:04:05"}}</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="btn-group d-flex justify-content-center" role="group" aria-label="Operations">
|
||||
{{if .WebPlayable}}
|
||||
{{if .HTMLFolderPath != ""}}
|
||||
<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>
|
||||
Reference in New Issue
Block a user