diff --git a/modules/forms/poll_form.go b/modules/forms/poll_form.go index 15ecc8a97..00926382a 100644 --- a/modules/forms/poll_form.go +++ b/modules/forms/poll_form.go @@ -1,8 +1,12 @@ -package auth // not sure why this is in package auth? +package forms import ( - "gitea.com/macaron/binding" - "gitea.com/macaron/macaron" + "net/http" + + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/web/middleware" + + "gitea.com/go-chi/binding" ) // Form for creating a poll @@ -11,7 +15,8 @@ type CreatePollForm struct { Description string } -// Validate validates the form fields -func (f *CreatePollForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { - return validate(errs, ctx.Data, f, ctx.Locale) +// Validate the form fields +func (f *CreatePollForm) Validate(req *http.Request, errs binding.Errors) binding.Errors { + ctx := context.GetContext(req) + return middleware.Validate(errs, ctx.Data, f, ctx.Locale) } diff --git a/routers/repo/poll.go b/routers/repo/poll.go index 2a3961e36..cca4d9326 100644 --- a/routers/repo/poll.go +++ b/routers/repo/poll.go @@ -6,10 +6,11 @@ package repo import ( "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/forms" "code.gitea.io/gitea/modules/markup/markdown" + "code.gitea.io/gitea/modules/web" //"code.gitea.io/gitea/modules/setting" //"code.gitea.io/gitea/modules/timeutil" //"time" @@ -57,7 +58,8 @@ func NewPoll(ctx *context.Context) { } // NewPollPost processes the "new poll" form and redirects -func NewPollPost(ctx *context.Context, form auth.CreatePollForm) { +func NewPollPost(ctx *context.Context) { + form := web.GetForm(ctx).(*forms.CreatePollForm) ctx.Data["Title"] = ctx.Tr("repo.polls.new") ctx.Data["PageIsPolls"] = true if ctx.HasError() { @@ -123,7 +125,8 @@ func EditPoll(ctx *context.Context) { } // EditPollPost response for edting poll -func EditPollPost(ctx *context.Context, form auth.CreatePollForm) { +func EditPollPost(ctx *context.Context) { + form := web.GetForm(ctx).(*forms.CreatePollForm) ctx.Data["Title"] = ctx.Tr("repo.polls.edit") ctx.Data["PageIsPolls"] = true ctx.Data["PageIsEditPoll"] = true diff --git a/routers/routes/web.go b/routers/routes/web.go index 39d2d7bef..906faf743 100644 --- a/routers/routes/web.go +++ b/routers/routes/web.go @@ -722,6 +722,10 @@ func RegisterRoutes(m *web.Route) { m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists). Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff). Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(auth.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost) + m.Group("/polls", func() { + m.Get("", repo.IndexPolls) + m.Get("/{id}", repo.ViewPoll) + }, context.RepoAssignment, context.RepoRef()) }, context.RepoAssignment, context.UnitTypes()) // Grouping for those endpoints that do require authentication @@ -800,6 +804,17 @@ func RegisterRoutes(m *web.Route) { m.Post("/{index}/target_branch", repo.UpdatePullRequestTarget) }, context.RepoMustNotBeArchived()) + m.Group("/polls", func() { + m.Combo("/new"). + Get(repo.NewPoll). + Post(bindIgnErr(auth.CreatePollForm{}), repo.NewPollPost) + m.Get("/{id}/edit", repo.EditPoll) + m.Post("/{id}/edit", bindIgnErr(auth.CreatePollForm{}), repo.EditPollPost) + m.Post("/{id}/delete", repo.DeletePoll) + m.Post("/{id}/judgments", repo.EmitJudgment) + //m.Delete("/{id}/judgments", repo.DeleteJudgment) + }, context.RepoMustNotBeArchived()) + m.Group("", func() { m.Group("", func() { m.Combo("/_edit/*").Get(repo.EditFile). diff --git a/web_src/less/_poll.less b/web_src/less/_poll.less index 9b2a48e5a..25143ac4e 100644 --- a/web_src/less/_poll.less +++ b/web_src/less/_poll.less @@ -72,6 +72,7 @@ Research notes: display: inline-block; left: -9px; opacity: 1.0; + padding-left: 1em; } .judgment-forms { @@ -137,12 +138,13 @@ Research notes: content: "×"; pointer-events: none; position: absolute; - top: 0.05em; - left: 0.05em; + top: 0; + left: 0; color: darkred; opacity: 0.8; font-size: 3em; z-index: 3; + line-height: 62%; } .judgment-form input.emote:hover,