feat(views): recalculate all positions when updating
This commit is contained in:
@ -1111,14 +1111,6 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update all positions if the newly saved position is < 0.1
|
||||
if ot.Position < 0.1 {
|
||||
err = recalculateTaskPositions(s, t.ProjectID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Get the task updated timestamp in a new struct - if we'd just try to put it into t which we already have, it
|
||||
// would still contain the old updated date.
|
||||
nt := &Task{}
|
||||
@ -1141,39 +1133,6 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
|
||||
return updateProjectLastUpdated(s, &Project{ID: t.ProjectID})
|
||||
}
|
||||
|
||||
func recalculateTaskPositions(s *xorm.Session, projectID int64) (err error) {
|
||||
|
||||
allTasks := []*Task{}
|
||||
err = s.
|
||||
Where("project_id = ?", projectID).
|
||||
OrderBy("position asc").
|
||||
Find(&allTasks)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
maxPosition := math.Pow(2, 32)
|
||||
|
||||
for i, task := range allTasks {
|
||||
|
||||
currentPosition := maxPosition / float64(len(allTasks)) * (float64(i + 1))
|
||||
|
||||
// Here we use "NoAutoTime() to prevent the ORM from updating column "updated" automatically.
|
||||
// Otherwise, this signals to CalDAV clients that the task has changed, which is not the case.
|
||||
// Consequence: when synchronizing a list of tasks, the first one immediately changes the date of all the
|
||||
// following ones from the same batch, which are then unable to be updated.
|
||||
_, err = s.Cols("position").
|
||||
Where("id = ?", task.ID).
|
||||
NoAutoTime().
|
||||
Update(&Task{Position: currentPosition})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func addOneMonthToDate(d time.Time) time.Time {
|
||||
return time.Date(d.Year(), d.Month()+1, d.Day(), d.Hour(), d.Minute(), d.Second(), d.Nanosecond(), config.GetTimeZone())
|
||||
}
|
||||
|
Reference in New Issue
Block a user