From c9f51037dc3999c149cd77d2fd58f63b1eddcd92 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 6 Oct 2017 22:07:12 +0200 Subject: [PATCH] Improved editor tools --- main.go | 8 ++- pages/admin/admin.pixy | 6 ++- pages/admin/webdev.pixy | 81 ++++++++++++++-------------- pages/{admin => editor}/anilist.go | 20 ++++++- pages/{admin => editor}/anilist.pixy | 15 ++++-- pages/editor/editor.go | 18 +++++++ pages/editor/editor.pixy | 16 ++++++ pages/{admin => editor}/shoboi.go | 20 ++++++- pages/{admin => editor}/shoboi.pixy | 15 ++++-- sw/service-worker.ts | 1 - tests.go | 4 +- 11 files changed, 148 insertions(+), 56 deletions(-) rename pages/{admin => editor}/anilist.go (61%) rename pages/{admin => editor}/anilist.pixy (73%) create mode 100644 pages/editor/editor.go create mode 100644 pages/editor/editor.pixy rename pages/{admin => editor}/shoboi.go (61%) rename pages/{admin => editor}/shoboi.pixy (73%) diff --git a/main.go b/main.go index 901769b0..e7ae17b5 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "github.com/animenotifier/notify.moe/pages/charge" "github.com/animenotifier/notify.moe/pages/dashboard" "github.com/animenotifier/notify.moe/pages/editanime" + "github.com/animenotifier/notify.moe/pages/editor" "github.com/animenotifier/notify.moe/pages/embed" "github.com/animenotifier/notify.moe/pages/explore" "github.com/animenotifier/notify.moe/pages/forum" @@ -134,10 +135,13 @@ func configure(app *aero.Application) *aero.Application { // Admin app.Ajax("/admin", admin.Get) - app.Ajax("/admin/anilist", admin.AniList) - app.Ajax("/admin/shoboi", admin.Shoboi) app.Ajax("/admin/webdev", admin.WebDev) + // Editor + app.Ajax("/editor", editor.Get) + app.Ajax("/editor/anilist", editor.AniList) + app.Ajax("/editor/shoboi", editor.Shoboi) + // Import app.Ajax("/import", listimport.Get) app.Ajax("/import/anilist/animelist", listimportanilist.Preview) diff --git a/pages/admin/admin.pixy b/pages/admin/admin.pixy index d7a94611..1bb6596e 100644 --- a/pages/admin/admin.pixy +++ b/pages/admin/admin.pixy @@ -2,8 +2,10 @@ component AdminTabs .tabs Tab("Server", "server", "/admin") Tab("WebDev", "html5", "/admin/webdev") - Tab("Shoboi", "calendar", "/admin/shoboi") - Tab("AniList", "list", "/admin/anilist") + + a.tab.ajax(href="/editor", aria-label="Editor") + Icon("pencil") + span.tab-text Editor component Admin(user *arn.User, cpuUsage, memUsage, diskUsage float64, platform, family, platformVersion, kernelVersion string) h1.page-title Admin Panel diff --git a/pages/admin/webdev.pixy b/pages/admin/webdev.pixy index a9c31884..0be46d3a 100644 --- a/pages/admin/webdev.pixy +++ b/pages/admin/webdev.pixy @@ -2,44 +2,47 @@ component WebDev AdminTabs h1.page-title WebDev - - h2 Tests - - .buttons - a.button.mountable(href="https://developers.google.com/speed/pagespeed/insights/?url=https://notify.moe/&tab=desktop", target="_blank", rel="noopener") - Icon("external-link") - span Google PageSpeed - a.button.mountable(href="https://observatory.mozilla.org/analyze.html?host=notify.moe", target="_blank", rel="noopener") - Icon("external-link") - span Mozilla Observatory - a.button.mountable(href="https://html5.validator.nu/?doc=https://notify.moe", target="_blank", rel="noopener") - Icon("external-link") - span HTML5 Validator - a.button.mountable(href="https://testmysite.withgoogle.com/", target="_blank", rel="noopener") - Icon("external-link") - span Mobile Speed - a.button.mountable(href="https://www.webpagetest.org/", target="_blank", rel="noopener") - Icon("external-link") - span Web Page Test - h2 Browser Support + .widgets + .widget.mountable + h3.widget-title Tests - .buttons - a.button.mountable(href="http://caniuse.com/#feat=webp", target="_blank", rel="noopener") - Icon("external-link") - span WebP - a.button.mountable(href="http://caniuse.com/#feat=push-api", target="_blank", rel="noopener") - Icon("external-link") - span Push API - a.button.mountable(href="http://caniuse.com/#feat=serviceworkers", target="_blank", rel="noopener") - Icon("external-link") - span Service Worker - a.button.mountable(href="http://caniuse.com/#feat=intersectionobserver", target="_blank", rel="noopener") - Icon("external-link") - span Intersection Observer - a.button.mountable(href="http://caniuse.com/#feat=requestidlecallback", target="_blank", rel="noopener") - Icon("external-link") - span Request Idle Callback - a.button.mountable(href="http://caniuse.com/#feat=css-variables", target="_blank", rel="noopener") - Icon("external-link") - span CSS Variables \ No newline at end of file + .buttons + a.button.mountable(href="https://developers.google.com/speed/pagespeed/insights/?url=https://notify.moe/&tab=desktop", target="_blank", rel="noopener") + Icon("external-link") + span Google PageSpeed + a.button.mountable(href="https://observatory.mozilla.org/analyze.html?host=notify.moe", target="_blank", rel="noopener") + Icon("external-link") + span Mozilla Observatory + a.button.mountable(href="https://html5.validator.nu/?doc=https://notify.moe", target="_blank", rel="noopener") + Icon("external-link") + span HTML5 Validator + a.button.mountable(href="https://testmysite.withgoogle.com/", target="_blank", rel="noopener") + Icon("external-link") + span Mobile Speed + a.button.mountable(href="https://www.webpagetest.org/", target="_blank", rel="noopener") + Icon("external-link") + span Web Page Test + + .widget.mountable + h3.widget-title Browser Support + + .buttons + a.button.mountable(href="http://caniuse.com/#feat=webp", target="_blank", rel="noopener") + Icon("external-link") + span WebP + a.button.mountable(href="http://caniuse.com/#feat=push-api", target="_blank", rel="noopener") + Icon("external-link") + span Push API + a.button.mountable(href="http://caniuse.com/#feat=serviceworkers", target="_blank", rel="noopener") + Icon("external-link") + span Service Worker + a.button.mountable(href="http://caniuse.com/#feat=intersectionobserver", target="_blank", rel="noopener") + Icon("external-link") + span Intersection Observer + a.button.mountable(href="http://caniuse.com/#feat=requestidlecallback", target="_blank", rel="noopener") + Icon("external-link") + span Request Idle Callback + a.button.mountable(href="http://caniuse.com/#feat=css-variables", target="_blank", rel="noopener") + Icon("external-link") + span CSS Variables \ No newline at end of file diff --git a/pages/admin/anilist.go b/pages/editor/anilist.go similarity index 61% rename from pages/admin/anilist.go rename to pages/editor/anilist.go index bcd74838..ffb8678b 100644 --- a/pages/admin/anilist.go +++ b/pages/editor/anilist.go @@ -1,4 +1,4 @@ -package admin +package editor import ( "net/http" @@ -9,6 +9,8 @@ import ( "github.com/animenotifier/notify.moe/components" ) +const maxAniListEntries = 70 + // AniList ... func AniList(ctx *aero.Context) string { missing, err := arn.FilterAnime(func(anime *arn.Anime) bool { @@ -20,8 +22,22 @@ func AniList(ctx *aero.Context) string { } sort.Slice(missing, func(i, j int) bool { - return missing[i].StartDate > missing[j].StartDate + a := missing[i] + b := missing[j] + + aPop := a.Popularity.Total() + bPop := b.Popularity.Total() + + if aPop == bPop { + return a.Title.Canonical < b.Title.Canonical + } + + return aPop > bPop }) + if len(missing) > maxAniListEntries { + missing = missing[:maxAniListEntries] + } + return ctx.HTML(components.AniListMissingMapping(missing)) } diff --git a/pages/admin/anilist.pixy b/pages/editor/anilist.pixy similarity index 73% rename from pages/admin/anilist.pixy rename to pages/editor/anilist.pixy index cbed563c..d27b6086 100644 --- a/pages/admin/anilist.pixy +++ b/pages/editor/anilist.pixy @@ -1,16 +1,25 @@ component AniListMissingMapping(missing []*arn.Anime) h1.page-title Anime without Anilist links - AdminTabs + EditorTabs table + thead + tr + th(title="Popularity") Pop. + th Title + th Type + th Year + th Tools tbody each anime in missing tr + td= anime.Popularity.Total() + td + a(href=anime.Link(), target="_blank", rel="noopener")= anime.Title.Canonical + td= anime.Type td if len(anime.StartDate) >= 4 span= anime.StartDate[:4] - td - a(href=anime.Link(), target="_blank", rel="noopener")= anime.Title.Canonical td a(href="https://anilist.co/search?type=anime&q=" + anime.Title.Canonical, target="_blank", rel="noopener") Search diff --git a/pages/editor/editor.go b/pages/editor/editor.go new file mode 100644 index 00000000..3abccc97 --- /dev/null +++ b/pages/editor/editor.go @@ -0,0 +1,18 @@ +package editor + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// Get ... +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil || (user.Role != "admin" && user.Role != "editor") { + return ctx.Redirect("/") + } + + return ctx.HTML(components.Editor()) +} diff --git a/pages/editor/editor.pixy b/pages/editor/editor.pixy new file mode 100644 index 00000000..c4af0c40 --- /dev/null +++ b/pages/editor/editor.pixy @@ -0,0 +1,16 @@ +component Editor + h1.page-title Editor Panel + + EditorTabs + + p Welcome to the Editor Panel! + +component EditorTabs + .tabs + Tab("Editor", "pencil", "/editor") + Tab("Shoboi", "calendar", "/editor/shoboi") + Tab("AniList", "list", "/editor/anilist") + + a.tab.ajax(href="/admin", aria-label="Admin") + Icon("wrench") + span.tab-text Admin \ No newline at end of file diff --git a/pages/admin/shoboi.go b/pages/editor/shoboi.go similarity index 61% rename from pages/admin/shoboi.go rename to pages/editor/shoboi.go index c4cdbd33..dd33e329 100644 --- a/pages/admin/shoboi.go +++ b/pages/editor/shoboi.go @@ -1,4 +1,4 @@ -package admin +package editor import ( "net/http" @@ -9,6 +9,8 @@ import ( "github.com/animenotifier/notify.moe/components" ) +const maxShoboiEntries = 70 + // Shoboi ... func Shoboi(ctx *aero.Context) string { missing, err := arn.FilterAnime(func(anime *arn.Anime) bool { @@ -20,8 +22,22 @@ func Shoboi(ctx *aero.Context) string { } sort.Slice(missing, func(i, j int) bool { - return missing[i].StartDate > missing[j].StartDate + a := missing[i] + b := missing[j] + + aPop := a.Popularity.Total() + bPop := b.Popularity.Total() + + if aPop == bPop { + return a.Title.Canonical < b.Title.Canonical + } + + return aPop > bPop }) + if len(missing) > maxShoboiEntries { + missing = missing[:maxShoboiEntries] + } + return ctx.HTML(components.ShoboiMissingMapping(missing)) } diff --git a/pages/admin/shoboi.pixy b/pages/editor/shoboi.pixy similarity index 73% rename from pages/admin/shoboi.pixy rename to pages/editor/shoboi.pixy index 5224eae7..8dd2aca0 100644 --- a/pages/admin/shoboi.pixy +++ b/pages/editor/shoboi.pixy @@ -1,16 +1,25 @@ component ShoboiMissingMapping(missing []*arn.Anime) h1.page-title Anime without Shoboi links - AdminTabs + EditorTabs table + thead + tr + th(title="Popularity") Pop. + th Title + th Type + th Year + th Tools tbody each anime in missing tr + td= anime.Popularity.Total() + td + a(href=anime.Link(), target="_blank", rel="noopener")= anime.Title.Canonical + td= anime.Type td if len(anime.StartDate) >= 4 span= anime.StartDate[:4] - td - a(href=anime.Link(), target="_blank", rel="noopener")= anime.Title.Canonical td a(href="http://cal.syoboi.jp/find?type=quick&sd=1&kw=" + anime.Title.Japanese, target="_blank", rel="noopener") Search diff --git a/sw/service-worker.ts b/sw/service-worker.ts index da79784a..6f800784 100644 --- a/sw/service-worker.ts +++ b/sw/service-worker.ts @@ -6,7 +6,6 @@ const ETAGS = new Map() const CACHEREFRESH = new Map>() const EXCLUDECACHE = new Set([ "/api/", - "/admin/", "/paypal/", "/import/", "chrome-extension" diff --git a/tests.go b/tests.go index 75b135a6..07253ae9 100644 --- a/tests.go +++ b/tests.go @@ -242,8 +242,8 @@ var routeTests = map[string][]string{ "/anime/:id/edit": nil, "/new/thread": nil, "/new/soundtrack": nil, - "/admin/anilist": nil, - "/admin/shoboi": nil, + "/editor/anilist": nil, + "/editor/shoboi": nil, "/user": nil, "/settings": nil, "/shop": nil,