feat(views): create task bucket relation when creating a new bucket
This commit is contained in:
parent
7f1788eba9
commit
61e27ae3eb
@ -257,6 +257,55 @@ func (p *ProjectView) Create(s *xorm.Session, a web.Auth) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createProjectView(s *xorm.Session, p *ProjectView, a web.Auth, createBacklogBucket bool) (err error) {
|
||||||
|
_, err = s.Insert(p)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if createBacklogBucket && p.BucketConfigurationMode == BucketConfigurationModeManual {
|
||||||
|
// Create a new first bucket for this project
|
||||||
|
b := &Bucket{
|
||||||
|
ProjectViewID: p.ID,
|
||||||
|
Title: "Backlog",
|
||||||
|
}
|
||||||
|
err = b.Create(s, a)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move all tasks into the new bucket when the project already has tasks
|
||||||
|
c := &TaskCollection{
|
||||||
|
ProjectID: p.ProjectID,
|
||||||
|
}
|
||||||
|
ts, _, _, err := c.ReadAll(s, a, "", 0, -1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tasks := ts.([]*Task)
|
||||||
|
|
||||||
|
if len(tasks) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
taskBuckets := []*TaskBucket{}
|
||||||
|
for _, task := range tasks {
|
||||||
|
taskBuckets = append(taskBuckets, &TaskBucket{
|
||||||
|
TaskID: task.ID,
|
||||||
|
BucketID: b.ID,
|
||||||
|
ProjectViewID: p.ID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = s.Insert(&taskBuckets)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RecalculateTaskPositions(s, p)
|
||||||
|
}
|
||||||
|
|
||||||
// Update is the handler to update a project view
|
// Update is the handler to update a project view
|
||||||
// @Summary Updates a project view
|
// @Summary Updates a project view
|
||||||
// @Description Updates a project view.
|
// @Description Updates a project view.
|
||||||
@ -331,7 +380,7 @@ func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth,
|
|||||||
ViewKind: ProjectViewKindList,
|
ViewKind: ProjectViewKindList,
|
||||||
Position: 100,
|
Position: 100,
|
||||||
}
|
}
|
||||||
err = list.Create(s, a)
|
err = createProjectView(s, list, a, createBacklogBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -342,7 +391,7 @@ func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth,
|
|||||||
ViewKind: ProjectViewKindGantt,
|
ViewKind: ProjectViewKindGantt,
|
||||||
Position: 200,
|
Position: 200,
|
||||||
}
|
}
|
||||||
err = gantt.Create(s, a)
|
err = createProjectView(s, gantt, a, createBacklogBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -353,7 +402,7 @@ func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth,
|
|||||||
ViewKind: ProjectViewKindTable,
|
ViewKind: ProjectViewKindTable,
|
||||||
Position: 300,
|
Position: 300,
|
||||||
}
|
}
|
||||||
err = table.Create(s, a)
|
err = createProjectView(s, table, a, createBacklogBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -365,19 +414,10 @@ func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth,
|
|||||||
Position: 400,
|
Position: 400,
|
||||||
BucketConfigurationMode: BucketConfigurationModeManual,
|
BucketConfigurationMode: BucketConfigurationModeManual,
|
||||||
}
|
}
|
||||||
err = kanban.Create(s, a)
|
err = createProjectView(s, kanban, a, createBacklogBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if createBacklogBucket {
|
|
||||||
// Create a new first bucket for this project
|
|
||||||
b := &Bucket{
|
|
||||||
ProjectViewID: kanban.ID,
|
|
||||||
Title: "Backlog",
|
|
||||||
}
|
|
||||||
err = b.Create(s, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ func (sf *SavedFilter) Create(s *xorm.Session, auth web.Auth) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CreateDefaultViewsForProject(s, &Project{ID: getProjectIDFromSavedFilterID(sf.ID)}, auth, false)
|
err = CreateDefaultViewsForProject(s, &Project{ID: getProjectIDFromSavedFilterID(sf.ID)}, auth, true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +110,10 @@ func RecalculateTaskPositions(s *xorm.Session, view *ProjectView) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(allTasks) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
maxPosition := math.Pow(2, 32)
|
maxPosition := math.Pow(2, 32)
|
||||||
newPositions := make([]*TaskPosition, 0, len(allTasks))
|
newPositions := make([]*TaskPosition, 0, len(allTasks))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user