Skip to content

Commit

Permalink
feat: album view
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 27, 2019
1 parent dd4fdd3 commit 9c05ba4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 37 deletions.
16 changes: 12 additions & 4 deletions pkg/soundcloud/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func (p *Playlist) Section() string {
return "other"
}

func (p *Playlist) URL() string {
return fmt.Sprintf("/album/%d", p.ID)
}

func (p *Playlist) IsExternal() bool { return false }

func (p *Playlist) ImageURL() string { return p.ArtworkUrl }

func (p *Playlists) BySection(section string) []*Playlist {
out := []*Playlist{}
for _, playlist := range p.Playlists {
Expand All @@ -32,10 +40,10 @@ func (p *Playlists) BySection(section string) []*Playlist {
return out
}

func (p *Playlist) URL() string {
return fmt.Sprintf("/album/%d", p.ID)
func (t *Track) URL() string {
return fmt.Sprintf("/track/%d", t.ID)
}

func (p *Playlist) IsExternal() bool { return true }
func (t *Track) IsExternal() bool { return false }

func (p *Playlist) ImageURL() string { return p.ArtworkUrl }
func (t *Track) ImageURL() string { return t.ArtworkUrl }
42 changes: 42 additions & 0 deletions templates/album.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{define "title"}}{{.album.Title}}{{end}}
{{define "h1"}}Album {{ mot_cool }}{{end}}
{{define "h1small"}}{{.album.Title}}{{end}}

{{define "content"}}

<div class="row">
<!--<pre>{{.album|toPrettyJson}}</pre>-->

<iframe
width="100%"
height="600"
scrolling="no"
frameborder="no"
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/{{ .album.ID }}&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true">
</iframe>

{{ if .album.Description }}
<pre class="album_description">{{ .album.Description | linkify }}</pre>
{{end}}

<h2>Tracks</h2>
{{ range $entry := .album.Tracks }}
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 rotate-random2">
<!--<pre>{{$entry|toPrettyJson}}</pre>-->
<a href="{{ $entry.URL}}" class="thumbnail"
width="500" height="500"
{{ if $entry.IsExternal }} target="_blank"{{ end }}>
<div class="caption-wrapper">
<p class="caption">
{{ $entry.Title }}
</p>
</div>
<img src="{{ $entry.ImageURL | resize "fill=250x250" }}"
class="img-responsive"
width="250" height="250" />
</a>
</div>
{{ end }}
</div>

{{end}}
32 changes: 0 additions & 32 deletions templates/old/album.html

This file was deleted.

1 change: 1 addition & 0 deletions views/funcmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (f *ctxFuncmap) resize(opts ...string) string {
buf := []byte(fmt.Sprintf("%s:%v", path, opts))
h := make([]byte, 8)
sha3.ShakeSum256(h, buf)
//FIXME: process hash based on file content instead of filepath (keep opts)
newpath := fmt.Sprintf("./static/img/cache/%x%s", h, filepath.Ext(path))

if _, err := os.Stat(newpath); !os.IsNotExist(err) {
Expand Down
20 changes: 19 additions & 1 deletion views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Setup(opts *Options) error {
opts.Router.HandleFunc("/hackz", handlers.hackzHandler)
opts.Router.HandleFunc("/copaings", handlers.copaingsHandler)
opts.Router.HandleFunc("/track/{track_id:[0-9]+}", handlers.trackHandler)
opts.Router.HandleFunc("/album/{album_id:[0-9]+}", handlers.albumHandler)

//
// old routes (to be imported)
Expand All @@ -45,7 +46,6 @@ func Setup(opts *Options) error {
// /hackz/recettator
// /hackz/moijaime
// /hackz/phazms GET/POST
// /album/<int:album_id>
// /scorz/inc/<string:user>/<string:what>/<int:points>
// /sitemap.xml

Expand Down Expand Up @@ -118,6 +118,24 @@ func (h *handlers) trackHandler(w http.ResponseWriter, r *http.Request) {
h.render(w, r, "track.tmpl", data)
}

func (h *handlers) albumHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
albumId, err := strconv.ParseUint(vars["album_id"], 10, 64)
if err != nil {
h.renderError(w, r, err)
return
}
album, err := h.opts.Svc.SoundcloudPlaylist(r.Context(), &api.SoundcloudPlaylistInput{
PlaylistId: albumId,
})
if err != nil {
h.renderError(w, r, err)
return
}
data := renderData{"album": album}
h.render(w, r, "album.tmpl", data)
}

func (h *handlers) copaingsHandler(w http.ResponseWriter, r *http.Request) {
h.setDefaultHeaders(w)
data := renderData{"friends": crew.CALC.Friends}
Expand Down

0 comments on commit 9c05ba4

Please sign in to comment.