Skip to content

Commit e52ac62

Browse files
authored
Redirect to project again after editing it (#23326)
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.
1 parent 8cadd51 commit e52ac62

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
@@ -233,6 +233,7 @@ func EditProject(ctx *context.Context) {
233233

234234
ctx.Data["title"] = p.Title
235235
ctx.Data["content"] = p.Description
236+
ctx.Data["redirect"] = ctx.FormString("redirect")
236237

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

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

279284
// 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 or $.CanWriteIssues $.CanWritePulls}}
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)