mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-05-07 12:37:14 -05:00
feat(task): always insert new tasks at the top
Resolves https://community.vikunja.io/t/kanban-cards-in-wrong-order/2731
This commit is contained in:
@@ -564,15 +564,15 @@ async function addTaskToBucket(bucketId: IBucket['id']) {
|
|||||||
})
|
})
|
||||||
newTaskText.value = ''
|
newTaskText.value = ''
|
||||||
kanbanStore.addTaskToBucket(task)
|
kanbanStore.addTaskToBucket(task)
|
||||||
scrollTaskContainerToBottom(bucketId)
|
scrollTaskContainerToTop(bucketId)
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollTaskContainerToBottom(bucketId: IBucket['id']) {
|
function scrollTaskContainerToTop(bucketId: IBucket['id']) {
|
||||||
const bucketEl = taskContainerRefs.value[bucketId]
|
const bucketEl = taskContainerRefs.value[bucketId]
|
||||||
if (!bucketEl) {
|
if (!bucketEl) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bucketEl.scrollTop = bucketEl.scrollHeight
|
bucketEl.scrollTop = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createNewBucket() {
|
async function createNewBucket() {
|
||||||
|
|||||||
@@ -194,8 +194,8 @@ export const useKanbanStore = defineStore('kanban', () => {
|
|||||||
...oldBucket,
|
...oldBucket,
|
||||||
count: (oldBucket?.count || 0) + 1,
|
count: (oldBucket?.count || 0) + 1,
|
||||||
tasks: [
|
tasks: [
|
||||||
...oldBucket.tasks,
|
|
||||||
task,
|
task,
|
||||||
|
...oldBucket.tasks,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
buckets.value[bucketIndex] = newBucket
|
buckets.value[bucketIndex] = newBucket
|
||||||
|
|||||||
@@ -192,3 +192,39 @@ func getPositionsForView(s *xorm.Session, view *ProjectView) (positions []*TaskP
|
|||||||
Find(&positions)
|
Find(&positions)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calculateNewPositionForTask(s *xorm.Session, a web.Auth, t *Task, view *ProjectView) (*TaskPosition, error) {
|
||||||
|
if t.Position == 0 {
|
||||||
|
lowestPosition := &TaskPosition{}
|
||||||
|
exists, err := s.Where("project_view_id = ?", view.ID).
|
||||||
|
OrderBy("position asc").
|
||||||
|
Get(lowestPosition)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
if lowestPosition.Position == 0 {
|
||||||
|
err = RecalculateTaskPositions(s, view, a)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
lowestPosition = &TaskPosition{}
|
||||||
|
_, err = s.Where("project_view_id = ?", view.ID).
|
||||||
|
OrderBy("position asc").
|
||||||
|
Get(lowestPosition)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Position = lowestPosition.Position / 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &TaskPosition{
|
||||||
|
TaskID: t.ID,
|
||||||
|
ProjectViewID: view.ID,
|
||||||
|
Position: calculateDefaultPosition(t.Index, t.Position),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -791,11 +791,12 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool, setB
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
positions = append(positions, &TaskPosition{
|
newPosition, err := calculateNewPositionForTask(s, a, t, view)
|
||||||
TaskID: t.ID,
|
if err != nil {
|
||||||
ProjectViewID: view.ID,
|
return err
|
||||||
Position: calculateDefaultPosition(t.Index, t.Position),
|
}
|
||||||
})
|
|
||||||
|
positions = append(positions, newPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(positions) > 0 {
|
if len(positions) > 0 {
|
||||||
@@ -955,11 +956,11 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tp := TaskPosition{
|
tp, err := calculateNewPositionForTask(s, a, t, view)
|
||||||
TaskID: t.ID,
|
if err != nil {
|
||||||
ProjectViewID: view.ID,
|
return err
|
||||||
Position: calculateDefaultPosition(t.Index, t.Position),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tp.Update(s, a)
|
err = tp.Update(s, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user