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

197 lines
4.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 :has-content="false">
<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-24 13:51:50 +00:00
<div class="field" v-if="!hasDefaultFilters">
<label class="label" for="range">Reset</label>
<div class="control">
<x-button @click="setDefaultFilters">Reset</x-button>
</div>
</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 :has-content="false" :padding="false" class="has-overflow">
<gantt-chart
:filters="filters"
:tasks="tasks"
:isLoading="isLoading"
:default-task-start-date="defaultTaskStartDate"
:default-task-end-date="defaultTaskEndDate"
@update:task="updateTask"
/>
<TaskForm v-if="canWrite" @create-task="addGanttTask" />
</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">
import {computed, ref, toRefs} from 'vue'
2022-10-11 11:22:57 +00:00
import type Flatpickr from 'flatpickr'
import {useI18n} from 'vue-i18n'
import type {RouteLocationNormalized} from 'vue-router'
2022-09-21 01:37:39 +00:00
import {useBaseStore} from '@/stores/base'
2022-09-21 01:37:39 +00:00
import {useAuthStore} from '@/stores/auth'
2021-11-01 17:19:59 +00:00
import Foo from '@/components/misc/flatpickr/Flatpickr.vue'
import ListWrapper from '@/components/list/ListWrapper.vue'
2021-12-10 14:29:28 +00:00
import Fancycheckbox from '@/components/input/fancycheckbox.vue'
import TaskForm from '@/components/tasks/TaskForm.vue'
2022-10-10 19:44:59 +00:00
import {createAsyncComponent} from '@/helpers/createAsyncComponent'
import {useGanttFilters} from './helpers/useGanttFilters'
import {RIGHTS} from '@/constants/rights'
import type {DateISO} from '@/types/DateISO'
import type {ITask} from '@/modelTypes/ITask'
2022-10-11 11:22:57 +00:00
type Options = Flatpickr.Options.Options
2022-10-10 19:44:59 +00:00
const GanttChart = createAsyncComponent(() => import('@/components/tasks/GanttChart.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
const baseStore = useBaseStore()
const canWrite = computed(() => baseStore.currentList.maxRight > RIGHTS.READ)
const {route} = toRefs(props)
const {
filters,
2022-10-24 13:51:50 +00:00
hasDefaultFilters,
setDefaultFilters,
tasks,
isLoading,
addTask,
updateTask,
} = useGanttFilters(route)
2022-11-09 17:33:06 +00:00
const DEFAULT_DATE_RANGE_DAYS = 7
const today = new Date()
const defaultTaskStartDate: DateISO = new Date(today.setHours(0, 0, 0, 0)).toISOString()
const defaultTaskEndDate: DateISO = new Date(new Date(
today.getFullYear(),
today.getMonth(),
today.getDate() + DEFAULT_DATE_RANGE_DAYS,
).setHours(23, 59, 0, 0)).toISOString()
async function addGanttTask(title: ITask['title']) {
return await addTask({
title,
2022-10-19 14:48:26 +00:00
listId: filters.value.listId,
startDate: defaultTaskStartDate,
endDate: defaultTaskEndDate,
})
}
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-19 14:48:26 +00:00
new Date(filters.value.dateFrom),
new Date(filters.value.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
2022-10-19 14:48:26 +00:00
Object.assign(filters.value, {dateFrom, dateTo})
2022-10-17 21:20:52 +00:00
},
2022-10-10 19:44:59 +00:00
})
2022-10-19 14:48:26 +00:00
const initialDateRange = [filters.value.dateFrom, filters.value.dateTo]
2022-10-11 11:22:57 +00:00
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>
2022-10-19 13:19:11 +00:00
<style lang="scss" scoped>
.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-10-18 13:55:53 +00:00
}
2022-10-19 13:19:11 +00:00
:global(.link-share-view:not(.has-background)) .gantt-options {
border: none;
box-shadow: none;
.card-content {
padding: .5rem;
}
}
2022-10-18 13:55:53 +00:00
.field {
margin-bottom: 0;
width: 33%;
2022-10-18 13:55:53 +00:00
&:not(:last-child) {
padding-right: .5rem;
}
2022-10-18 13:55:53 +00:00
@media screen and (max-width: $tablet) {
width: 100%;
max-width: 100%;
margin-top: .5rem;
padding-right: 0 !important;
}
2022-10-18 13:55:53 +00:00
&, .input {
font-size: .8rem;
}
2022-10-19 13:19:11 +00:00
.select,
.select select {
2022-10-18 13:55:53 +00:00
height: auto;
width: 100%;
font-size: .8rem;
}
2022-10-18 13:55:53 +00:00
.label {
font-size: .9rem;
}
}
</style>