This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/views/list/ListGantt.vue

277 lines
6.7 KiB
Vue
Raw Normal View History

2019-04-29 21:41:39 +00:00
<template>
2022-10-11 11:22:57 +00:00
<ListWrapper class="list-gantt" :list-id="filters.listId" viewName="gantt">
2021-11-14 20:33:53 +00:00
<template #header>
<card>
<div class="gantt-options">
2022-08-02 12:09:29 +00:00
<div class="field">
<label class="label" for="range">{{ $t('list.gantt.range') }}</label>
<div class="control">
2022-10-10 19:44:59 +00:00
<Foo
ref="flatPickerEl"
2022-08-02 12:09:29 +00:00
:config="flatPickerConfig"
class="input"
id="range"
:placeholder="$t('list.gantt.range')"
2022-10-10 19:44:59 +00:00
v-model="flatPickerDateRange"
2022-08-02 12:09:29 +00:00
/>
</div>
2019-04-29 21:41:39 +00:00
</div>
2022-10-11 11:22:57 +00:00
<fancycheckbox class="is-block" v-model="filters.showTasksWithoutDates">
{{ $t('list.gantt.showTasksWithoutDates') }}
</fancycheckbox>
2019-04-29 21:41:39 +00:00
</div>
</card>
2021-11-14 20:33:53 +00:00
</template>
2021-11-14 20:33:53 +00:00
<template #default>
<div class="gantt-chart-container">
<card :padding="false" class="has-overflow">
2022-10-17 14:11:57 +00:00
<gantt-chart
2022-10-11 11:22:57 +00:00
:list-id="filters.listId"
2022-10-17 20:28:01 +00:00
:date-from="filters.dateFrom"
:date-to="filters.dateTo"
2022-10-17 21:20:52 +00:00
:show-tasks-without-dates="filters.showTasksWithoutDates"
2022-10-17 14:11:57 +00:00
/>
</card>
</div>
2021-11-14 20:33:53 +00:00
</template>
</ListWrapper>
2019-04-29 21:41:39 +00:00
</template>
2021-12-10 14:29:28 +00:00
<script setup lang="ts">
2022-10-17 21:20:52 +00:00
import {computed, reactive, ref, watch} from 'vue'
2022-10-10 19:44:59 +00:00
import Foo from '@/components/misc/flatpickr/Flatpickr.vue'
2022-10-11 11:22:57 +00:00
import type Flatpickr from 'flatpickr'
import {useI18n} from 'vue-i18n'
2022-10-17 21:20:52 +00:00
import {useRoute, useRouter, type RouteLocationNormalized, type RouteLocationRaw} from 'vue-router'
import cloneDeep from 'lodash.clonedeep'
2022-09-21 01:37:39 +00:00
import {useAuthStore} from '@/stores/auth'
2021-11-01 17:19:59 +00:00
2021-12-10 14:29:28 +00:00
import ListWrapper from './ListWrapper.vue'
import Fancycheckbox from '@/components/input/fancycheckbox.vue'
2022-10-10 19:44:59 +00:00
import {createAsyncComponent} from '@/helpers/createAsyncComponent'
2022-10-17 21:20:52 +00:00
import {isoToKebabDate} from '@/helpers/time/isoToKebabDate'
2022-10-10 19:44:59 +00:00
2022-10-17 21:20:52 +00:00
import type {IList} from '@/modelTypes/IList'
import type {DateISO} from '@/types/DateISO'
import type {DateKebab} from '@/types/DateKebab'
2022-10-11 11:22:57 +00:00
2022-10-17 21:20:52 +00:00
// convenient internal filter object
2022-10-11 11:22:57 +00:00
export interface GanttFilter {
listId: IList['id']
dateFrom: DateISO
dateTo: DateISO
showTasksWithoutDates: boolean
}
type Options = Flatpickr.Options.Options
2022-10-10 19:44:59 +00:00
2022-10-17 21:20:52 +00:00
const GanttChart = createAsyncComponent(() => import('@/components/tasks/gantt-chart.vue'))
2021-12-10 14:29:28 +00:00
2022-10-17 21:20:52 +00:00
const props = defineProps<{route: RouteLocationNormalized}>()
2021-11-01 17:19:59 +00:00
2022-10-10 19:44:59 +00:00
const router = useRouter()
const route = useRoute()
2022-10-11 11:22:57 +00:00
function parseDateProp(kebabDate: DateKebab | undefined): string | undefined {
2022-10-10 19:44:59 +00:00
try {
if (!kebabDate) {
throw new Error('No value')
}
const dateValues = kebabDate.split('-')
const [, monthString, dateString] = dateValues
const [year, month, date] = dateValues.map(val => Number(val))
const dateValuesAreValid = (
!Number.isNaN(year) &&
monthString.length >= 1 && monthString.length <= 2 &&
!Number.isNaN(month) &&
month >= 1 && month <= 12 &&
dateString.length >= 1 && dateString.length <= 31 &&
!Number.isNaN(date) &&
date >= 1 && date <= 31
)
if (!dateValuesAreValid) {
throw new Error('Invalid date values')
}
2022-10-11 11:22:57 +00:00
return new Date(year, month, date).toISOString()
2022-10-10 19:44:59 +00:00
} catch(e) {
// ignore nonsense route queries
2022-10-11 11:22:57 +00:00
return
2022-10-10 19:44:59 +00:00
}
}
2022-10-11 11:22:57 +00:00
function parseBooleanProp(booleanProp: string) {
return (booleanProp === 'false' || booleanProp === '0')
? false
: Boolean(booleanProp)
}
const DEFAULT_SHOW_TASKS_WITHOUT_DATES = false
2022-10-17 14:11:57 +00:00
const DEFAULT_DATEFROM_DAY_OFFSET = -15
2022-10-10 19:44:59 +00:00
const DEFAULT_DATETO_DAY_OFFSET = +55
2021-11-01 17:19:59 +00:00
const now = new Date()
2022-10-10 19:44:59 +00:00
function getDefaultDateFrom() {
2022-10-11 11:22:57 +00:00
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + DEFAULT_DATEFROM_DAY_OFFSET).toISOString()
2022-10-10 19:44:59 +00:00
}
function getDefaultDateTo() {
2022-10-11 11:22:57 +00:00
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + DEFAULT_DATETO_DAY_OFFSET).toISOString()
2022-10-10 19:44:59 +00:00
}
2022-10-11 11:22:57 +00:00
function routeToFilter(route: RouteLocationNormalized): GanttFilter {
return {
listId: Number(route.params.listId as string),
dateFrom: parseDateProp(route.query.dateFrom as DateKebab) || getDefaultDateFrom(),
dateTo: parseDateProp(route.query.dateTo as DateKebab) || getDefaultDateTo(),
showTasksWithoutDates: parseBooleanProp(route.query.showTasksWithoutDates as string) || DEFAULT_SHOW_TASKS_WITHOUT_DATES,
}
}
2022-10-10 19:44:59 +00:00
2022-10-11 11:22:57 +00:00
function filterToRoute(filters: GanttFilter): RouteLocationRaw {
let query: Record<string, string> = {}
if (
filters.dateFrom !== getDefaultDateFrom() ||
filters.dateTo !== getDefaultDateTo()
) {
query = {
2022-10-17 14:11:57 +00:00
dateFrom: isoToKebabDate(filters.dateFrom),
dateTo: isoToKebabDate(filters.dateTo),
2022-10-10 19:44:59 +00:00
}
2022-10-11 11:22:57 +00:00
}
2022-10-10 19:44:59 +00:00
2022-10-11 11:22:57 +00:00
if (filters.showTasksWithoutDates) {
query.showTasksWithoutDates = String(filters.showTasksWithoutDates)
}
2022-10-10 19:44:59 +00:00
2022-10-11 11:22:57 +00:00
return {
name: 'list.gantt',
params: {listId: filters.listId},
2022-10-17 21:20:52 +00:00
query,
2022-10-11 11:22:57 +00:00
}
}
2022-10-10 19:44:59 +00:00
2022-10-11 11:22:57 +00:00
const filters: GanttFilter = reactive(routeToFilter(route))
2022-10-17 21:20:52 +00:00
watch(() => cloneDeep(props.route), (route, oldRoute) => {
2022-10-11 11:22:57 +00:00
if (route.name !== oldRoute.name) {
return
}
const filterFullPath = router.resolve(filterToRoute(filters)).fullPath
if (filterFullPath === route.fullPath) {
return
}
Object.assign(filters, routeToFilter(route))
2022-10-10 19:44:59 +00:00
})
2022-10-11 11:22:57 +00:00
watch(
filters,
async () => {
const newRouteFullPath = router.resolve(filterToRoute(filters)).fullPath
if (newRouteFullPath !== route.fullPath) {
await router.push(newRouteFullPath)
}
},
2022-10-17 21:20:52 +00:00
// only apply new route after all filters have changed in component cycle
{flush: 'post'},
2022-10-11 11:22:57 +00:00
)
2022-10-10 19:44:59 +00:00
2022-10-17 21:20:52 +00:00
const flatPickerEl = ref<typeof Foo | null>(null)
const flatPickerDateRange = computed<Date[]>({
2022-10-10 19:44:59 +00:00
get: () => ([
2022-10-17 21:20:52 +00:00
new Date(filters.dateFrom),
new Date(filters.dateTo),
2022-10-10 19:44:59 +00:00
]),
set(newVal) {
2022-10-11 11:22:57 +00:00
const [dateFrom, dateTo] = newVal.map((date) => date?.toISOString())
2022-10-10 19:44:59 +00:00
2022-10-11 11:22:57 +00:00
// only set after whole range has been selected
if (!dateTo) return
Object.assign(filters, {dateFrom, dateTo})
2022-10-17 21:20:52 +00:00
},
2022-10-10 19:44:59 +00:00
})
2022-10-11 11:22:57 +00:00
const initialDateRange = [filters.dateFrom, filters.dateTo]
const {t} = useI18n({useScope: 'global'})
2022-09-21 01:37:39 +00:00
const authStore = useAuthStore()
2022-10-11 11:22:57 +00:00
const flatPickerConfig = computed<Options>(() => ({
2021-12-07 18:40:50 +00:00
altFormat: t('date.altFormatShort'),
2021-11-01 17:19:59 +00:00
altInput: true,
2022-10-10 19:44:59 +00:00
defaultDate: initialDateRange,
2021-11-01 17:19:59 +00:00
enableTime: false,
mode: 'range',
2021-11-01 17:19:59 +00:00
locale: {
2022-09-21 01:37:39 +00:00
firstDayOfWeek: authStore.settings.weekStart,
},
2021-11-01 17:19:59 +00:00
}))
</script>
<style lang="scss">
.gantt-chart-container {
padding-bottom: 1rem;
}
.gantt-options {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
@media screen and (max-width: $tablet) {
flex-direction: column;
}
2022-08-02 12:09:29 +00:00
.field {
margin-bottom: 0;
width: 33%;
&:not(:last-child) {
padding-right: .5rem;
}
@media screen and (max-width: $tablet) {
width: 100%;
2022-08-02 12:09:29 +00:00
max-width: 100%;
margin-top: .5rem;
padding-right: 0 !important;
}
2022-08-02 12:09:29 +00:00
&, .input {
font-size: .8rem;
}
2022-08-02 12:09:29 +00:00
.select, .select select {
height: auto;
width: 100%;
font-size: .8rem;
}
2022-08-02 12:09:29 +00:00
.label {
font-size: .9rem;
}
}
}
// vue-draggable overwrites
.vdr.active::before {
display: none;
}
.link-share-view:not(.has-background) .card.gantt-options {
border: none;
box-shadow: none;
.card-content {
padding: .5rem;
}
}
</style>