Added tag filter for soundtracks
This commit is contained in:
parent
e67a2023c7
commit
634bbb151e
@ -19,6 +19,7 @@
|
|||||||
"grid",
|
"grid",
|
||||||
"forum",
|
"forum",
|
||||||
"tabs",
|
"tabs",
|
||||||
|
"tags",
|
||||||
"user",
|
"user",
|
||||||
"video",
|
"video",
|
||||||
"loading",
|
"loading",
|
||||||
|
@ -3,22 +3,7 @@
|
|||||||
justify-content center
|
justify-content center
|
||||||
|
|
||||||
.anime-genre
|
.anime-genre
|
||||||
default-transition
|
genre-tag
|
||||||
padding 0.25rem 0.75rem
|
|
||||||
font-size 85%
|
|
||||||
color text-color
|
|
||||||
background reverse-light-color
|
|
||||||
border-radius ui-element-border-radius
|
|
||||||
margin 0.35rem
|
|
||||||
|
|
||||||
&.mounted
|
|
||||||
opacity 0.8
|
|
||||||
|
|
||||||
:hover
|
|
||||||
color text-color
|
|
||||||
opacity 1.0
|
|
||||||
text-shadow none
|
|
||||||
background reverse-light-hover-color
|
|
||||||
|
|
||||||
> 800px
|
> 800px
|
||||||
.anime-genres
|
.anime-genres
|
||||||
|
@ -144,6 +144,8 @@ func Configure(app *aero.Application) {
|
|||||||
l.Page("/soundtracks/from/:index", soundtracks.LatestFrom)
|
l.Page("/soundtracks/from/:index", soundtracks.LatestFrom)
|
||||||
l.Page("/soundtracks/best", soundtracks.Best)
|
l.Page("/soundtracks/best", soundtracks.Best)
|
||||||
l.Page("/soundtracks/best/from/:index", soundtracks.BestFrom)
|
l.Page("/soundtracks/best/from/:index", soundtracks.BestFrom)
|
||||||
|
l.Page("/soundtracks/tag/:tag", soundtracks.FilterByTag)
|
||||||
|
l.Page("/soundtracks/tag/:tag/from/:index", soundtracks.FilterByTagFrom)
|
||||||
l.Page("/soundtrack/:id", soundtrack.Get)
|
l.Page("/soundtrack/:id", soundtrack.Get)
|
||||||
l.Page("/soundtrack/:id/edit", soundtrack.Edit)
|
l.Page("/soundtrack/:id/edit", soundtrack.Edit)
|
||||||
|
|
||||||
|
@ -41,5 +41,5 @@ func Get(ctx *aero.Context) string {
|
|||||||
|
|
||||||
ctx.Data = openGraph
|
ctx.Data = openGraph
|
||||||
|
|
||||||
return ctx.HTML(components.Track(track, user))
|
return ctx.HTML(components.SoundTrackPage(track, user))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
component Track(track *arn.SoundTrack, user *arn.User)
|
component SoundTrackPage(track *arn.SoundTrack, user *arn.User)
|
||||||
SoundTrackTabs(track, user)
|
SoundTrackTabs(track, user)
|
||||||
|
|
||||||
.soundtrack-full-page
|
.soundtrack-full-page
|
||||||
@ -35,11 +35,14 @@ component Track(track *arn.SoundTrack, user *arn.User)
|
|||||||
for index, beatmap := range track.Beatmaps()
|
for index, beatmap := range track.Beatmaps()
|
||||||
li
|
li
|
||||||
a.beatmap(href="https://osu.ppy.sh/s/" + beatmap, target="_blank")= "Beatmap #" + strconv.Itoa(index + 1)
|
a.beatmap(href="https://osu.ppy.sh/s/" + beatmap, target="_blank")= "Beatmap #" + strconv.Itoa(index + 1)
|
||||||
|
|
||||||
.widget.mountable
|
.widget.mountable
|
||||||
h3.widget-title Tags
|
h3.widget-title Tags
|
||||||
|
|
||||||
.tags
|
.tags
|
||||||
each tag in track.Tags
|
each tag in track.Tags
|
||||||
.tag= tag
|
a.tag.ajax(href="/soundtracks/tag/" + tag)= tag
|
||||||
|
|
||||||
.footer.mountable
|
.footer.mountable
|
||||||
if track.EditedBy != ""
|
if track.EditedBy != ""
|
||||||
span Edited
|
span Edited
|
||||||
|
@ -20,11 +20,15 @@ func Best(ctx *aero.Context) string {
|
|||||||
|
|
||||||
arn.SortSoundTracksPopularFirst(tracks)
|
arn.SortSoundTracksPopularFirst(tracks)
|
||||||
|
|
||||||
|
// Limit the number of displayed tracks
|
||||||
|
loadMoreIndex := 0
|
||||||
|
|
||||||
if len(tracks) > maxTracks {
|
if len(tracks) > maxTracks {
|
||||||
tracks = tracks[:maxTracks]
|
tracks = tracks[:maxTracks]
|
||||||
|
loadMoreIndex = maxTracks
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.SoundTracks(tracks, maxTracks, user))
|
return ctx.HTML(components.SoundTracks(tracks, loadMoreIndex, "", user))
|
||||||
}
|
}
|
||||||
|
|
||||||
// BestFrom renders the soundtracks from the given index.
|
// BestFrom renders the soundtracks from the given index.
|
||||||
|
@ -30,7 +30,7 @@ func Latest(ctx *aero.Context) string {
|
|||||||
loadMoreIndex = maxTracks
|
loadMoreIndex = maxTracks
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.SoundTracks(tracks, loadMoreIndex, user))
|
return ctx.HTML(components.SoundTracks(tracks, loadMoreIndex, "", user))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LatestFrom renders the soundtracks from the given index.
|
// LatestFrom renders the soundtracks from the given index.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
component SoundTracks(tracks []*arn.SoundTrack, loadMoreIndex int, user *arn.User)
|
component SoundTracks(tracks []*arn.SoundTrack, loadMoreIndex int, tag string, user *arn.User)
|
||||||
h1.page-title Soundtracks
|
h1.page-title Soundtracks
|
||||||
|
|
||||||
SoundTracksTabs
|
SoundTracksTabs(tag)
|
||||||
|
|
||||||
.corner-buttons
|
.corner-buttons
|
||||||
if user != nil
|
if user != nil
|
||||||
@ -25,7 +25,10 @@ component SoundTracksScrollable(tracks []*arn.SoundTrack, user *arn.User)
|
|||||||
each track in tracks
|
each track in tracks
|
||||||
SoundTrack(track)
|
SoundTrack(track)
|
||||||
|
|
||||||
component SoundTracksTabs
|
component SoundTracksTabs(tag string)
|
||||||
.tabs
|
.tabs
|
||||||
Tab("Latest", "music", "/soundtracks")
|
Tab("Latest", "music", "/soundtracks")
|
||||||
Tab("Best", "heart", "/soundtracks/best")
|
Tab("Best", "heart", "/soundtracks/best")
|
||||||
|
|
||||||
|
if tag != ""
|
||||||
|
Tab(tag, "tag", "/soundtracks/tag/" + tag)
|
72
pages/soundtracks/tag.go
Normal file
72
pages/soundtracks/tag.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package soundtracks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FilterByTag renders the soundtracks with the given tag.
|
||||||
|
func FilterByTag(ctx *aero.Context) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
tag := ctx.Get("tag")
|
||||||
|
|
||||||
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
|
return !track.IsDraft && len(track.Media) > 0 && track.HasTag(tag)
|
||||||
|
})
|
||||||
|
|
||||||
|
arn.SortSoundTracksPopularFirst(tracks)
|
||||||
|
|
||||||
|
// Limit the number of displayed tracks
|
||||||
|
loadMoreIndex := 0
|
||||||
|
|
||||||
|
if len(tracks) > maxTracks {
|
||||||
|
tracks = tracks[:maxTracks]
|
||||||
|
loadMoreIndex = maxTracks
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.HTML(components.SoundTracks(tracks, loadMoreIndex, tag, user))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByTagFrom renders the soundtracks from the given index.
|
||||||
|
func FilterByTagFrom(ctx *aero.Context) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
tag := ctx.Get("tag")
|
||||||
|
index, err := ctx.GetInt("index")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Error(http.StatusBadRequest, "Invalid start index", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
allTracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
|
return !track.IsDraft && len(track.Media) > 0 && track.HasTag(tag)
|
||||||
|
})
|
||||||
|
|
||||||
|
if index < 0 || index >= len(allTracks) {
|
||||||
|
return ctx.Error(http.StatusBadRequest, "Invalid start index (maximum is "+strconv.Itoa(len(allTracks))+")", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
arn.SortSoundTracksPopularFirst(allTracks)
|
||||||
|
|
||||||
|
tracks := allTracks[index:]
|
||||||
|
|
||||||
|
if len(tracks) > maxTracks {
|
||||||
|
tracks = tracks[:maxTracks]
|
||||||
|
}
|
||||||
|
|
||||||
|
nextIndex := index + maxTracks
|
||||||
|
|
||||||
|
if nextIndex >= len(allTracks) {
|
||||||
|
// End of data - no more scrolling
|
||||||
|
ctx.Response().Header().Set("X-LoadMore-Index", "-1")
|
||||||
|
} else {
|
||||||
|
// Send the index for the next request
|
||||||
|
ctx.Response().Header().Set("X-LoadMore-Index", strconv.Itoa(nextIndex))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.HTML(components.SoundTracksScrollable(tracks, user))
|
||||||
|
}
|
@ -3,6 +3,24 @@ mixin tag-dimensions
|
|||||||
margin 0.4rem
|
margin 0.4rem
|
||||||
height 38px
|
height 38px
|
||||||
|
|
||||||
|
mixin genre-tag
|
||||||
|
default-transition
|
||||||
|
padding 0.25rem 0.75rem
|
||||||
|
font-size 85%
|
||||||
|
color text-color
|
||||||
|
background reverse-light-color
|
||||||
|
border-radius ui-element-border-radius
|
||||||
|
margin 0.35rem
|
||||||
|
|
||||||
|
&.mounted
|
||||||
|
opacity 0.8
|
||||||
|
|
||||||
|
:hover
|
||||||
|
color text-color
|
||||||
|
opacity 1.0
|
||||||
|
text-shadow none
|
||||||
|
background reverse-light-hover-color
|
||||||
|
|
||||||
.tags
|
.tags
|
||||||
horizontal-wrap
|
horizontal-wrap
|
||||||
|
|
||||||
@ -10,6 +28,7 @@ mixin tag-dimensions
|
|||||||
ui-element
|
ui-element
|
||||||
tag-dimensions
|
tag-dimensions
|
||||||
margin-right 0
|
margin-right 0
|
||||||
|
color text-color
|
||||||
|
|
||||||
.tag-edit
|
.tag-edit
|
||||||
border-right none
|
border-right none
|
||||||
|
Loading…
Reference in New Issue
Block a user