Skip to content

Commit bb95eca

Browse files
committed
support sorting for project board issuses
1 parent 6fb7fb6 commit bb95eca

File tree

8 files changed

+51
-20
lines changed

8 files changed

+51
-20
lines changed

models/issue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,8 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
11781178
"ELSE issue.deadline_unix END DESC")
11791179
case "priorityrepo":
11801180
sess.OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(priorityRepoID, 10) + " THEN 1 ELSE 2 END, issue.created_unix DESC")
1181+
case "project-sorting":
1182+
sess.Asc("project_issue.sorting")
11811183
default:
11821184
sess.Desc("issue.created_unix")
11831185
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ var migrations = []Migration{
344344
NewMigration("Add Branch Protection Unprotected Files Column", addBranchProtectionUnprotectedFilesColumn),
345345
// v195 -> v196
346346
NewMigration("Add table commit_status_index", addTableCommitStatusIndex),
347+
// v196 -> v197
348+
NewMigration("Add Sorting to ProjectIssue table", addProjectIssueSorting),
347349
}
348350

349351
// GetCurrentDBVersion returns the current db version

models/migrations/v196.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func addProjectIssueSorting(x *xorm.Engine) error {
12+
// ProjectIssue saves relation from issue to a project
13+
type ProjectIssue struct {
14+
Sorting int64 `xorm:"NOT NULL DEFAULT 0"`
15+
}
16+
17+
return x.Sync2(new(ProjectIssue))
18+
}

models/project_board.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ func (b *ProjectBoard) LoadIssues() (IssueList, error) {
250250
issues, err := Issues(&IssuesOptions{
251251
ProjectBoardID: b.ID,
252252
ProjectID: b.ProjectID,
253+
SortType: "project-sorting",
253254
})
254255
if err != nil {
255256
return nil, err
@@ -261,6 +262,7 @@ func (b *ProjectBoard) LoadIssues() (IssueList, error) {
261262
issues, err := Issues(&IssuesOptions{
262263
ProjectBoardID: -1, // Issues without ProjectBoardID
263264
ProjectID: b.ProjectID,
265+
SortType: "project-sorting",
264266
})
265267
if err != nil {
266268
return nil, err

models/project_issue.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ProjectIssue struct {
2020

2121
// If 0, then it has not been added to a specific board in the project
2222
ProjectBoardID int64 `xorm:"INDEX"`
23+
Sorting int64 `xorm:"NOT NULL DEFAULT 0"`
2324
}
2425

2526
func init() {
@@ -182,7 +183,7 @@ func addUpdateIssueProject(e *xorm.Session, issue *Issue, doer *User, newProject
182183
// |__/
183184

184185
// MoveIssueAcrossProjectBoards move a card from one board to another
185-
func MoveIssueAcrossProjectBoards(issue *Issue, board *ProjectBoard) error {
186+
func MoveIssueAcrossProjectBoards(issue *Issue, board *ProjectBoard, sorting int64) error {
186187
sess := db.NewSession(db.DefaultContext)
187188
defer sess.Close()
188189
if err := sess.Begin(); err != nil {
@@ -200,14 +201,17 @@ func MoveIssueAcrossProjectBoards(issue *Issue, board *ProjectBoard) error {
200201
}
201202

202203
pis.ProjectBoardID = board.ID
203-
if _, err := sess.ID(pis.ID).Cols("project_board_id").Update(&pis); err != nil {
204+
pis.Sorting = sorting
205+
if _, err := sess.ID(pis.ID).Cols("project_board_id").Cols("sorting").Update(&pis); err != nil {
204206
return err
205207
}
206208

209+
fmt.Println("sorting", sorting)
210+
207211
return sess.Commit()
208212
}
209213

210214
func (pb *ProjectBoard) removeIssues(e db.Engine) error {
211-
_, err := e.Exec("UPDATE `project_issue` SET project_board_id = 0 WHERE project_board_id = ? ", pb.ID)
215+
_, err := e.Exec("UPDATE `project_issue` SET project_board_id = 0, sorting = 0 WHERE project_board_id = ? ", pb.ID)
212216
return err
213217
}

routers/web/repo/projects.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ func ViewProject(ctx *context.Context) {
299299
ctx.ServerError("LoadIssuesOfBoards", err)
300300
return
301301
}
302-
ctx.Data["Issues"] = issueList
303302

304303
linkedPrsMap := make(map[int64][]*models.Issue)
305304
for _, issue := range issueList {
@@ -587,6 +586,7 @@ func MoveIssueAcrossBoards(ctx *context.Context) {
587586
}
588587

589588
} else {
589+
// column
590590
board, err = models.GetProjectBoard(ctx.ParamsInt64(":boardID"))
591591
if err != nil {
592592
if models.IsErrProjectBoardNotExist(err) {
@@ -602,7 +602,7 @@ func MoveIssueAcrossBoards(ctx *context.Context) {
602602
}
603603
}
604604

605-
issue, err := models.GetIssueByID(ctx.ParamsInt64(":index"))
605+
issue, err := models.GetIssueByID(ctx.ParamsInt64(":issueID"))
606606
if err != nil {
607607
if models.IsErrIssueNotExist(err) {
608608
ctx.NotFound("", nil)
@@ -613,7 +613,7 @@ func MoveIssueAcrossBoards(ctx *context.Context) {
613613
return
614614
}
615615

616-
if err := models.MoveIssueAcrossProjectBoards(issue, board); err != nil {
616+
if err := models.MoveIssueAcrossProjectBoards(issue, board, ctx.ParamsInt64(":sorting")); err != nil {
617617
ctx.ServerError("MoveIssueAcrossProjectBoards", err)
618618
return
619619
}

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ func RegisterRoutes(m *web.Route) {
872872
m.Delete("", repo.DeleteProjectBoard)
873873
m.Post("/default", repo.SetDefaultProjectBoard)
874874

875-
m.Post("/{index}", repo.MoveIssueAcrossBoards)
875+
m.Post("/{issueID}/{sorting}", repo.MoveIssueAcrossBoards)
876876
})
877877
})
878878
}, reqRepoProjectsWriter, context.RepoMustNotBeArchived())

web_src/js/features/projects.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,29 @@ export default async function initProject() {
3737
},
3838
);
3939

40+
const moveIssue = (e) => {
41+
$.ajax(`${e.to.dataset.url}/${e.item.dataset.issue}/${e.newIndex}`, {
42+
headers: {
43+
'X-Csrf-Token': csrf,
44+
'X-Remote': true,
45+
},
46+
contentType: 'application/json',
47+
type: 'POST',
48+
error: () => {
49+
e.from.insertBefore(e.item, e.from.children[e.oldIndex]);
50+
},
51+
});
52+
};
53+
4054
for (const column of boardColumns) {
4155
new Sortable(
4256
column.getElementsByClassName('board')[0],
4357
{
4458
group: 'shared',
4559
animation: 150,
4660
ghostClass: 'card-ghost',
47-
onAdd: (e) => {
48-
$.ajax(`${e.to.dataset.url}/${e.item.dataset.issue}`, {
49-
headers: {
50-
'X-Csrf-Token': csrf,
51-
'X-Remote': true,
52-
},
53-
contentType: 'application/json',
54-
type: 'POST',
55-
error: () => {
56-
e.from.insertBefore(e.item, e.from.children[e.oldIndex]);
57-
},
58-
});
59-
},
61+
onAdd: moveIssue,
62+
onUpdate: moveIssue,
6063
},
6164
);
6265
}

0 commit comments

Comments
 (0)