Skip to content

Commit

Permalink
feat: muzik view
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 27, 2019
1 parent d8bbb75 commit dd4fdd3
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 58 deletions.
41 changes: 41 additions & 0 deletions pkg/soundcloud/entities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package soundcloud

import "fmt"

func (p *Playlist) IsMain() bool {
switch p.PlaylistType {
case "single", "album", "compilation", "ep":
return true
}
return false
}

func (p *Playlist) Section() string {
switch p.PlaylistType {
case "album":
return "albums"
case "single", "ep":
return "singles-eps"
case "compilation":
return "appears-on"
}
return "other"
}

func (p *Playlists) BySection(section string) []*Playlist {
out := []*Playlist{}
for _, playlist := range p.Playlists {
if playlist.Section() == section {
out = append(out, playlist)
}
}
return out
}

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

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

func (p *Playlist) ImageURL() string { return p.ArtworkUrl }
96 changes: 95 additions & 1 deletion templates/muzik.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,99 @@
{{define "title"}}Muzik{{end}}

{{/*
{% block title %}Des albums{% endblock %}
{% block subtitle %}pas au hasard{% endblock %}
*/}}

{{define "content"}}
Muzikkk
{{ $columns := 2 }}
{{ $grid_size := div 12 $columns }}
{{ $square_size := 250 }}


<div class="row">
<!--<pre>{{.playlists|toPrettyJson}}</pre>-->
<h2>Albums</h2>
{{ range $entry := (.playlists.BySection "albums") }}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 rotate-random2">
<!--<pre>{{$entry|toPrettyJson}}</pre>-->
<a href="{{ $entry.URL}}" class="thumbnail"
width="{{$square_size}}" height="{{$square_size}}"
{{ if $entry.IsExternal }} target="_blank"{{ end }}>
<div class="caption-wrapper">
<p class="caption">
{{ $entry.Title }}
</p>
</div>
<img src="{{ $entry.ImageURL | resize "fill=500x500" }}"
class="img-responsive"
width="500" height="500" />
</a>
</div>
{{ end }}
</div>

<div class="row">
<h2>Singles & EPs</h2>
{{ range $entry := (.playlists.BySection "singles-eps") }}
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 rotate-random2">
<!--<pre>{{$entry|toPrettyJson}}</pre>-->
<a href="{{ $entry.URL}}" class="thumbnail"
width="{{$square_size}}" height="{{$square_size}}"
{{ 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>

<div class="row">
<h2>Compilations</h2>
{{ range $entry := (.playlists.BySection "appears-on") }}
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 rotate-random2">
<!--<pre>{{$entry|toPrettyJson}}</pre>-->
<a href="{{ $entry.URL}}" class="thumbnail"
width="{{$square_size}}" height="{{$square_size}}"
{{ 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>

<div class="row">
<h2>Brouillons</h2>
{{ range $entry := (.playlists.BySection "other") }}
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 rotate-random2">
<!--<pre>{{$entry|toPrettyJson}}</pre>-->
<a href="{{ $entry.URL}}" class="thumbnail"
width="{{$square_size}}" height="{{$square_size}}"
{{ 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}}
56 changes: 0 additions & 56 deletions templates/old/muzik.html

This file was deleted.

9 changes: 8 additions & 1 deletion views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ func (h *handlers) homeHandler(w http.ResponseWriter, r *http.Request) {

func (h *handlers) muzikHandler(w http.ResponseWriter, r *http.Request) {
h.setDefaultHeaders(w)
data := renderData{"hello": "world"}
playlists, err := h.opts.Svc.SoundcloudPlaylists(r.Context(), &api.Void{})
if err != nil {
h.renderError(w, r, err)
return
}
data := renderData{
"playlists": playlists,
}
h.render(w, r, "muzik.tmpl", data)
}

Expand Down

0 comments on commit dd4fdd3

Please sign in to comment.