From 4b7cb813e613268dbdd3c5ed21456341f1421097 Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 23 Mar 2022 01:41:12 +0000 Subject: [PATCH] Use the new/choose link for New Issue on project page (#19172) (#19176) Backport #19172 Extend issues/new/choose to pass the project id and change New Issue link on project page to use new/choose Fix #19170 Signed-off-by: Andrew Thornton Co-authored-by: wxiaoguang Co-authored-by: wxiaoguang --- routers/web/repo/issue.go | 11 +++++++++-- templates/repo/issue/choose.tmpl | 4 ++-- templates/repo/projects/view.tmpl | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 8c707e1678..bb24d0462c 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -843,12 +843,19 @@ func NewIssue(ctx *context.Context) { func NewIssueChooseTemplate(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true - ctx.Data["milestone"] = ctx.FormInt64("milestone") issueTemplates := ctx.IssueTemplatesFromDefaultBranch() - ctx.Data["NewIssueChooseTemplate"] = len(issueTemplates) > 0 ctx.Data["IssueTemplates"] = issueTemplates + if len(issueTemplates) == 0 { + // The "issues/new" and "issues/new/choose" share the same query parameters "project" and "milestone", if no template here, just redirect to the "issues/new" page with these parameters. + ctx.Redirect(fmt.Sprintf("%s/issues/new?%s", ctx.Repo.Repository.HTMLURL(), ctx.Req.URL.RawQuery), http.StatusSeeOther) + return + } + + ctx.Data["milestone"] = ctx.FormInt64("milestone") + ctx.Data["project"] = ctx.FormInt64("project") + ctx.HTML(http.StatusOK, tplIssueChoose) } diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl index 0cec1ef63c..4a26e4f689 100644 --- a/templates/repo/issue/choose.tmpl +++ b/templates/repo/issue/choose.tmpl @@ -14,7 +14,7 @@
{{.About | RenderEmojiPlain}} @@ -26,7 +26,7 @@
{{.i18n.Tr "repo.issues.choose.blank_about"}} diff --git a/templates/repo/projects/view.tmpl b/templates/repo/projects/view.tmpl index 1db52a3d79..c823c29c62 100644 --- a/templates/repo/projects/view.tmpl +++ b/templates/repo/projects/view.tmpl @@ -8,7 +8,7 @@
{{if and .CanWriteProjects (not .Repository.IsArchived)}} - {{.i18n.Tr "repo.issues.new"}} + {{.i18n.Tr "repo.issues.new"}} {{.i18n.Tr "new_project_board"}} {{end}}