-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add project column choice option on issue sidebar #30617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
6524bd5
dd52d2e
64701bd
092c46d
9207a4e
9b2b4da
85b93b2
aa91afb
8a98856
7e1b786
ae9d629
a824db0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,14 @@ import ( | |
|
||
// ProjectIssue saves relation from issue to a project | ||
type ProjectIssue struct { //revive:disable-line:exported | ||
ID int64 `xorm:"pk autoincr"` | ||
IssueID int64 `xorm:"INDEX"` | ||
ProjectID int64 `xorm:"INDEX"` | ||
ID int64 `xorm:"pk autoincr"` | ||
IssueID int64 `xorm:"INDEX"` | ||
ProjectID int64 `xorm:"INDEX"` | ||
Project *Project `xorm:"-"` | ||
|
||
// ProjectColumnID should not be zero since 1.22. If it's zero, the issue will not be displayed on UI and it might result in errors. | ||
ProjectColumnID int64 `xorm:"'project_board_id' INDEX"` | ||
ProjectColumnID int64 `xorm:"'project_board_id' INDEX"` | ||
ProjectColumn *Column `xorm:"-"` | ||
|
||
// the sorting order on the column | ||
Sorting int64 `xorm:"NOT NULL DEFAULT 0"` | ||
|
@@ -34,6 +36,50 @@ func deleteProjectIssuesByProjectID(ctx context.Context, projectID int64) error | |
return err | ||
} | ||
|
||
type ErrProjectIssueNotExist struct { | ||
IssueID int64 | ||
} | ||
|
||
func (e ErrProjectIssueNotExist) Error() string { | ||
return fmt.Sprintf("can't find project issue [issue_id: %d]", e.IssueID) | ||
} | ||
|
||
func IsErrProjectIssueNotExist(e error) bool { | ||
_, ok := e.(ErrProjectIssueNotExist) | ||
return ok | ||
} | ||
|
||
func GetProjectIssueByIssueID(ctx context.Context, issueID int64) (*ProjectIssue, error) { | ||
issue := &ProjectIssue{} | ||
|
||
has, err := db.GetEngine(ctx).Where("issue_id = ?", issueID).Get(issue) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !has { | ||
return nil, ErrProjectIssueNotExist{IssueID: issueID} | ||
} | ||
|
||
return issue, nil | ||
} | ||
|
||
func (issue *ProjectIssue) LoadProjectColumn(ctx context.Context) error { | ||
if issue.ProjectColumn != nil { | ||
return nil | ||
} | ||
|
||
var err error | ||
|
||
if issue.ProjectColumnID == 0 { | ||
issue.ProjectColumn, err = issue.Project.GetDefaultColumn(ctx) | ||
return err | ||
} | ||
|
||
issue.ProjectColumn, err = GetColumn(ctx, issue.ProjectColumnID) | ||
return err | ||
} | ||
|
||
// NumIssues return counter of all issues assigned to a project | ||
func (p *Project) NumIssues(ctx context.Context) int { | ||
c, err := db.GetEngine(ctx).Table("project_issue"). | ||
|
@@ -100,6 +146,27 @@ func MoveIssuesOnProjectColumn(ctx context.Context, column *Column, sortedIssueI | |
}) | ||
} | ||
|
||
func MoveIssueToColumnTail(ctx context.Context, issue *ProjectIssue, toColumn *Column) error { | ||
ctx, committer, err := db.TxContext(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer committer.Close() | ||
|
||
num, err := toColumn.NumIssues(ctx) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = db.GetEngine(ctx).Exec("UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", | ||
toColumn.ID, num, issue.IssueID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return committer.Commit() | ||
} | ||
|
||
func (c *Column) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Column) error { | ||
if c.ProjectID != newColumn.ProjectID { | ||
return fmt.Errorf("columns have to be in the same project") | ||
|
Uh oh!
There was an error while loading. Please reload this page.