diff options
Diffstat (limited to 'models/project_board.go')
-rw-r--r-- | models/project_board.go | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/models/project_board.go b/models/project_board.go index a9c0b3ed8b..e56bf8f819 100644 --- a/models/project_board.go +++ b/models/project_board.go @@ -36,6 +36,7 @@ type ProjectBoard struct { ID int64 `xorm:"pk autoincr"` Title string Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board + Sorting int8 `xorm:"DEFAULT 0"` ProjectID int64 `xorm:"INDEX NOT NULL"` CreatorID int64 `xorm:"NOT NULL"` @@ -157,15 +158,24 @@ func getProjectBoard(e Engine, boardID int64) (*ProjectBoard, error) { return board, nil } -// UpdateProjectBoard updates the title of a project board +// UpdateProjectBoard updates a project board func UpdateProjectBoard(board *ProjectBoard) error { return updateProjectBoard(x, board) } func updateProjectBoard(e Engine, board *ProjectBoard) error { - _, err := e.ID(board.ID).Cols( - "title", - ).Update(board) + var fieldToUpdate []string + + if board.Sorting != 0 { + fieldToUpdate = append(fieldToUpdate, "sorting") + } + + if board.Title != "" { + fieldToUpdate = append(fieldToUpdate, "title") + } + + _, err := e.ID(board.ID).Cols(fieldToUpdate...).Update(board) + return err } @@ -178,7 +188,7 @@ func GetProjectBoards(projectID int64) (ProjectBoardList, error) { func getProjectBoards(e Engine, projectID int64) ([]*ProjectBoard, error) { var boards = make([]*ProjectBoard, 0, 5) - if err := e.Where("project_id=? AND `default`=?", projectID, false).Find(&boards); err != nil { + if err := e.Where("project_id=? AND `default`=?", projectID, false).OrderBy("Sorting").Find(&boards); err != nil { return nil, err } @@ -277,3 +287,17 @@ func (bs ProjectBoardList) LoadIssues() (IssueList, error) { } return issues, nil } + +// UpdateProjectBoardSorting update project board sorting +func UpdateProjectBoardSorting(bs ProjectBoardList) error { + for i := range bs { + _, err := x.ID(bs[i].ID).Cols( + "sorting", + ).Update(bs[i]) + + if err != nil { + return err + } + } + return nil +} |