-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix project issues list and counting #33594
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
e6f719c
611862f
374e11e
134f691
7344a1e
a845cd1
5878ceb
2f2ccd9
1133503
fc6cab9
b63e059
707af3c
0b82fed
25ebf7c
5a106cf
d215623
e859276
92dedaf
74c9b7b
3670a2c
91ad9af
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 |
---|---|---|
|
@@ -48,6 +48,8 @@ type Column struct { | |
ProjectID int64 `xorm:"INDEX NOT NULL"` | ||
CreatorID int64 `xorm:"NOT NULL"` | ||
|
||
NumIssues int64 `xorm:"-"` | ||
|
||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | ||
} | ||
|
@@ -57,20 +59,6 @@ func (Column) TableName() string { | |
return "project_board" // TODO: the legacy table name should be project_column | ||
} | ||
|
||
// NumIssues return counter of all issues assigned to the column | ||
func (c *Column) NumIssues(ctx context.Context) int { | ||
total, err := db.GetEngine(ctx).Table("project_issue"). | ||
Where("project_id=?", c.ProjectID). | ||
And("project_board_id=?", c.ID). | ||
GroupBy("issue_id"). | ||
Cols("issue_id"). | ||
Count() | ||
if err != nil { | ||
return 0 | ||
} | ||
return int(total) | ||
} | ||
|
||
func (c *Column) GetIssues(ctx context.Context) ([]*ProjectIssue, error) { | ||
issues := make([]*ProjectIssue, 0, 5) | ||
if err := db.GetEngine(ctx).Where("project_id=?", c.ProjectID). | ||
|
@@ -192,7 +180,7 @@ func deleteColumnByID(ctx context.Context, columnID int64) error { | |
if err != nil { | ||
return err | ||
} | ||
defaultColumn, err := project.GetDefaultColumn(ctx) | ||
defaultColumn, err := project.MustDefaultColumn(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -257,8 +245,8 @@ func (p *Project) GetColumns(ctx context.Context) (ColumnList, error) { | |
return columns, nil | ||
} | ||
|
||
// GetDefaultColumn return default column and ensure only one exists | ||
func (p *Project) GetDefaultColumn(ctx context.Context) (*Column, error) { | ||
// getDefaultColumn return default column and ensure only one exists | ||
func (p *Project) getDefaultColumn(ctx context.Context) (*Column, error) { | ||
var column Column | ||
has, err := db.GetEngine(ctx). | ||
Where("project_id=? AND `default` = ?", p.ID, true). | ||
|
@@ -270,6 +258,31 @@ func (p *Project) GetDefaultColumn(ctx context.Context) (*Column, error) { | |
if has { | ||
return &column, nil | ||
} | ||
return nil, ErrProjectColumnNotExist{ColumnID: 0} | ||
} | ||
|
||
// MustDefaultColumn returns the default column for a project, get the first one if exist one and creating one if it does not exist | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (p *Project) MustDefaultColumn(ctx context.Context) (*Column, error) { | ||
c, err := p.getDefaultColumn(ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think it should change the existing logic in The old logic means this: use the latest default one. It doesn't care about "sorting" or not. There should be only one "default" column, the "order by" is just a fallback. |
||
if err != nil && !IsErrProjectColumnNotExist(err) { | ||
return nil, err | ||
} | ||
if c != nil { | ||
return c, nil | ||
} | ||
|
||
var column Column | ||
has, err := db.GetEngine(ctx).Where("project_id=?", p.ID).OrderBy("sorting, id").Get(&column) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if has { | ||
column.Default = true | ||
if _, err := db.GetEngine(ctx).ID(column.ID).Cols("`default`").Update(&column); err != nil { | ||
return nil, err | ||
} | ||
return &column, nil | ||
} | ||
|
||
// create a default column if none is found | ||
column = Column{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.