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
|
2021-06-03 17:18:38 +02:00
|
|
|
@change="setDate"
|
2020-09-05 22:35:52 +02:00
|
|
|
class="is-pulled-right"
|
|
|
|
v-if="!showAll"
|
|
|
|
v-model="showNulls"
|
2020-07-22 12:39:07 +02:00
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.show.noDates') }}
|
2020-07-22 12:39:07 +02:00
|
|
|
</fancycheckbox>
|
2021-06-24 01:24:57 +02:00
|
|
|
<h3 v-if="showAll && tasks.length > 0">
|
|
|
|
{{ $t('task.show.current') }}
|
|
|
|
</h3>
|
2021-01-24 14:00:21 +01:00
|
|
|
<h3 v-else-if="!showAll" class="mb-2">
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.show.from') }}
|
2020-07-22 12:29:03 +02:00
|
|
|
<flat-pickr
|
2021-08-06 19:25:17 +02:00
|
|
|
:class="{ 'disabled': loading}"
|
2020-09-05 22:35:52 +02:00
|
|
|
:config="flatPickerConfig"
|
2021-08-06 19:25:17 +02:00
|
|
|
:disabled="loading"
|
2021-06-03 17:18:38 +02:00
|
|
|
@on-close="setDate"
|
2020-09-05 22:35:52 +02:00
|
|
|
class="input"
|
|
|
|
v-model="cStartDate"
|
2020-07-22 12:29:03 +02:00
|
|
|
/>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.show.until') }}
|
2020-07-22 12:29:03 +02:00
|
|
|
<flat-pickr
|
2021-08-06 19:25:17 +02:00
|
|
|
:class="{ 'disabled': loading}"
|
2020-09-05 22:35:52 +02:00
|
|
|
:config="flatPickerConfig"
|
2021-08-06 19:25:17 +02:00
|
|
|
:disabled="loading"
|
2021-06-03 17:18:38 +02:00
|
|
|
@on-close="setDate"
|
2020-09-05 22:35:52 +02:00
|
|
|
class="input"
|
|
|
|
v-model="cEndDate"
|
2020-07-22 12:29:03 +02:00
|
|
|
/>
|
|
|
|
</h3>
|
2021-01-24 14:00:21 +01:00
|
|
|
<div v-if="!showAll" class="mb-4">
|
2021-06-24 01:24:57 +02:00
|
|
|
<x-button type="secondary" @click="showTodaysTasks()" class="mr-2">{{ $t('task.show.today') }}</x-button>
|
|
|
|
<x-button type="secondary" @click="setDatesToNextWeek()" class="mr-2">{{ $t('task.show.nextWeek') }}</x-button>
|
|
|
|
<x-button type="secondary" @click="setDatesToNextMonth()">{{ $t('task.show.nextMonth') }}</x-button>
|
2020-11-22 18:05:25 +01:00
|
|
|
</div>
|
2021-08-06 19:25:17 +02:00
|
|
|
<template v-if="!loading && (!tasks || tasks.length === 0) && showNothingToDo">
|
2021-06-24 01:24:57 +02:00
|
|
|
<h3 class="nothing">{{ $t('task.show.noTasks') }}</h3>
|
2021-10-03 20:48:02 +02:00
|
|
|
<img alt="" :src="llamaCoolUrl" />
|
2018-12-25 23:41:55 +01:00
|
|
|
</template>
|
2021-08-06 19:25:17 +02:00
|
|
|
<div :class="{ 'is-loading': loading}" class="spinner"></div>
|
2021-01-24 14:00:21 +01:00
|
|
|
|
2021-01-24 15:37:19 +01:00
|
|
|
<card :padding="false" class="has-overflow" :has-content="false" v-if="tasks && tasks.length > 0">
|
2021-01-24 14:00:21 +01:00
|
|
|
<div class="tasks">
|
|
|
|
<single-task-in-list
|
|
|
|
:key="t.id"
|
|
|
|
class="task"
|
|
|
|
v-for="t in tasks"
|
|
|
|
:show-list="true"
|
|
|
|
:the-task="t"
|
|
|
|
@taskUpdated="updateTasks"/>
|
|
|
|
</div>
|
|
|
|
</card>
|
2018-12-25 23:41:55 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02:00
|
|
|
import SingleTaskInList from '../../components/tasks/partials/singleTaskInList'
|
|
|
|
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'
|
2021-08-06 19:25:17 +02:00
|
|
|
import {LOADING, LOADING_MODULE} from '../../store/mutation-types'
|
2020-07-22 12:29:03 +02:00
|
|
|
|
2021-10-03 20:48:02 +02:00
|
|
|
import llamaCoolUrl from '@/assets/llama-cool.svg'
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'ShowTasks',
|
|
|
|
components: {
|
|
|
|
Fancycheckbox,
|
|
|
|
SingleTaskInList,
|
|
|
|
flatPickr,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tasks: [],
|
|
|
|
showNulls: true,
|
2021-01-16 20:20:43 +01:00
|
|
|
showOverdue: false,
|
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
|
|
|
|
2021-01-24 14:00:21 +01:00
|
|
|
showNothingToDo: false,
|
2021-10-03 20:48:02 +02:00
|
|
|
llamaCoolUrl,
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
startDate: Date,
|
|
|
|
endDate: Date,
|
|
|
|
showAll: Boolean,
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.cStartDate = this.startDate
|
|
|
|
this.cEndDate = this.endDate
|
|
|
|
this.loadPendingTasks()
|
|
|
|
},
|
2021-01-24 14:00:21 +01:00
|
|
|
mounted() {
|
|
|
|
setTimeout(() => this.showNothingToDo = true, 100)
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
watch: {
|
2021-09-08 11:59:38 +02:00
|
|
|
'$route': {
|
|
|
|
handler: 'loadPendingTasks',
|
|
|
|
deep: true,
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
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
|
|
|
|
},
|
|
|
|
},
|
2021-06-24 01:24:57 +02:00
|
|
|
computed: {
|
|
|
|
flatPickerConfig() {
|
|
|
|
return {
|
|
|
|
altFormat: this.$t('date.altFormatLong'),
|
|
|
|
altInput: true,
|
|
|
|
dateFormat: 'Y-m-d H:i',
|
|
|
|
enableTime: true,
|
|
|
|
time_24hr: true,
|
|
|
|
locale: {
|
|
|
|
firstDayOfWeek: this.$store.state.auth.settings.weekStart,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
...mapState({
|
|
|
|
userAuthenticated: state => state.auth.authenticated,
|
2021-08-06 19:25:17 +02:00
|
|
|
loading: state => state[LOADING] && state[LOADING_MODULE] === 'tasks',
|
2021-06-24 01:24:57 +02:00
|
|
|
}),
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
methods: {
|
2021-06-03 17:18:38 +02:00
|
|
|
setDate() {
|
|
|
|
this.$router.push({
|
|
|
|
name: this.$route.name,
|
|
|
|
query: {
|
|
|
|
from: +new Date(this.cStartDate),
|
|
|
|
to: +new Date(this.cEndDate),
|
|
|
|
showOverdue: this.showOverdue,
|
|
|
|
showNulls: this.showNulls,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
async loadPendingTasks() {
|
2020-09-05 22:35:52 +02:00
|
|
|
// 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
|
2021-06-03 17:18:38 +02:00
|
|
|
if (typeof this.$route.query.from !== 'undefined' && typeof this.$route.query.to !== 'undefined') {
|
|
|
|
this.cStartDate = new Date(Number(this.$route.query.from))
|
|
|
|
this.cEndDate = new Date(Number(this.$route.query.to))
|
|
|
|
} else {
|
|
|
|
this.cStartDate = new Date(this.cStartDate)
|
|
|
|
this.cEndDate = new Date(this.cEndDate)
|
|
|
|
}
|
|
|
|
this.showOverdue = this.$route.query.showOverdue
|
|
|
|
this.showNulls = this.$route.query.showNulls
|
2020-07-07 22:07:13 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.showAll) {
|
2021-06-24 01:24:57 +02:00
|
|
|
this.setTitle(this.$t('task.show.titleCurrent'))
|
2020-09-05 22:35:52 +02:00
|
|
|
} else {
|
2021-10-11 19:37:20 +02:00
|
|
|
this.setTitle(this.$t('task.show.titleDates', {
|
|
|
|
from: this.cStartDate.toLocaleDateString(),
|
|
|
|
to: this.cEndDate.toLocaleDateString(),
|
|
|
|
}))
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
2020-05-09 15:46:05 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
const params = {
|
|
|
|
sort_by: ['due_date', 'id'],
|
2021-02-20 18:35:29 +01:00
|
|
|
order_by: ['desc', 'desc'],
|
2020-09-05 22:35:52 +02:00
|
|
|
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')
|
|
|
|
|
2021-01-16 20:20:43 +01:00
|
|
|
if (!this.showOverdue) {
|
|
|
|
params.filter_by.push('due_date')
|
|
|
|
params.filter_value.push(this.cStartDate)
|
|
|
|
params.filter_comparator.push('greater')
|
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
|
2021-10-11 19:37:20 +02:00
|
|
|
const tasks = await this.$store.dispatch('tasks/loadTasks', params)
|
2021-02-20 18:35:29 +01:00
|
|
|
|
2021-10-11 19:37:20 +02:00
|
|
|
// FIXME: sort tasks in computed
|
|
|
|
// Sort all tasks to put those with a due date before the ones without a due date, the
|
|
|
|
// soonest before the later ones.
|
|
|
|
// We can't use the api sorting here because that sorts tasks with a due date after
|
|
|
|
// ones without a due date.
|
2021-10-17 16:06:58 +02:00
|
|
|
this.tasks = tasks.sort((a, b) => a.dueDate - b.dueDate)
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
|
|
|
// FIXME: this modification should happen in the store
|
2020-09-05 22:35:52 +02:00
|
|
|
updateTasks(updatedTask) {
|
|
|
|
for (const t in this.tasks) {
|
|
|
|
if (this.tasks[t].id === updatedTask.id) {
|
2021-08-19 21:35:38 +02:00
|
|
|
this.tasks[t] = updatedTask
|
2020-09-28 20:37:06 +02:00
|
|
|
// Move the task to the end of the done tasks if it is now done
|
|
|
|
if (updatedTask.done) {
|
|
|
|
this.tasks.splice(t, 1)
|
|
|
|
this.tasks.push(updatedTask)
|
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
break
|
2020-03-23 23:24:14 +01:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
2018-12-25 23:41:55 +01:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
2020-11-22 18:05:25 +01:00
|
|
|
setDatesToNextWeek() {
|
|
|
|
this.cStartDate = new Date()
|
|
|
|
this.cEndDate = new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000)
|
2021-01-16 20:20:43 +01:00
|
|
|
this.showOverdue = false
|
2021-06-03 17:18:38 +02:00
|
|
|
this.setDate()
|
2020-11-22 18:05:25 +01:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
2020-11-22 18:05:25 +01:00
|
|
|
setDatesToNextMonth() {
|
|
|
|
this.cStartDate = new Date()
|
|
|
|
this.cEndDate = new Date((new Date()).setMonth((new Date()).getMonth() + 1))
|
2021-01-16 20:20:43 +01:00
|
|
|
this.showOverdue = false
|
2021-06-03 17:18:38 +02:00
|
|
|
this.setDate()
|
2021-01-16 20:20:43 +01:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
2021-01-16 20:20:43 +01:00
|
|
|
showTodaysTasks() {
|
|
|
|
const d = new Date()
|
|
|
|
this.cStartDate = new Date()
|
|
|
|
this.cEndDate = new Date(d.setDate(d.getDate() + 1))
|
|
|
|
this.showOverdue = true
|
2021-06-03 17:18:38 +02:00
|
|
|
this.setDate()
|
2020-11-22 18:05:25 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2018-12-25 23:41:55 +01:00
|
|
|
</script>
|