From e99225ce1043e751a36c9dcbac10d20e08c9929c Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 18 Jun 2017 17:16:40 +0200 Subject: [PATCH] Added extra navigation and new pages --- fade.scarlet | 7 ++++++ main.go | 4 ++++ middleware/Log.go | 5 ++-- mixins/Navigation.pixy | 21 ++++++++++++---- pages/admin/admin.go | 18 ++++++++++++++ pages/admin/admin.pixy | 6 +++++ pages/anime/anime.pixy | 3 --- pages/settings/settings.go | 18 ++++++++++++++ pages/settings/settings.pixy | 3 +++ reset.scarlet | 46 ++++++++++++++++++++++++++++++++++++ styles/navigation.scarlet | 20 +++++++++++++++- 11 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 fade.scarlet create mode 100644 pages/admin/admin.go create mode 100644 pages/admin/admin.pixy create mode 100644 pages/settings/settings.go create mode 100644 pages/settings/settings.pixy create mode 100644 reset.scarlet diff --git a/fade.scarlet b/fade.scarlet new file mode 100644 index 00000000..a3c62d77 --- /dev/null +++ b/fade.scarlet @@ -0,0 +1,7 @@ +.fade + opacity 1 + transition opacity fade-speed ease + will-change opacity + +.fade-out + opacity 0 \ No newline at end of file diff --git a/main.go b/main.go index 21f60df3..fa4e6a95 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/layout" "github.com/animenotifier/notify.moe/middleware" + "github.com/animenotifier/notify.moe/pages/admin" "github.com/animenotifier/notify.moe/pages/airing" "github.com/animenotifier/notify.moe/pages/anime" "github.com/animenotifier/notify.moe/pages/awards" @@ -17,6 +18,7 @@ import ( "github.com/animenotifier/notify.moe/pages/posts" "github.com/animenotifier/notify.moe/pages/profile" "github.com/animenotifier/notify.moe/pages/search" + "github.com/animenotifier/notify.moe/pages/settings" "github.com/animenotifier/notify.moe/pages/threads" "github.com/animenotifier/notify.moe/pages/users" "github.com/animenotifier/notify.moe/utils" @@ -48,6 +50,8 @@ func main() { app.Ajax("/posts/:id", posts.Get) app.Ajax("/user/:nick", profile.Get) app.Ajax("/user/:nick/threads", profile.GetThreadsByUser) + app.Ajax("/settings", settings.Get) + app.Ajax("/admin", admin.Get) app.Ajax("/users", users.Get) app.Ajax("/airing", airing.Get) app.Ajax("/awards", awards.Get) diff --git a/middleware/Log.go b/middleware/Log.go index d5bc8abc..40a52e71 100644 --- a/middleware/Log.go +++ b/middleware/Log.go @@ -39,8 +39,9 @@ func Log() aero.Middleware { err.Error(http.StatusText(ctx.StatusCode), ctx.RealIP(), ctx.StatusCode, responseTimeString, ctx.URI()) } - // Notify us about long requests - if responseTime >= 200*time.Millisecond { + // Notify us about long requests. + // However ignore requests under /auth/ because those depend on 3rd party servers. + if responseTime >= 200*time.Millisecond && !strings.HasPrefix(ctx.URI(), "/auth/") { err.Error("Long response time", ctx.RealIP(), ctx.StatusCode, responseTimeString, ctx.URI()) } } diff --git a/mixins/Navigation.pixy b/mixins/Navigation.pixy index 6b148724..70cf58f4 100644 --- a/mixins/Navigation.pixy +++ b/mixins/Navigation.pixy @@ -2,7 +2,7 @@ component Navigation(user *arn.User) if user == nil LoggedOutMenu else - LoggedInMenu + LoggedInMenu(user) component LoggedOutMenu nav#navigation @@ -12,14 +12,21 @@ component LoggedOutMenu NavigationButton("Users", "/users", "globe") NavigationButton("Airing", "/airing", "rss") -component LoggedInMenu +component LoggedInMenu(user *arn.User) nav#navigation NavigationButton("Dash", "/", "inbox") NavigationButton("Anime", "/anime", "television") NavigationButton("Forum", "/forum", "comment") - NavigationButton("Users", "/users", "globe") NavigationButton("Airing", "/airing", "rss") - NavigationButtonNoAJAX("Logout", "/logout", "sign-out") + NavigationButton("Settings", "/settings", "cog") + + .extra-navigation + ExtraNavigationButton("Users", "/users", "globe") + + if user.Role == "admin" + ExtraNavigationButton("Admin", "/admin", "wrench") + + NavigationButtonNoAJAX("Logout", "/logout", "sign-out") component NavigationButton(name string, target string, icon string) a.navigation-link.ajax(href=target, aria-label=name) @@ -27,6 +34,12 @@ component NavigationButton(name string, target string, icon string) Icon(icon) span.navigation-text= name +component ExtraNavigationButton(name string, target string, icon string) + a.navigation-link.ajax(href=target, aria-label=name, title=name) + .navigation-button + Icon(icon) + span.navigation-text= name + component NavigationButtonNoAJAX(name string, target string, icon string) a.navigation-link(href=target, aria-label=name) .navigation-button diff --git a/pages/admin/admin.go b/pages/admin/admin.go new file mode 100644 index 00000000..9ef619e3 --- /dev/null +++ b/pages/admin/admin.go @@ -0,0 +1,18 @@ +package admin + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// Get admin page. +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil || user.Role != "admin" { + return ctx.Redirect("/") + } + + return ctx.HTML(components.Admin(user)) +} diff --git a/pages/admin/admin.pixy b/pages/admin/admin.pixy new file mode 100644 index 00000000..32111c8a --- /dev/null +++ b/pages/admin/admin.pixy @@ -0,0 +1,6 @@ +component Admin(user *arn.User) + h2.page-title Admin + table + tr + td Go version: + td= runtime.Version() \ No newline at end of file diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 4d613707..f27c26ca 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -127,9 +127,6 @@ component Anime(anime *arn.Anime) h3.anime-section-name Tracks p Coming soon. - h3.anime-section-name Artwork - p Coming soon. - h3.anime-section-name Reviews p Coming soon. diff --git a/pages/settings/settings.go b/pages/settings/settings.go new file mode 100644 index 00000000..e23ff35e --- /dev/null +++ b/pages/settings/settings.go @@ -0,0 +1,18 @@ +package settings + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// Get user settings page. +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Redirect("/") + } + + return ctx.HTML(components.Settings(user)) +} diff --git a/pages/settings/settings.pixy b/pages/settings/settings.pixy new file mode 100644 index 00000000..64bb800e --- /dev/null +++ b/pages/settings/settings.pixy @@ -0,0 +1,3 @@ +component Settings(user *arn.User) + h2.page-title Settings + input(type="text", value=user.Nick) \ No newline at end of file diff --git a/reset.scarlet b/reset.scarlet new file mode 100644 index 00000000..a93e2791 --- /dev/null +++ b/reset.scarlet @@ -0,0 +1,46 @@ +html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video, main + outline 0 + border 0 + font-size 100% + font inherit + vertical-align baseline + background transparent + +html + box-sizing border-box + +textarea + resize vertical + +article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section + display block + +body + line-height 1 + -webkit-font-smoothing antialiased + -moz-osx-font-smoothing grayscale + +ol, ul + list-style none + +blockquote, q + quotes none + +blockquote:before, blockquote:after, q:before, q:after + content '' + content none + +table + border-collapse collapse + border-spacing 0 + +audio, canvas, img, video, input, select + vertical-align middle + +:focus + outline 0 + +* + margin 0 + padding 0 + box-sizing inherit \ No newline at end of file diff --git a/styles/navigation.scarlet b/styles/navigation.scarlet index 652d86c6..eb6edde4 100644 --- a/styles/navigation.scarlet +++ b/styles/navigation.scarlet @@ -42,6 +42,16 @@ .navigation-text display none +.extra-navigation + display none + + .navigation-text + display none + + .navigation-button + .icon + margin-right 0 + > 330px .navigation-button font-size 1.3em @@ -58,6 +68,11 @@ .navigation-text display inline-block + + .extra-navigation + horizontal + justify-content flex-end + flex 1 < 400px height #navigation @@ -66,4 +81,7 @@ padding content-padding 0 #container - horizontal \ No newline at end of file + horizontal + + .extra-navigation + display none \ No newline at end of file