Skip to content

Commit 62afc0a

Browse files
GiteaBotyp05327
andauthored
Redirect to project again after editing it (#23326) (#23739)
Backport #23326 by @yp05327 A part of #22865 We have edit buttons in projects list page and project view page. But after user edit a project, it will always redirect to the projects list page. Co-authored-by: yp05327 <[email protected]>
1 parent b6a2323 commit 62afc0a

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

routers/web/org/projects.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func EditProject(ctx *context.Context) {
234234

235235
ctx.Data["title"] = p.Title
236236
ctx.Data["content"] = p.Description
237+
ctx.Data["redirect"] = ctx.FormString("redirect")
237238

238239
ctx.HTML(http.StatusOK, tplProjectsNew)
239240
}
@@ -274,7 +275,11 @@ func EditProjectPost(ctx *context.Context) {
274275
}
275276

276277
ctx.Flash.Success(ctx.Tr("repo.projects.edit_success", p.Title))
277-
ctx.Redirect(ctx.Repo.RepoLink + "/projects")
278+
if ctx.FormString("redirect") == "project" {
279+
ctx.Redirect(p.Link())
280+
} else {
281+
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects")
282+
}
278283
}
279284

280285
// ViewProject renders the project board for a project

routers/web/repo/projects.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func EditProject(ctx *context.Context) {
235235
ctx.Data["title"] = p.Title
236236
ctx.Data["content"] = p.Description
237237
ctx.Data["card_type"] = p.CardType
238+
ctx.Data["redirect"] = ctx.FormString("redirect")
238239

239240
ctx.HTML(http.StatusOK, tplProjectsNew)
240241
}
@@ -275,7 +276,11 @@ func EditProjectPost(ctx *context.Context) {
275276
}
276277

277278
ctx.Flash.Success(ctx.Tr("repo.projects.edit_success", p.Title))
278-
ctx.Redirect(ctx.Repo.RepoLink + "/projects")
279+
if ctx.FormString("redirect") == "project" {
280+
ctx.Redirect(p.Link())
281+
} else {
282+
ctx.Redirect(ctx.Repo.RepoLink + "/projects")
283+
}
279284
}
280285

281286
// ViewProject renders the project board for a project

templates/projects/new.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<form class="ui form grid" action="{{.Link}}" method="post">
2222
{{.CsrfTokenHtml}}
2323
<div class="eleven wide column">
24+
<input type="hidden" id="redirect" name="redirect" value="{{.redirect}}">
2425
<div class="field {{if .Err_Title}}error{{end}}">
2526
<label>{{.locale.Tr "repo.projects.title"}}</label>
2627
<input name="title" placeholder="{{.locale.Tr "repo.projects.title"}}" value="{{.title}}" autofocus required>

templates/projects/view.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{{if $.CanWriteProjects}}
4747
<div class="column right aligned">
4848
<div class="ui compact right small menu">
49-
<a class="item" href="{{$.Link}}/edit" data-id={{$.Project.ID}} data-title={{$.Project.Title}}>
49+
<a class="item" href="{{$.Link}}/edit?redirect=project" data-id={{$.Project.ID}} data-title={{$.Project.Title}}>
5050
{{svg "octicon-pencil"}}
5151
<span class="gt-mx-3">{{$.locale.Tr "repo.issues.label_edit"}}</span>
5252
</a>

templates/repo/projects/new.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<form class="ui form grid" action="{{.Link}}" method="post">
2525
{{.CsrfTokenHtml}}
2626
<div class="eleven wide column">
27+
<input type="hidden" id="redirect" name="redirect" value="{{.redirect}}">
2728
<div class="field {{if .Err_Title}}error{{end}}">
2829
<label>{{.locale.Tr "repo.projects.title"}}</label>
2930
<input name="title" placeholder="{{.locale.Tr "repo.projects.title"}}" value="{{.title}}" autofocus required>

templates/repo/projects/view.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
{{if and (or $.CanWriteIssues $.CanWritePulls) (not $.Repository.IsArchived)}}
5151
<div class="column right aligned">
5252
<div class="ui compact right small menu">
53-
<a class="item" href="{{$.RepoLink}}/projects/{{.Project.ID}}/edit" data-id={{$.Project.ID}} data-title={{$.Project.Title}}>
53+
<a class="item" href="{{$.RepoLink}}/projects/{{.Project.ID}}/edit?redirect=project" data-id={{$.Project.ID}} data-title={{$.Project.Title}}>
5454
{{svg "octicon-pencil"}}
5555
<span class="gt-mx-3">{{$.locale.Tr "repo.issues.label_edit"}}</span>
5656
</a>

0 commit comments

Comments
 (0)