Skip to content

Commit f586577

Browse files
committed
fix sorting
1 parent ca73f6c commit f586577

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

models/fixtures/project_board.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
title: To Do
55
creator_id: 2
66
default: true
7-
sorting: 0
87
created_unix: 1588117528
98
updated_unix: 1588117528
109

@@ -13,7 +12,6 @@
1312
project_id: 1
1413
title: In Progress
1514
creator_id: 2
16-
sorting: 1
1715
created_unix: 1588117528
1816
updated_unix: 1588117528
1917

@@ -22,7 +20,6 @@
2220
project_id: 1
2321
title: Done
2422
creator_id: 2
25-
sorting: 2
2623
created_unix: 1588117528
2724
updated_unix: 1588117528
2825

@@ -31,7 +28,6 @@
3128
project_id: 4
3229
title: Done
3330
creator_id: 2
34-
sorting: 0
3531
created_unix: 1588117528
3632
updated_unix: 1588117528
3733

@@ -50,7 +46,6 @@
5046
title: Backlog
5147
creator_id: 2
5248
default: true
53-
sorting: 1
5449
created_unix: 1588117528
5550
updated_unix: 1588117528
5651

@@ -69,7 +64,6 @@
6964
title: Backlog
7065
creator_id: 2
7166
default: true
72-
sorting: 0
7367
created_unix: 1588117528
7468
updated_unix: 1588117528
7569

@@ -79,6 +73,5 @@
7973
title: Uncategorized
8074
creator_id: 2
8175
default: true
82-
sorting: 1
8376
created_unix: 1588117528
8477
updated_unix: 1588117528

models/issues/issue_project.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package issues
55

66
import (
77
"context"
8-
"database/sql"
98
"fmt"
109

1110
"code.gitea.io/gitea/models/db"
1211
project_model "code.gitea.io/gitea/models/project"
1312
user_model "code.gitea.io/gitea/models/user"
13+
"code.gitea.io/gitea/modules/util"
1414
)
1515

1616
// LoadProject load the project the issue was assigned to
@@ -132,22 +132,22 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
132132
return nil
133133
}
134134

135-
var maxSorting sql.NullInt64
136-
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
135+
res := struct {
136+
MaxSorting int64
137+
IssueCount int64
138+
}{}
139+
if _, err := db.GetEngine(ctx).Select("max(sorting) as MaxSorting, count(*) as IssueCount").Table("project_issue").
137140
Where("project_id=?", newProjectID).
138141
And("project_board_id=?", newColumnID).
139-
Get(&maxSorting); err != nil {
142+
Get(&res); err != nil {
140143
return err
141144
}
142-
if maxSorting.Valid {
143-
maxSorting.Int64++
144-
}
145-
145+
newSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0)
146146
return db.Insert(ctx, &project_model.ProjectIssue{
147147
IssueID: issue.ID,
148148
ProjectID: newProjectID,
149149
ProjectBoardID: newColumnID,
150-
Sorting: maxSorting.Int64,
150+
Sorting: newSorting,
151151
})
152152
})
153153
}

0 commit comments

Comments
 (0)