vikunja-frontend/src/components/tasks/ShowTasks.vue

131 lines
2.9 KiB
Vue
Raw Normal View History

<template>
<div>
<h3 v-if="showAll">Current tasks</h3>
<h3 v-else>Tasks from {{startDate.toLocaleDateString()}} until {{endDate.toLocaleDateString()}}</h3>
2019-03-10 13:59:17 +01:00
<template v-if="!taskService.loading && (!hasUndoneTasks || !tasks)">
<h3 class="nothing">Nothing to to - Have a nice day!</h3>
<img src="/images/cool.svg" alt=""/>
</template>
2019-03-10 13:59:17 +01:00
<div class="spinner" :class="{ 'is-loading': taskService.loading}"></div>
<div class="tasks" v-if="tasks && tasks.length > 0">
<div class="task" v-for="t in tasks" :key="t.id">
2020-05-11 16:52:58 +02:00
<single-task-in-list :the-task="t" @taskUpdated="updateTasks" :show-list="true"/>
</div>
</div>
</div>
</template>
<script>
import TaskService from '../../services/task'
import SingleTaskInList from "./reusable/singleTaskInList";
export default {
2019-12-07 17:35:42 +01:00
name: 'ShowTasks',
2019-11-24 14:16:24 +01:00
components: {
SingleTaskInList,
2019-11-24 14:16:24 +01:00
},
data() {
return {
tasks: [],
hasUndoneTasks: false,
taskService: TaskService,
}
},
props: {
startDate: Date,
endDate: Date,
showAll: Boolean,
},
created() {
this.taskService = new TaskService()
this.loadPendingTasks()
},
watch: {
'$route': 'loadPendingTasks',
2019-12-15 21:42:40 +01:00
},
methods: {
loadPendingTasks() {
2020-05-09 15:46:05 +02:00
const params = {
sort_by: ['due_date_unix', 'id'],
order_by: ['desc', 'desc'],
filter_by: ['done'],
filter_value: [false],
2020-05-09 15:46:05 +02:00
filter_comparator: ['equals'],
filter_concat: 'and',
}
if (!this.showAll) {
2020-05-09 15:46:05 +02:00
params.filter_by.push('start_date')
params.filter_value.push(Math.round(+ this.startDate / 1000))
params.filter_comparator.push('greater')
params.filter_by.push('end_date')
params.filter_value.push(Math.round(+ this.endDate / 1000))
params.filter_comparator.push('less')
params.filter_by.push('due_date')
params.filter_value.push(Math.round(+ this.endDate / 1000))
params.filter_comparator.push('less')
}
2019-03-10 13:59:17 +01:00
this.taskService.getAll({}, params)
.then(r => {
if (r.length > 0) {
for (const index in r) {
if (r[index].done !== true) {
this.hasUndoneTasks = true
}
}
}
2020-05-09 15:46:05 +02:00
this.$set(this, 'tasks', r.filter(t => !t.done))
})
.catch(e => {
this.error(e, this)
})
},
sortTasks() {
if (this.tasks === null || this.tasks === []) {
return
}
return this.tasks.sort(function(a,b) {
if (a.done < b.done)
return -1
if (a.done > b.done)
return 1
if (a.id > b.id)
return -1
if (a.id < b.id)
return 1
return 0
})
},
updateTasks(updatedTask) {
for (const t in this.tasks) {
if (this.tasks[t].id === updatedTask.id) {
this.$set(this.tasks, t, updatedTask)
break
}
}
this.sortTasks()
},
},
}
</script>
<style scoped>
h3{
text-align: left;
}
h3.nothing{
text-align: center;
margin-top: 3em;
}
img{
margin-top: 2em;
}
.spinner.is-loading:after {
margin-left: calc(40% - 1em);
}
</style>