New filters for soundtrack editors

This commit is contained in:
Eduard Urbach 2018-04-13 13:09:46 +02:00
parent 06c09bc1ff
commit b1bc006a0c
10 changed files with 159 additions and 41 deletions

View File

@ -78,4 +78,11 @@ component EditorTabs(url string, user *arn.User)
.corner-buttons.fixed
#filter-root(data-url=url)
ExploreFilters(user.Settings().Editor.Filter.Year, user.Settings().Editor.Filter.Status, user.Settings().Editor.Filter.Type, true)
if strings.Contains(url, "/editor/soundtracks/")
.tabs
Tab("Links", "external-link", "/editor/soundtracks/links")
Tab("Lyrics", "font", "/editor/soundtracks/lyrics")
Tab("Tags", "tag", "/editor/soundtracks/tags")
Tab("File", "volume-off", "/editor/soundtracks/file")

View File

@ -0,0 +1,18 @@
package filtersoundtracks
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
)
// File shows soundtracks without an audio file.
func File(ctx *aero.Context) string {
return editorList(
ctx,
"Soundtracks without an audio file",
func(track *arn.SoundTrack) bool {
return track.File == ""
},
nil,
)
}

View File

@ -1,33 +0,0 @@
package filtersoundtracks
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
const maxEntries = 70
// NoLinks ...
func NoLinks(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "admin" && user.Role != "editor") {
return ctx.Redirect("/")
}
soundTracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
return !track.IsDraft && len(track.Links) == 0
})
arn.SortSoundTracksPopularFirst(soundTracks)
count := len(soundTracks)
if count > maxEntries {
soundTracks = soundTracks[:maxEntries]
}
return ctx.HTML(components.SoundTracksEditorList(soundTracks, count, ctx.URI(), user))
}

View File

@ -1,8 +1,10 @@
component SoundTracksEditorList(tracks []*arn.SoundTrack, count int, url string, user *arn.User)
EditorTabs(url, user)
h1.editor-list-page-title.mountable Soundtracks without links
component SoundTracksEditorListFull(title string, missing []*arn.SoundTrack, count int, pageURI string, generateSearchLink func(*arn.SoundTrack) string, user *arn.User)
EditorTabs(pageURI, user)
h1.editor-list-page-title.mountable= title
.footer.editor-list-entry-count.mountable= strconv.Itoa(count) + " soundtracks"
SoundTracksEditorList(missing, generateSearchLink, user)
component SoundTracksEditorList(tracks []*arn.SoundTrack, generateSearchLink func(*arn.SoundTrack) string, user *arn.User)
table.editor-list
thead
tr.mountable
@ -14,7 +16,8 @@ component SoundTracksEditorList(tracks []*arn.SoundTrack, count int, url string,
td= len(track.Likes)
td
a(href=track.Link(), target="_blank", rel="noopener")= track.Title.ByUser(user)
td
each media in track.Media
if media.Service == "Youtube"
a(href="https://song.link/https://youtu.be/" + media.ServiceID, target="_blank", rel="noopener") 🔍
if generateSearchLink != nil
td
if generateSearchLink(track) != ""
a(href=generateSearchLink(track), target="_blank", rel="noopener") 🔍

View File

@ -0,0 +1,28 @@
package filtersoundtracks
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
)
const maxEntries = 70
// Links shows soundtracks without links.
func Links(ctx *aero.Context) string {
return editorList(
ctx,
"Soundtracks without links",
func(track *arn.SoundTrack) bool {
return len(track.Links) == 0
},
func(track *arn.SoundTrack) string {
youtubeMedia := track.MediaByService("Youtube")
if len(youtubeMedia) > 0 {
return "https://song.link/https://youtu.be/" + youtubeMedia[0].ServiceID
}
return ""
},
)
}

View File

@ -0,0 +1,20 @@
package filtersoundtracks
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
)
// Lyrics shows soundtracks without lyrics.
func Lyrics(ctx *aero.Context) string {
return editorList(
ctx,
"Soundtracks without lyrics",
func(track *arn.SoundTrack) bool {
return !track.HasLyrics()
},
func(track *arn.SoundTrack) string {
return "https://www.google.com/search?q=" + track.Title.String() + " lyrics site:animelyrics.com"
},
)
}

View File

@ -0,0 +1,18 @@
package filtersoundtracks
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
)
// Tags shows soundtracks with less than 3 tags.
func Tags(ctx *aero.Context) string {
return editorList(
ctx,
"Soundtracks with less than 3 tags",
func(track *arn.SoundTrack) bool {
return len(track.Tags) < 3
},
nil,
)
}

View File

@ -0,0 +1,54 @@
package filtersoundtracks
import (
"net/http"
"strings"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
const maxSoundTrackEntries = 70
// editorList renders the soundtrack list with the given title and filter.
func editorList(ctx *aero.Context, title string, filter func(*arn.SoundTrack) bool, searchLink func(*arn.SoundTrack) string) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "admin" && user.Role != "editor") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
}
tracks, count := filterSoundTracks(ctx, user, filter)
url := strings.TrimPrefix(ctx.URI(), "/_")
return ctx.HTML(components.SoundTracksEditorListFull(
title,
tracks,
count,
url,
searchLink,
user,
))
}
// filterSoundTracks filters soundtracks by the given filter function.
func filterSoundTracks(ctx *aero.Context, user *arn.User, filter func(*arn.SoundTrack) bool) ([]*arn.SoundTrack, int) {
// Filter
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
return !track.IsDraft && filter(track)
})
// Sort
arn.SortSoundTracksPopularFirst(tracks)
// Limit
count := len(tracks)
if count > maxSoundTrackEntries {
tracks = tracks[:maxSoundTrackEntries]
}
return tracks, count
}

View File

@ -305,7 +305,10 @@ func Configure(app *aero.Application) {
l.Page("/editor/companies/description", filtercompanies.NoDescription)
// Editor - Soundtracks
l.Page("/editor/soundtracks/links", filtersoundtracks.NoLinks)
l.Page("/editor/soundtracks/links", filtersoundtracks.Links)
l.Page("/editor/soundtracks/lyrics", filtersoundtracks.Lyrics)
l.Page("/editor/soundtracks/tags", filtersoundtracks.Tags)
l.Page("/editor/soundtracks/file", filtersoundtracks.File)
// Log
l.Page("/log", editlog.Get)