feat: add date math for filters #1342

Merged
konrad merged 88 commits from feature/date-math into main 2022-03-28 17:30:43 +00:00
1 changed files with 26 additions and 20 deletions
Showing only changes of commit d825960836 - Show all commits

View File

@ -4,21 +4,12 @@
{{ pageTitle }}
</h3>
<p v-if="!showAll">
<fancycheckbox
@change="setDate"
v-model="showNulls"
>
<fancycheckbox @change="setShowNulls">
{{ $t('task.show.noDates') }}
</fancycheckbox>
<fancycheckbox
@change="setDate"
v-model="showOverdue"
>
<fancycheckbox @change="setShowOverdue">
{{ $t('task.show.overdue') }}
</fancycheckbox>
{{ showOverdue ? 'true' : 'false'}}
{{ $t('task.show.select') }}
<datepicker-with-range @dateChanged="setDate"/>
</p>
@ -66,12 +57,6 @@ export default {
data() {
return {
tasks: [],
showNulls: true,
showOverdue: false,
// TODO: Set the date range based on the default (to make sure it shows up in the picker) -> maybe also use a computed which depends on dateFrom and dateTo?
dateRange: null,
showNothingToDo: false,
}
},
@ -108,6 +93,12 @@ export default {
? d
: this.endDate
},
showNulls() {
return this.$route.query.showNulls === 'true'
konrad marked this conversation as resolved Outdated

Unsure: I think eslint doesn't complain here if you use underscore (_) to spread the unused variable.

Unsure: I think eslint doesn't complain here if you use underscore (`_`) to spread the unused variable.

Add ?.[0] so we return the key, which is what we actually want to use and adjust variable name.

Add `?.[0]` so we return the key, which is what we actually want to use and adjust variable name.

Unsure: I think eslint doesn't complain here if you use underscore (_) to spread the unused variable.

Nope, does not seem to have an effect.

> Unsure: I think eslint doesn't complain here if you use underscore (_) to spread the unused variable. Nope, does not seem to have an effect.

Add ?.[0] so we return the key, which is what we actually want to use and adjust variable name.

Done.

> Add ?.[0] so we return the key, which is what we actually want to use and adjust variable name. Done.

Nope, does not seem to have an effect.

Interesting!

> Nope, does not seem to have an effect. Interesting!
},
konrad marked this conversation as resolved Outdated

Remove title var and return directly:

if (typeof predefinedRange !== 'undefined') {
    return t(`input.datepickerRange.ranges.${predefinedRangeKey}`)
} else {
    return showAll
			? t('task.show.titleCurrent')
			: t('task.show.fromuntil', {
				from: formatDate(dateFrom, 'PPP'),
				until: formatDate(dateTo, 'PPP'),
			})
}
Remove title var and return directly: ```js if (typeof predefinedRange !== 'undefined') { return t(`input.datepickerRange.ranges.${predefinedRangeKey}`) } else { return showAll ? t('task.show.titleCurrent') : t('task.show.fromuntil', { from: formatDate(dateFrom, 'PPP'), until: formatDate(dateTo, 'PPP'), }) }

Done.

Done.
showOverdue() {
return this.$route.query.showOverdue === 'true'
},
pageTitle() {
const title = this.showAll
? this.$t('task.show.titleCurrent')
@ -149,6 +140,24 @@ export default {
},
})
},
setShowOverdue(show) {
this.$router.push({
name: this.$route.name,
query: {
...this.$route.query,
showOverdue: show,
dpschen marked this conversation as resolved Outdated

Mhh that is a bit annoying that we have to convert to strings here :/
But I also don't have a better idea for now.
Right now this might be still fine, but I remember similar usecases where the conversion from state object to the url representation was quite complex.

We might need to abstract this in the future, so let's keep that in the back of our head =)

Mhh that is a bit annoying that we have to convert to strings here :/ But I also don't have a better idea for now. Right now this might be still fine, but I remember similar usecases where the conversion from state object to the url representation was quite complex. We might need to abstract this in the future, so let's keep that in the back of our head =)
},
})
},
setShowNulls(show) {
this.$router.push({
name: this.$route.name,
query: {
...this.$route.query,
showNulls: show,
},
})
},
async 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
@ -157,9 +166,6 @@ export default {
return
}
this.showOverdue = this.$route.query.showOverdue === 'true'
this.showNulls = this.$route.query.showNulls === 'true'
const params = {
sort_by: ['due_date', 'id'],
order_by: ['desc', 'desc'],