2018-12-25 23:41:55 +01:00
|
|
|
<template>
|
2020-07-22 12:29:03 +02:00
|
|
|
<div class="is-max-width-desktop show-tasks">
|
2020-07-22 12:39:07 +02:00
|
|
|
<fancycheckbox
|
2020-09-05 22:35:52 +02:00
|
|
|
@change="loadPendingTasks"
|
|
|
|
class="is-pulled-right"
|
|
|
|
v-if="!showAll"
|
|
|
|
v-model="showNulls"
|
2020-07-22 12:39:07 +02:00
|
|
|
>
|
|
|
|
Show tasks without dates
|
|
|
|
</fancycheckbox>
|
2018-12-25 23:41:55 +01:00
|
|
|
<h3 v-if="showAll">Current tasks</h3>
|
2020-07-22 12:29:03 +02:00
|
|
|
<h3 v-else>
|
|
|
|
Tasks from
|
|
|
|
<flat-pickr
|
2020-09-05 22:35:52 +02:00
|
|
|
:class="{ 'disabled': taskService.loading}"
|
|
|
|
:config="flatPickerConfig"
|
|
|
|
:disabled="taskService.loading"
|
|
|
|
@on-close="loadPendingTasks"
|
|
|
|
class="input"
|
|
|
|
v-model="cStartDate"
|
2020-07-22 12:29:03 +02:00
|
|
|
/>
|
|
|
|
until
|
|
|
|
<flat-pickr
|
2020-09-05 22:35:52 +02:00
|
|
|
:class="{ 'disabled': taskService.loading}"
|
|
|
|
:config="flatPickerConfig"
|
|
|
|
:disabled="taskService.loading"
|
|
|
|
@on-close="loadPendingTasks"
|
|
|
|
class="input"
|
|
|
|
v-model="cEndDate"
|
2020-07-22 12:29:03 +02:00
|
|
|
/>
|
|
|
|
</h3>
|
2020-07-22 12:39:07 +02:00
|
|
|
<template v-if="!taskService.loading && (!hasUndoneTasks || !tasks || tasks.length === 0)">
|
2020-05-29 23:12:38 +02:00
|
|
|
<h3 class="nothing">Nothing to do - Have a nice day!</h3>
|
2020-09-05 22:35:52 +02:00
|
|
|
<img alt="" src="/images/cool.svg"/>
|
2018-12-25 23:41:55 +01:00
|
|
|
</template>
|
2020-09-05 22:35:52 +02:00
|
|
|
<div :class="{ 'is-loading': taskService.loading}" class="spinner"></div>
|
2018-12-25 23:41:55 +01:00
|
|
|
<div class="tasks" v-if="tasks && tasks.length > 0">
|
2020-09-05 23:41:23 +02:00
|
|
|
<single-task-in-list
|
|
|
|
:key="t.id"
|
|
|
|
class="task"
|
|
|
|
v-for="t in tasks"
|
|
|
|
:show-list="true"
|
|
|
|
:the-task="t"
|
|
|
|
@taskUpdated="updateTasks"/>
|
2018-12-25 23:41:55 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02:00
|
|
|
import TaskService from '../../services/task'
|
|
|
|
import SingleTaskInList from '../../components/tasks/partials/singleTaskInList'
|
|
|
|
import {HAS_TASKS} from '@/store/mutation-types'
|
|
|
|
import {mapState} from 'vuex'
|
2018-12-25 23:41:55 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
import flatPickr from 'vue-flatpickr-component'
|
|
|
|
import 'flatpickr/dist/flatpickr.css'
|
|
|
|
import Fancycheckbox from '../../components/input/fancycheckbox'
|
2020-07-22 12:29:03 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'ShowTasks',
|
|
|
|
components: {
|
|
|
|
Fancycheckbox,
|
|
|
|
SingleTaskInList,
|
|
|
|
flatPickr,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tasks: [],
|
|
|
|
hasUndoneTasks: false,
|
|
|
|
taskService: TaskService,
|
|
|
|
showNulls: true,
|
2020-07-22 12:29:03 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
cStartDate: null,
|
|
|
|
cEndDate: null,
|
2020-07-22 12:29:03 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
flatPickerConfig: {
|
|
|
|
altFormat: 'j M Y H:i',
|
|
|
|
altInput: true,
|
|
|
|
dateFormat: 'Y-m-d H:i',
|
|
|
|
enableTime: true,
|
|
|
|
time_24hr: true,
|
2020-07-22 12:29:03 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
startDate: Date,
|
|
|
|
endDate: Date,
|
|
|
|
showAll: Boolean,
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.taskService = new TaskService()
|
|
|
|
this.cStartDate = this.startDate
|
|
|
|
this.cEndDate = this.endDate
|
|
|
|
this.loadPendingTasks()
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$route': 'loadPendingTasks',
|
|
|
|
startDate(newVal) {
|
|
|
|
this.cStartDate = newVal
|
2019-12-15 21:42:40 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
endDate(newVal) {
|
|
|
|
this.cEndDate = newVal
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: mapState({
|
|
|
|
userAuthenticated: state => state.auth.authenticated,
|
|
|
|
}),
|
|
|
|
methods: {
|
|
|
|
loadPendingTasks() {
|
|
|
|
// Since this route is authentication only, users would get an error message if they access the page unauthenticated.
|
|
|
|
// Since this component is mounted as the home page before unauthenticated users get redirected
|
|
|
|
// to the login page, they will almost always see the error message.
|
|
|
|
if (!this.userAuthenticated) {
|
|
|
|
return
|
|
|
|
}
|
2020-07-22 12:29:03 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
// Make sure all dates are date objects
|
|
|
|
this.cStartDate = new Date(this.cStartDate)
|
|
|
|
this.cEndDate = new Date(this.cEndDate)
|
2020-07-07 22:07:13 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.showAll) {
|
|
|
|
this.setTitle('Current Tasks')
|
|
|
|
} else {
|
|
|
|
this.setTitle(`Tasks from ${this.cStartDate.toLocaleDateString()} until ${this.cEndDate.toLocaleDateString()}`)
|
|
|
|
}
|
2020-05-09 15:46:05 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
const params = {
|
|
|
|
sort_by: ['due_date', 'id'],
|
|
|
|
order_by: ['desc', 'desc'],
|
|
|
|
filter_by: ['done'],
|
|
|
|
filter_value: [false],
|
|
|
|
filter_comparator: ['equals'],
|
|
|
|
filter_concat: 'and',
|
|
|
|
filter_include_nulls: this.showNulls,
|
|
|
|
}
|
|
|
|
if (!this.showAll) {
|
|
|
|
if (this.showNulls) {
|
|
|
|
params.filter_by.push('start_date')
|
|
|
|
params.filter_value.push(this.cStartDate)
|
|
|
|
params.filter_comparator.push('greater')
|
2020-05-09 15:46:05 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
params.filter_by.push('end_date')
|
2020-07-22 12:29:03 +02:00
|
|
|
params.filter_value.push(this.cEndDate)
|
2020-05-09 15:46:05 +02:00
|
|
|
params.filter_comparator.push('less')
|
2018-12-25 23:41:55 +01:00
|
|
|
}
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
params.filter_by.push('due_date')
|
|
|
|
params.filter_value.push(this.cEndDate)
|
|
|
|
params.filter_comparator.push('less')
|
|
|
|
|
|
|
|
params.filter_by.push('due_date')
|
|
|
|
params.filter_value.push(this.cStartDate)
|
|
|
|
params.filter_comparator.push('greater')
|
|
|
|
}
|
|
|
|
|
|
|
|
this.taskService.getAll({}, params)
|
|
|
|
.then(r => {
|
|
|
|
if (r.length > 0) {
|
|
|
|
for (const index in r) {
|
|
|
|
if (r[index].done !== true) {
|
|
|
|
this.hasUndoneTasks = true
|
2018-12-25 23:41:55 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-23 23:24:14 +01:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
this.$set(this, 'tasks', r.filter(t => !t.done))
|
|
|
|
this.$store.commit(HAS_TASKS, r.length > 0)
|
|
|
|
})
|
|
|
|
.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
|
2020-03-23 23:24:14 +01:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
this.sortTasks()
|
2018-12-25 23:41:55 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2018-12-25 23:41:55 +01:00
|
|
|
</script>
|