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
3 changed files with 6 additions and 6 deletions
Showing only changes of commit 60be8b428e - Show all commits

View File

@ -1,4 +1,4 @@
export const dateRanges = {
export const DATE_RANGES = {
konrad marked this conversation as resolved Outdated

Use UPPER_SNAKE_CASE for constants

Use UPPER_SNAKE_CASE for constants

Done.

Done.
// Format:
// Key is the title, as a translation string, the first entry of the value array
// is the "from" date, the second one is the "to" date.

View File

@ -11,7 +11,7 @@
{{ $t('misc.custom') }}
</BaseButton>
<BaseButton
v-for="(value, text) in dateRanges"
v-for="(value, text) in DATE_RANGES"
konrad marked this conversation as resolved Outdated

Use BaseButton

Use BaseButton

Done.

Done.
:key="text"
@click="setDateRange(value)"
:class="{'is-active': from === value[0] && to === value[1]}">
konrad marked this conversation as resolved Outdated

Use BaseButton

Use BaseButton

Done.

Done.
@ -78,7 +78,7 @@ import flatPickr from 'vue-flatpickr-component'
import 'flatpickr/dist/flatpickr.css'
import Popup from '@/components/misc/popup.vue'
import {dateRanges} from '@/components/date/dateRanges'
import {DATE_RANGES} from '@/components/date/dateRanges'
import BaseButton from '@/components/base/BaseButton.vue'
import DatemathHelp from '@/components/date/datemathHelp.vue'
@ -156,7 +156,7 @@ function setDateRange(range: string[] | null) {
}
const customRangeActive = computed<Boolean>(() => {
konrad marked this conversation as resolved Outdated

picky: el is a bit misleading here. We don't have elements

picky: `el` is a bit misleading here. We don't have elements

right, I've changed it.

right, I've changed it.
return !Object.values(dateRanges).some(el => from.value === el[0] && to.value === el[1])
return !Object.values(DateRanges).some(el => from.value === el[0] && to.value === el[1])
})
const buttonText = computed<string>(() => {

View File

@ -45,7 +45,6 @@
</template>
<script setup lang="ts">
import {dateRanges} from '@/components/date/dateRanges'
import SingleTaskInList from '@/components/tasks/partials/singleTaskInList.vue'
import {parseDateOrString} from '@/helpers/time/parseDateOrString'
import {mapState, useStore} from 'vuex'
@ -61,6 +60,7 @@ import {useRoute, useRouter} from 'vue-router'
import {formatDate} from '@/helpers/time/formatDate'
import {useI18n} from 'vue-i18n'
import {setTitle} from '@/helpers/setTitle'
import {DATE_RANGES} from '@/components/date/dateRanges'
function getNextWeekDate() {
return new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000)
@ -89,7 +89,7 @@ const pageTitle = computed(() => {
// We need to define "key" because it is the first parameter in the array and we need the second
konrad marked this conversation as resolved Outdated

Readd route props

Readd route props

Changed it to route props.

However, we still have a dependency on the router: every time when seleting a date in ShowTasks it will push the change to the route. I don't know how to change that without massively overengeneering everything so I'd say we leave it at that.

Changed it to route props. However, we still have a dependency on the router: every time when seleting a date in ShowTasks it will push the change to the route. I don't know how to change that without massively overengeneering everything so I'd say we leave it at that.

I think it's fine for now. I thought a while about this but also don't have a better soltion for this at the moment (except the v-model version)

I think it's fine for now. I thought a while about this but also don't have a better soltion for this at the moment (except the v-model version)
// eslint-disable-next-line no-unused-vars
const predefinedRange = Object.entries(dateRanges).find(([key, value]) => dateFrom.value === value[0] && dateTo.value === value[1])
const predefinedRange = Object.entries(DATE_RANGES).find(([key, value]) => dateFrom.value === value[0] && dateTo.value === value[1])
if (typeof predefinedRange !== 'undefined') {
title = t(`input.datepickerRange.ranges.${predefinedRange[0]}`)
} else {