add artists/tracks pages; more components; css cleanup
This commit is contained in:
parent
065a34a744
commit
b0dd87cad3
37 changed files with 498 additions and 354 deletions
|
|
@ -12,11 +12,46 @@ import (
|
|||
|
||||
func serveTracks(app *model.AppState) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
slices := strings.Split(strings.TrimPrefix(r.URL.Path, "/tracks")[1:], "/")
|
||||
id := slices[0]
|
||||
track, err := controller.GetTrack(app.DB, id)
|
||||
trackID := slices[0]
|
||||
|
||||
if len(trackID) > 0 {
|
||||
serveTrack(app, trackID).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
tracks, err := controller.GetAllTracks(app.DB)
|
||||
if err != nil {
|
||||
fmt.Printf("Error rendering admin track page for %s: %s\n", id, err)
|
||||
fmt.Printf("WARN: Failed to fetch tracks: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
type TracksResponse struct {
|
||||
adminPageData
|
||||
Tracks []*model.Track
|
||||
}
|
||||
|
||||
err = templates.TracksTemplate.Execute(w, TracksResponse{
|
||||
adminPageData: adminPageData{ Path: r.URL.Path, Session: session },
|
||||
Tracks: tracks,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to serve admin tracks page: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func serveTrack(app *model.AppState, trackID string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
track, err := controller.GetTrack(app.DB, trackID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to serve admin track page for %s: %s\n", trackID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
@ -27,7 +62,7 @@ func serveTracks(app *model.AppState) http.Handler {
|
|||
|
||||
releases, err := controller.GetTrackReleases(app.DB, track.ID, true)
|
||||
if err != nil {
|
||||
fmt.Printf("FATAL: Failed to pull releases for %s: %s\n", id, err)
|
||||
fmt.Printf("WARN: Failed to fetch releases for track %s: %s\n", trackID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
@ -38,17 +73,14 @@ func serveTracks(app *model.AppState) http.Handler {
|
|||
Releases []*model.Release
|
||||
}
|
||||
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
err = templates.EditTrackTemplate.Execute(w, TrackResponse{
|
||||
adminPageData: adminPageData{ Path: r.URL.Path, Session: session },
|
||||
Track: track,
|
||||
Releases: releases,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Error rendering admin track page for %s: %s\n", id, err)
|
||||
fmt.Printf("WARN: Failed to serve admin track page for %s: %s\n", trackID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue