feat: add more pre-defined ranges

This commit is contained in:
kolaente 2022-01-09 16:46:12 +01:00
parent e7fa1d3383
commit 0ae8a0e6ef
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
4 changed files with 43 additions and 20 deletions

View file

@ -1,10 +1,21 @@
// TODO: more ranges!
export const dateRanges = { export const dateRanges = {
'task.show.today': ['now/d', 'now/d+1d'], // Format:
'task.show.thisWeek': ['now/w', 'now/w+1w'], // Key is the title, as a translation string, the first entry of the value array
'task.show.nextWeek': ['now/w+1w', 'now/w+2w'], // is the "from" date, the second one is the "to" date.
'task.show.next7Days': ['now', 'now+7d'], 'today': ['now/d', 'now/d+1d'],
'task.show.thisMonth': ['now/M', 'now/M+1M'],
'task.show.nextMonth': ['now/M+1M', 'now/M+2M'], 'lastWeek': ['now/w-1w', 'now/w-2w'],
'task.show.next30Days': ['now', 'now+30d'], 'thisWeek': ['now/w', 'now/w+1w'],
'restOfThisWeek': ['now', 'now/w+1w'],
'nextWeek': ['now/w+1w', 'now/w+2w'],
'next7Days': ['now', 'now+7d'],
'lastMonth': ['now/M-1M', 'now/M-2M'],
'thisMonth': ['now/M', 'now/M+1M'],
'restOfThisMonth': ['now', 'now/M+1M'],
'nextMonth': ['now/M+1M', 'now/M+2M'],
'next30Days': ['now', 'now+30d'],
'thisYear': ['now/y', 'now/y+1y'],
'restOfThisYear': ['now', 'now/y+1y'],
} }

View file

@ -11,15 +11,15 @@
<template #content="{isOpen}"> <template #content="{isOpen}">
<div class="datepicker-with-range" :class="{'is-open': isOpen}"> <div class="datepicker-with-range" :class="{'is-open': isOpen}">
<div class="selections"> <div class="selections">
<button @click="setDateRange(null)" :class="{'is-active': customRangeActive}">
{{ $t('misc.custom') }}
</button>
<button <button
v-for="(value, text) in dateRanges" v-for="(value, text) in dateRanges"
:key="text" :key="text"
@click="setDateRange(value)" @click="setDateRange(value)"
:class="{'is-active': from === value[0] && to === value[1]}"> :class="{'is-active': from === value[0] && to === value[1]}">
{{ $t(text) }} {{ $t(`input.datepickerRange.ranges.${text}`) }}
</button>
<button @click="setDateRange(null)" :class="{'is-active': customRangeActive}">
{{ $t('misc.custom') }}
</button> </button>
</div> </div>
<div class="flatpickr-container input-group"> <div class="flatpickr-container input-group">
@ -324,6 +324,7 @@ const customRangeActive = computed<Boolean>(() => {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding-top: .5rem; padding-top: .5rem;
overflow-y: scroll;
button { button {
display: block; display: block;

View file

@ -556,6 +556,24 @@
"in30Days": "In 30 days", "in30Days": "In 30 days",
"datePlusMonth": "{0} plus one month at 00:00 of that day" "datePlusMonth": "{0} plus one month at 00:00 of that day"
} }
},
"ranges": {
"today": "Today",
"thisWeek": "This Week",
"restOfThisWeek": "The Rest of This Week",
"nextWeek": "Next Week",
"next7Days": "Next 7 Days",
"lastWeek": "Last Week",
"thisMonth": "This Month",
"restOfThisMonth": "The Rest of This Month",
"nextMonth": "Next Month",
"next30Days": "Next 30 Days",
"lastMonth": "Last Month",
"thisYear": "This Year",
"restOfThisYear": "The Rest of This Year"
} }
} }
}, },
@ -577,13 +595,6 @@
"overdue": "Show overdue tasks", "overdue": "Show overdue tasks",
"fromuntil": "Tasks from {from} until {until}", "fromuntil": "Tasks from {from} until {until}",
"select": "Select a date range", "select": "Select a date range",
"today": "Today",
"thisWeek": "This Week",
"nextWeek": "Next Week",
"next7Days": "Next 7 Days",
"thisMonth": "This Month",
"nextMonth": "Next Month",
"next30Days": "Next 30 Days",
"noTasks": "Nothing to do — Have a nice day!" "noTasks": "Nothing to do — Have a nice day!"
}, },
"detail": { "detail": {

View file

@ -111,7 +111,7 @@ export default {
const predefinedRange = Object.entries(dateRanges).find(([key, value]) => this.dateFrom === value[0] && this.dateTo === value[1]) const predefinedRange = Object.entries(dateRanges).find(([key, value]) => this.dateFrom === value[0] && this.dateTo === value[1])
if (typeof predefinedRange !== 'undefined') { if (typeof predefinedRange !== 'undefined') {
title = this.$t(predefinedRange[0]) title = this.$t(`input.datepickerRange.ranges.${predefinedRange[0]}`)
} else { } else {
title = this.showAll title = this.showAll
? this.$t('task.show.titleCurrent') ? this.$t('task.show.titleCurrent')