Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ func NewIssue(ctx *context.Context) {
ctx.Data["Project"] = project
}

if ctx.FormBool("redirect_on_project") {
ctx.Data["redirect_on_project"] = true
}
}

RetrieveRepoMetas(ctx, ctx.Repo.Repository, false)
Expand Down Expand Up @@ -990,7 +993,11 @@ func NewIssuePost(ctx *context.Context) {
}

log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + fmt.Sprint(issue.Index))
if ctx.FormBool("redirect_on_project") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is necessary to introduce redirect_on_project? Can we just check if form.ProjectID > 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible, when form is submitted we can't know if user click on "new issue" button from project view, maybe he creates issue from issue list view.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On which page besides projects/view.tmpl the new issue link uses project_id=xxx in query string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one, but when you submit the new issue form with a project, the project_id is also filled ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't read the source code carefully, just a feeling and curiosity: if there is no project_id, how can the newly created issue be added into current project?

Copy link
Contributor Author

@romdum romdum Oct 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is two cases :

  • First, you want to create an issue from button on list issue view, after on the form you can assign issue to a project. In this case, we don't want to redirect on the project but the project_id is filled.
  • Second, you want to create an issue from the button on project view, you are redirected to the new issue form with the project automatically selected. In this case we want to redirect on the project when the form is submitted

If the project is not selected when the form is submitted the user is redirected to issue view

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first case, the project_id is in POST body. So ctx.Req.URL.Query().Get("project_id") will work like redirect_on_project, Query().Get("project_id") only presents when the issue is created from the page view button.

For me, I prefer to use use existing and simple mechanism as long as it doesn't introduce ambiguity.

Copy link
Contributor Author

@romdum romdum Oct 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I didn't understand what do you mean, sorry. So I removed redirect_on_project in URL and I used ctx.Req.URL.Query().Get("project") to know if we should redirect on project page or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't saying clearly. 😂

ctx.Redirect(ctx.Repo.RepoLink + "/projects/" + fmt.Sprint(form.ProjectID))
} else {
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + fmt.Sprint(issue.Index))
}
}

// commentTag returns the CommentTag for a comment in/with the given repo, poster and issue
Expand Down
1 change: 1 addition & 0 deletions templates/repo/issue/new_form.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,6 @@
{{end}}
</div>
</div>
<input type="hidden" name="redirect_on_project" value="{{.redirect_on_project}}">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can call this variable redirection_after_creation (now we only have 2 choices, empty or project), then developers in future will have a chance to introduce more redirection pages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good idea, it's done 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can call this variable redirection_after_creation (now we only have 2 choices, empty or project), then developers in future will have a chance to introduce more redirection pages.

I think it can be even shorter, what do you think about redirection_after_creation?

</div>
</form>
2 changes: 1 addition & 1 deletion templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<div class="column right aligned">
{{if and .CanWriteProjects (not .Repository.IsArchived) .PageIsProjects}}
<a class="ui green button show-modal item" href="{{$.RepoLink}}/issues/new?project={{$.Project.ID}}">{{.i18n.Tr "repo.issues.new"}}</a>
<a class="ui green button show-modal item" href="{{$.RepoLink}}/issues/new?project={{$.Project.ID}}&redirect_on_project=true">{{.i18n.Tr "repo.issues.new"}}</a>
<a class="ui green button show-modal item" data-modal="#new-board-item">{{.i18n.Tr "new_project_board"}}</a>
{{end}}
<div class="ui small modal new-board-modal" id="new-board-item">
Expand Down