1
0

feat(views): recalculate all positions when updating

This commit is contained in:
kolaente
2024-03-15 13:45:30 +01:00
parent 8ce476491e
commit ca4e3e01c5
5 changed files with 42 additions and 47 deletions

View File

@ -64,6 +64,17 @@ func (tp *TaskPosition) CanUpdate(s *xorm.Session, a web.Auth) (bool, error) {
// @Failure 500 {object} models.Message "Internal error"
// @Router /tasks/{id}/position [post]
func (tp *TaskPosition) Update(s *xorm.Session, _ web.Auth) (err error) {
// Update all positions if the newly saved position is < 0.1
if tp.Position < 0.1 {
view, err := GetProjectViewByID(s, tp.ProjectViewID)
if err != nil {
return err
}
return RecalculateTaskPositions(s, view)
}
exists, err := s.
Where("task_id = ? AND project_view_id = ?", tp.TaskID, tp.ProjectViewID).
Get(&TaskPosition{})
@ -110,6 +121,13 @@ func RecalculateTaskPositions(s *xorm.Session, view *ProjectView) (err error) {
})
}
_, err = s.
Where("project_view_id = ?", view.ID).
Delete(&TaskPosition{})
if err != nil {
return
}
_, err = s.Insert(newPositions)
return
}