Added more filters for editors
This commit is contained in:
parent
8cf76481bf
commit
43c978ed8b
@ -64,6 +64,7 @@ component EditorTabs(url string, user *arn.User)
|
||||
Tab("Status", "calendar-check-o", "/editor/anime/details/status" + user.Settings().Editor.Filter.Suffix())
|
||||
Tab("Trailers", "youtube", "/editor/anime/details/trailers" + user.Settings().Editor.Filter.Suffix())
|
||||
Tab("Start date", "calendar", "/editor/anime/details/startdate" + user.Settings().Editor.Filter.Suffix())
|
||||
Tab("End date", "calendar", "/editor/anime/details/enddate" + user.Settings().Editor.Filter.Suffix())
|
||||
Tab("Ep. Length", "clock-o", "/editor/anime/details/episodelength" + user.Settings().Editor.Filter.Suffix())
|
||||
Tab("Source", "book", "/editor/anime/details/source" + user.Settings().Editor.Filter.Suffix())
|
||||
|
||||
|
22
pages/editor/filteranime/enddate.go
Normal file
22
pages/editor/filteranime/enddate.go
Normal file
@ -0,0 +1,22 @@
|
||||
package filteranime
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/notify.moe/arn"
|
||||
"github.com/animenotifier/notify.moe/arn/validate"
|
||||
)
|
||||
|
||||
// EndDate ...
|
||||
func EndDate(ctx aero.Context) error {
|
||||
return editorList(
|
||||
ctx,
|
||||
"Anime without a valid end date",
|
||||
func(anime *arn.Anime) bool {
|
||||
_, err := time.Parse(validate.DateFormat, anime.EndDate)
|
||||
return err != nil
|
||||
},
|
||||
nil,
|
||||
)
|
||||
}
|
55
pages/editor/filtercharacters/filtercharacters.go
Normal file
55
pages/editor/filtercharacters/filtercharacters.go
Normal file
@ -0,0 +1,55 @@
|
||||
package filtercharacters
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/notify.moe/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
const maxCharacterEntries = 70
|
||||
|
||||
// characterList renders the characters with the given filter for editors.
|
||||
func characterList(ctx aero.Context, title string, filter func(*arn.Character) bool, searchLink func(*arn.Character) string) error {
|
||||
user := arn.GetUserFromContext(ctx)
|
||||
|
||||
if user == nil || (user.Role != "admin" && user.Role != "editor") {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not authorized")
|
||||
}
|
||||
|
||||
characters, count := filterCharacters(ctx, user, filter)
|
||||
|
||||
return ctx.HTML(components.CharacterEditorListFull(
|
||||
title,
|
||||
characters,
|
||||
count,
|
||||
searchLink,
|
||||
user,
|
||||
))
|
||||
}
|
||||
|
||||
// filterCharacters filters anime by the given filter function and
|
||||
// additionally applies year and types filters if specified.
|
||||
func filterCharacters(ctx aero.Context, user *arn.User, filter func(*arn.Character) bool) ([]*arn.Character, int) {
|
||||
// Filter
|
||||
characters := arn.FilterCharacters(func(character *arn.Character) bool {
|
||||
if character.IsDraft {
|
||||
return false
|
||||
}
|
||||
|
||||
return filter(character)
|
||||
})
|
||||
|
||||
// Sort
|
||||
arn.SortCharactersByLikes(characters)
|
||||
|
||||
// Limit
|
||||
count := len(characters)
|
||||
|
||||
if count > maxCharacterEntries {
|
||||
characters = characters[:maxCharacterEntries]
|
||||
}
|
||||
|
||||
return characters, count
|
||||
}
|
30
pages/editor/filtercharacters/filtercharacters.pixy
Normal file
30
pages/editor/filtercharacters/filtercharacters.pixy
Normal file
@ -0,0 +1,30 @@
|
||||
component CharacterEditorListFull(title string, missing []*arn.Character, count int, generateSearchLink func(*arn.Character) string, user *arn.User)
|
||||
.corner-buttons-left
|
||||
a.button(href="/editor")
|
||||
RawIcon("arrow-left")
|
||||
|
||||
h1.editor-list-page-title.mountable= title
|
||||
footer.footer.editor-list-entry-count.mountable= strconv.Itoa(count) + " characters"
|
||||
CharacterEditorList(missing, generateSearchLink)
|
||||
|
||||
component CharacterEditorList(characters []*arn.Character, generateSearchLink func(*arn.Character) string)
|
||||
table.editor-list
|
||||
thead
|
||||
tr.mountable
|
||||
th Name
|
||||
|
||||
if generateSearchLink != nil
|
||||
th Tools
|
||||
tbody
|
||||
each character in characters
|
||||
tr.mountable
|
||||
td
|
||||
a(href=character.Link(), target="_blank", rel="noopener")
|
||||
if character.HasImage()
|
||||
img.character-list-item-image.lazy(data-src=character.ImageLink("small"), data-webp="true", data-color=character.AverageColor(), alt=character.Name.Canonical)
|
||||
|
||||
span= character.Name.Canonical
|
||||
|
||||
if generateSearchLink != nil
|
||||
td
|
||||
a(href=generateSearchLink(character), target="_blank", rel="noopener") 🔍
|
18
pages/editor/filtercharacters/image.go
Normal file
18
pages/editor/filtercharacters/image.go
Normal file
@ -0,0 +1,18 @@
|
||||
package filtercharacters
|
||||
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/notify.moe/arn"
|
||||
)
|
||||
|
||||
// NoImage ...
|
||||
func NoImage(ctx aero.Context) error {
|
||||
return characterList(
|
||||
ctx,
|
||||
"Characters without an image",
|
||||
func(character *arn.Character) bool {
|
||||
return !character.HasImage()
|
||||
},
|
||||
nil,
|
||||
)
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/animenotifier/notify.moe/pages/editlog"
|
||||
"github.com/animenotifier/notify.moe/pages/editor"
|
||||
"github.com/animenotifier/notify.moe/pages/editor/filteranime"
|
||||
"github.com/animenotifier/notify.moe/pages/editor/filtercharacters"
|
||||
"github.com/animenotifier/notify.moe/pages/editor/filtercompanies"
|
||||
"github.com/animenotifier/notify.moe/pages/editor/filtersoundtracks"
|
||||
"github.com/animenotifier/notify.moe/pages/editor/jobs"
|
||||
@ -43,12 +44,16 @@ func Register(app *aero.Application) {
|
||||
editorFilterable("/editor/anime/details/genres", filteranime.Genres)
|
||||
editorFilterable("/editor/anime/details/trailers", filteranime.Trailers)
|
||||
editorFilterable("/editor/anime/details/startdate", filteranime.StartDate)
|
||||
editorFilterable("/editor/anime/details/enddate", filteranime.EndDate)
|
||||
editorFilterable("/editor/anime/details/episodelength", filteranime.EpisodeLength)
|
||||
editorFilterable("/editor/anime/details/source", filteranime.Source)
|
||||
editorFilterable("/editor/anime/details/status", filteranime.Status)
|
||||
|
||||
editorFilterable("/editor/anime/all", filteranime.All)
|
||||
|
||||
// Editor - Characters
|
||||
page.Get(app, "/editor/character/image/none", filtercharacters.NoImage)
|
||||
|
||||
// Editor - MALdiff
|
||||
editorFilterable("/editor/mal/diff/anime", editor.CompareMAL)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user