Fix sorting task by due date on task overview

This commit is contained in:
kolaente 2021-02-20 18:35:29 +01:00
parent cf47e196d7
commit 634f134ede
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 15 additions and 11 deletions

View File

@ -34,7 +34,7 @@
<x-button type="secondary" @click="setDatesToNextWeek()" class="mr-2">Next Week</x-button> <x-button type="secondary" @click="setDatesToNextWeek()" class="mr-2">Next Week</x-button>
<x-button type="secondary" @click="setDatesToNextMonth()">Next Month</x-button> <x-button type="secondary" @click="setDatesToNextMonth()">Next Month</x-button>
</div> </div>
<template v-if="!taskService.loading && (!hasUndoneTasks || !tasks || tasks.length === 0) && showNothingToDo"> <template v-if="!taskService.loading && (!tasks || tasks.length === 0) && showNothingToDo">
<h3 class="nothing">Nothing to do - Have a nice day!</h3> <h3 class="nothing">Nothing to do - Have a nice day!</h3>
<img alt="" src="/images/cool.svg"/> <img alt="" src="/images/cool.svg"/>
</template> </template>
@ -73,7 +73,6 @@ export default {
data() { data() {
return { return {
tasks: [], tasks: [],
hasUndoneTasks: false,
taskService: TaskService, taskService: TaskService,
showNulls: true, showNulls: true,
showOverdue: false, showOverdue: false,
@ -139,7 +138,7 @@ export default {
const params = { const params = {
sort_by: ['due_date', 'id'], sort_by: ['due_date', 'id'],
order_by: ['asc', 'desc'], order_by: ['desc', 'desc'],
filter_by: ['done'], filter_by: ['done'],
filter_value: [false], filter_value: [false],
filter_comparator: ['equals'], filter_comparator: ['equals'],
@ -170,14 +169,19 @@ export default {
this.taskService.getAll({}, params) this.taskService.getAll({}, params)
.then(r => { .then(r => {
if (r.length > 0) {
for (const index in r) { // Sort all tasks to put those with a due date before the ones without a due date, the
if (r[index].done !== true) { // soonest before the later ones.
this.hasUndoneTasks = true // We can't use the api sorting here because that sorts tasks with a due date after
} // ones without a due date.
} r.sort((a, b) => {
} return a.dueDate === null && b.dueDate === null ? -1 : 1
this.$set(this, 'tasks', r.filter(t => !t.done)) })
const tasks = r.
filter(t => t.dueDate !== null).
concat(r.filter(t => t.dueDate === null))
this.$set(this, 'tasks', tasks)
this.$store.commit(HAS_TASKS, r.length > 0) this.$store.commit(HAS_TASKS, r.length > 0)
}) })
.catch(e => { .catch(e => {