2018-12-25 23:41:55 +01:00
|
|
|
<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)">
|
2018-12-25 23:41:55 +01:00
|
|
|
<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>
|
2018-12-25 23:41:55 +01:00
|
|
|
<div class="tasks" v-if="tasks && tasks.length > 0">
|
2020-03-23 23:24:14 +01:00
|
|
|
<div class="task" v-for="t in tasks" :key="t.id">
|
|
|
|
<single-task-in-list :the-task="t" @taskUpdated="updateTasks"/>
|
2018-12-25 23:41:55 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2019-03-02 11:25:10 +01:00
|
|
|
import TaskService from '../../services/task'
|
2020-03-23 23:24:14 +01:00
|
|
|
import SingleTaskInList from "./reusable/singleTaskInList";
|
2018-12-25 23:41:55 +01:00
|
|
|
|
|
|
|
export default {
|
2019-12-07 17:35:42 +01:00
|
|
|
name: 'ShowTasks',
|
2019-11-24 14:16:24 +01:00
|
|
|
components: {
|
2020-03-23 23:24:14 +01:00
|
|
|
SingleTaskInList,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2018-12-25 23:41:55 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tasks: [],
|
2019-03-02 11:25:10 +01:00
|
|
|
hasUndoneTasks: false,
|
|
|
|
taskService: TaskService,
|
2018-12-25 23:41:55 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
startDate: Date,
|
|
|
|
endDate: Date,
|
|
|
|
showAll: Boolean,
|
|
|
|
},
|
|
|
|
created() {
|
2019-03-02 11:25:10 +01:00
|
|
|
this.taskService = new TaskService()
|
2018-12-25 23:41:55 +01:00
|
|
|
this.loadPendingTasks()
|
|
|
|
},
|
2019-12-15 21:42:40 +01:00
|
|
|
computed: {
|
|
|
|
undoneTasks: function () {
|
|
|
|
return this.tasks.filter(t => !t.done)
|
|
|
|
}
|
|
|
|
},
|
2018-12-25 23:41:55 +01:00
|
|
|
methods: {
|
|
|
|
loadPendingTasks() {
|
2020-01-31 11:09:45 +01:00
|
|
|
let params = {sort_by: ['due_date_unix', 'id'], order_by: ['desc', 'desc']}
|
2018-12-25 23:41:55 +01:00
|
|
|
if (!this.showAll) {
|
2019-03-10 13:59:17 +01:00
|
|
|
params.startdate = Math.round(+ this.startDate / 1000)
|
|
|
|
params.enddate = Math.round(+ this.endDate / 1000)
|
2018-12-25 23:41:55 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2018-12-25 23:48:32 +01:00
|
|
|
this.hasUndoneTasks = true
|
|
|
|
}
|
2018-12-25 23:41:55 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-10 13:59:17 +01:00
|
|
|
this.$set(this, 'tasks', r)
|
2020-03-23 23:24:14 +01:00
|
|
|
this.sortTasks()
|
2018-12-25 23:41:55 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2018-12-25 23:41:55 +01:00
|
|
|
})
|
|
|
|
},
|
2020-03-23 23:24:14 +01:00
|
|
|
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()
|
2018-12-25 23:41:55 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</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>
|