fix(views): import
This commit is contained in:
parent
8b90eb4a15
commit
f3cdd7d15f
@ -349,6 +349,7 @@ func (b *Bucket) Update(s *xorm.Session, _ web.Auth) (err error) {
|
|||||||
"title",
|
"title",
|
||||||
"limit",
|
"limit",
|
||||||
"position",
|
"position",
|
||||||
|
"project_view_id",
|
||||||
).
|
).
|
||||||
Update(b)
|
Update(b)
|
||||||
return
|
return
|
||||||
|
@ -422,5 +422,12 @@ func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project.Views = []*ProjectView{
|
||||||
|
list,
|
||||||
|
gantt,
|
||||||
|
table,
|
||||||
|
kanban,
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,7 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
|||||||
originalBuckets := project.Buckets
|
originalBuckets := project.Buckets
|
||||||
originalBackgroundInformation := project.BackgroundInformation
|
originalBackgroundInformation := project.BackgroundInformation
|
||||||
needsDefaultBucket := false
|
needsDefaultBucket := false
|
||||||
|
oldViews := project.Views
|
||||||
|
|
||||||
// Saving the archived status to archive the project again after creating it
|
// Saving the archived status to archive the project again after creating it
|
||||||
var wasArchived bool
|
var wasArchived bool
|
||||||
@ -182,6 +183,47 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
|||||||
log.Debugf("[creating structure] Created bucket %d, old ID was %d", bucket.ID, oldID)
|
log.Debugf("[creating structure] Created bucket %d, old ID was %d", bucket.ID, oldID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create all views, create default views if we don't have any
|
||||||
|
if len(oldViews) > 0 {
|
||||||
|
for _, view := range oldViews {
|
||||||
|
view.ID = 0
|
||||||
|
|
||||||
|
if view.DefaultBucketID != 0 {
|
||||||
|
bucket, has := buckets[view.DefaultBucketID]
|
||||||
|
if has {
|
||||||
|
view.DefaultBucketID = bucket.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if view.DoneBucketID != 0 {
|
||||||
|
bucket, has := buckets[view.DoneBucketID]
|
||||||
|
if has {
|
||||||
|
view.DoneBucketID = bucket.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = view.Create(s, user)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Only using the default views
|
||||||
|
// Add all buckets to the default kanban view
|
||||||
|
for _, view := range project.Views {
|
||||||
|
if view.ViewKind == models.ProjectViewKindKanban {
|
||||||
|
for _, b := range buckets {
|
||||||
|
b.ProjectViewID = view.ID
|
||||||
|
err = b.Update(s, user)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Debugf("[creating structure] Creating %d tasks", len(tasks))
|
log.Debugf("[creating structure] Creating %d tasks", len(tasks))
|
||||||
|
|
||||||
setBucketOrDefault := func(task *models.Task) {
|
setBucketOrDefault := func(task *models.Task) {
|
||||||
@ -205,7 +247,6 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
|||||||
oldid := t.ID
|
oldid := t.ID
|
||||||
t.ProjectID = project.ID
|
t.ProjectID = project.ID
|
||||||
err = t.Create(s, user)
|
err = t.Create(s, user)
|
||||||
|
|
||||||
if err != nil && models.IsErrTaskCannotBeEmpty(err) {
|
if err != nil && models.IsErrTaskCannotBeEmpty(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -332,6 +373,14 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
|||||||
// All tasks brought their own bucket with them, therefore the newly created default bucket is just extra space
|
// All tasks brought their own bucket with them, therefore the newly created default bucket is just extra space
|
||||||
if !needsDefaultBucket {
|
if !needsDefaultBucket {
|
||||||
b := &models.Bucket{ProjectID: project.ID}
|
b := &models.Bucket{ProjectID: project.ID}
|
||||||
|
|
||||||
|
for _, view := range project.Views {
|
||||||
|
if view.ViewKind == models.ProjectViewKindKanban {
|
||||||
|
b.ProjectViewID = view.ID
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bucketsIn, _, _, err := b.ReadAll(s, user, "", 1, 1)
|
bucketsIn, _, _, err := b.ReadAll(s, user, "", 1, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -341,6 +390,7 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
|||||||
for _, b := range buckets {
|
for _, b := range buckets {
|
||||||
if b.Title == "Backlog" {
|
if b.Title == "Backlog" {
|
||||||
newBacklogBucket = b
|
newBacklogBucket = b
|
||||||
|
newBacklogBucket.ProjectID = project.ID
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,12 +142,11 @@ func TestInsertFromStructure(t *testing.T) {
|
|||||||
"title": testStructure[1].Title,
|
"title": testStructure[1].Title,
|
||||||
"description": testStructure[1].Description,
|
"description": testStructure[1].Description,
|
||||||
}, false)
|
}, false)
|
||||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
db.AssertExists(t, "task_buckets", map[string]interface{}{
|
||||||
"title": testStructure[1].Tasks[5].Title,
|
"task_id": testStructure[1].Tasks[5].ID,
|
||||||
"bucket_id": testStructure[1].Buckets[0].ID,
|
"bucket_id": testStructure[1].Buckets[0].ID,
|
||||||
}, false)
|
}, false)
|
||||||
db.AssertMissing(t, "tasks", map[string]interface{}{
|
db.AssertMissing(t, "task_buckets", map[string]interface{}{
|
||||||
"title": testStructure[1].Tasks[6].Title,
|
|
||||||
"bucket_id": 1111, // No task with that bucket should exist
|
"bucket_id": 1111, // No task with that bucket should exist
|
||||||
})
|
})
|
||||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user