From 85c796b51dbde9ad667240b4ff9629d189954ed1 Mon Sep 17 00:00:00 2001 From: milovann Date: Sat, 6 Apr 2024 19:37:39 +0200 Subject: [PATCH] [FORDJ] Add Playground --- routers/web/playground.go | 25 +++++++++++++++++++++++++ routers/web/web.go | 1 + templates/base/head_navbar.tmpl | 1 + templates/playground/playground.tmpl | 7 +++++++ 4 files changed, 34 insertions(+) create mode 100644 routers/web/playground.go create mode 100644 templates/playground/playground.tmpl diff --git a/routers/web/playground.go b/routers/web/playground.go new file mode 100644 index 0000000000..2905d24204 --- /dev/null +++ b/routers/web/playground.go @@ -0,0 +1,25 @@ +// Copyright 2024 Milovann Yanatchkov +// SPDX-License-Identifier: MIT + +package web + +import ( + "net/http" + + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/services/context" +) + +const ( + // tplPlayground home page template + tplPlayground base.TplName = "playground/playground" +) + +func Playground(ctx *context.Context) { + if ctx.IsSigned { + ctx.Data["UserName"] = ctx.Doer.DisplayName() + } + + ctx.Data["PageIsPlayground"] = true + ctx.HTML(http.StatusOK, tplPlayground) +} diff --git a/routers/web/web.go b/routers/web/web.go index 0ab25fd7e3..80a711c561 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -432,6 +432,7 @@ func registerRoutes(m *web.Route) { // Especially some AJAX requests, we can reduce middleware number to improve performance. m.Get("/", Home) + m.Get("/playground", Playground) m.Get("/sitemap.xml", sitemapEnabled, ignExploreSignIn, HomeSitemap) m.Group("/.well-known", func() { m.Get("/openid-configuration", auth.OIDCWellKnown) diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 068271bbe9..a326f7b9a2 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -39,6 +39,7 @@ {{end}} {{end}} {{ctx.Locale.Tr "explore"}} + Playground {{else if .IsLandingPageOrganizations}} {{ctx.Locale.Tr "explore"}} {{else}} diff --git a/templates/playground/playground.tmpl b/templates/playground/playground.tmpl new file mode 100644 index 0000000000..183e31d213 --- /dev/null +++ b/templates/playground/playground.tmpl @@ -0,0 +1,7 @@ +{{template "base/head" .}} +{{if .IsSigned}} +User : {{.UserName}} +{{else}} +User : None +{{end}} +{{template "base/footer" .}}