aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorAnbraten <anton@ju60.de>2021-12-08 07:57:18 +0100
committerGitHub <noreply@github.com>2021-12-08 14:57:18 +0800
commit0ff18a808c7c14d42ea2325b5d9623f7a30d9107 (patch)
tree6271529776d63a8c741bc3159cd5cfacd5539be1 /routers
parent4cbe792562e69e76df07cfa4aa9c0c254b2dec7c (diff)
downloadgitea-0ff18a808c7c14d42ea2325b5d9623f7a30d9107.tar.gz
gitea-0ff18a808c7c14d42ea2325b5d9623f7a30d9107.zip
Support sorting for project board issuses (#17152)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/projects.go56
-rw-r--r--routers/web/web.go2
2 files changed, 39 insertions, 19 deletions
diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go
index c237544385..a8b2a7a5c4 100644
--- a/routers/web/repo/projects.go
+++ b/routers/web/repo/projects.go
@@ -5,6 +5,7 @@
package repo
import (
+ "encoding/json"
"fmt"
"net/http"
"net/url"
@@ -299,7 +300,6 @@ func ViewProject(ctx *context.Context) {
ctx.ServerError("LoadIssuesOfBoards", err)
return
}
- ctx.Data["Issues"] = issueList
linkedPrsMap := make(map[int64][]*models.Issue)
for _, issue := range issueList {
@@ -547,9 +547,8 @@ func SetDefaultProjectBoard(ctx *context.Context) {
})
}
-// MoveIssueAcrossBoards move a card from one board to another in a project
-func MoveIssueAcrossBoards(ctx *context.Context) {
-
+// MoveIssues moves or keeps issues in a column and sorts them inside that column
+func MoveIssues(ctx *context.Context) {
if ctx.User == nil {
ctx.JSON(http.StatusForbidden, map[string]string{
"message": "Only signed in users are allowed to perform this action.",
@@ -564,59 +563,80 @@ func MoveIssueAcrossBoards(ctx *context.Context) {
return
}
- p, err := models.GetProjectByID(ctx.ParamsInt64(":id"))
+ project, err := models.GetProjectByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrProjectNotExist(err) {
- ctx.NotFound("", nil)
+ ctx.NotFound("ProjectNotExist", nil)
} else {
ctx.ServerError("GetProjectByID", err)
}
return
}
- if p.RepoID != ctx.Repo.Repository.ID {
- ctx.NotFound("", nil)
+ if project.RepoID != ctx.Repo.Repository.ID {
+ ctx.NotFound("InvalidRepoID", nil)
return
}
var board *models.ProjectBoard
if ctx.ParamsInt64(":boardID") == 0 {
-
board = &models.ProjectBoard{
ID: 0,
- ProjectID: 0,
+ ProjectID: project.ID,
Title: ctx.Tr("repo.projects.type.uncategorized"),
}
-
} else {
+ // column
board, err = models.GetProjectBoard(ctx.ParamsInt64(":boardID"))
if err != nil {
if models.IsErrProjectBoardNotExist(err) {
- ctx.NotFound("", nil)
+ ctx.NotFound("ProjectBoardNotExist", nil)
} else {
ctx.ServerError("GetProjectBoard", err)
}
return
}
- if board.ProjectID != p.ID {
- ctx.NotFound("", nil)
+ if board.ProjectID != project.ID {
+ ctx.NotFound("BoardNotInProject", nil)
return
}
}
- issue, err := models.GetIssueByID(ctx.ParamsInt64(":index"))
+ type movedIssuesForm struct {
+ Issues []struct {
+ IssueID int64 `json:"issueID"`
+ Sorting int64 `json:"sorting"`
+ } `json:"issues"`
+ }
+
+ form := &movedIssuesForm{}
+ if err = json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
+ ctx.ServerError("DecodeMovedIssuesForm", err)
+ }
+
+ issueIDs := make([]int64, 0, len(form.Issues))
+ sortedIssueIDs := make(map[int64]int64)
+ for _, issue := range form.Issues {
+ issueIDs = append(issueIDs, issue.IssueID)
+ sortedIssueIDs[issue.Sorting] = issue.IssueID
+ }
+ movedIssues, err := models.GetIssuesByIDs(issueIDs)
if err != nil {
if models.IsErrIssueNotExist(err) {
- ctx.NotFound("", nil)
+ ctx.NotFound("IssueNotExisting", nil)
} else {
ctx.ServerError("GetIssueByID", err)
}
+ return
+ }
+ if len(movedIssues) != len(form.Issues) {
+ ctx.ServerError("IssuesNotFound", err)
return
}
- if err := models.MoveIssueAcrossProjectBoards(issue, board); err != nil {
- ctx.ServerError("MoveIssueAcrossProjectBoards", err)
+ if err = models.MoveIssuesOnProjectBoard(board, sortedIssueIDs); err != nil {
+ ctx.ServerError("MoveIssuesOnProjectBoard", err)
return
}
diff --git a/routers/web/web.go b/routers/web/web.go
index c52d3483f0..0d4d3bd90f 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -897,7 +897,7 @@ func RegisterRoutes(m *web.Route) {
m.Delete("", repo.DeleteProjectBoard)
m.Post("/default", repo.SetDefaultProjectBoard)
- m.Post("/{index}", repo.MoveIssueAcrossBoards)
+ m.Post("/move", repo.MoveIssues)
})
})
}, reqRepoProjectsWriter, context.RepoMustNotBeArchived())