fix sorting

This commit is contained in:
wxiaoguang 2024-05-06 12:09:02 +08:00
parent ca73f6c78e
commit f586577008
2 changed files with 9 additions and 16 deletions

View File

@ -4,7 +4,6 @@
title: To Do
creator_id: 2
default: true
sorting: 0
created_unix: 1588117528
updated_unix: 1588117528
@ -13,7 +12,6 @@
project_id: 1
title: In Progress
creator_id: 2
sorting: 1
created_unix: 1588117528
updated_unix: 1588117528
@ -22,7 +20,6 @@
project_id: 1
title: Done
creator_id: 2
sorting: 2
created_unix: 1588117528
updated_unix: 1588117528
@ -31,7 +28,6 @@
project_id: 4
title: Done
creator_id: 2
sorting: 0
created_unix: 1588117528
updated_unix: 1588117528
@ -50,7 +46,6 @@
title: Backlog
creator_id: 2
default: true
sorting: 1
created_unix: 1588117528
updated_unix: 1588117528
@ -69,7 +64,6 @@
title: Backlog
creator_id: 2
default: true
sorting: 0
created_unix: 1588117528
updated_unix: 1588117528
@ -79,6 +73,5 @@
title: Uncategorized
creator_id: 2
default: true
sorting: 1
created_unix: 1588117528
updated_unix: 1588117528

View File

@ -5,12 +5,12 @@ package issues
import (
"context"
"database/sql"
"fmt"
"code.gitea.io/gitea/models/db"
project_model "code.gitea.io/gitea/models/project"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/util"
)
// LoadProject load the project the issue was assigned to
@ -132,22 +132,22 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
return nil
}
var maxSorting sql.NullInt64
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
res := struct {
MaxSorting int64
IssueCount int64
}{}
if _, err := db.GetEngine(ctx).Select("max(sorting) as MaxSorting, count(*) as IssueCount").Table("project_issue").
Where("project_id=?", newProjectID).
And("project_board_id=?", newColumnID).
Get(&maxSorting); err != nil {
Get(&res); err != nil {
return err
}
if maxSorting.Valid {
maxSorting.Int64++
}
newSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0)
return db.Insert(ctx, &project_model.ProjectIssue{
IssueID: issue.ID,
ProjectID: newProjectID,
ProjectBoardID: newColumnID,
Sorting: maxSorting.Int64,
Sorting: newSorting,
})
})
}