feat: working gantt-chart
This commit is contained in:
parent
0b194bb0cf
commit
eaf777864a
@ -1,13 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Loading
|
<Loading
|
||||||
v-if="taskService.loading || taskCollectionService.loading || dayjsLanguageLoading"
|
v-if="taskCollectionService.loading || dayjsLanguageLoading"
|
||||||
class="gantt-container"
|
class="gantt-container"
|
||||||
/>
|
/>
|
||||||
<div class="gantt-container" v-else>
|
<div class="gantt-container" v-else>
|
||||||
<GGanttChart
|
<GGanttChart
|
||||||
:chart-start="`${props.dateFrom} 00:00`"
|
:date-format="DAYJS_ISO_DATE_FORMAT"
|
||||||
:chart-end="`${props.dateTo} 23:59`"
|
:chart-start="isoToKebabDate(props.dateFrom)"
|
||||||
|
:chart-end="isoToKebabDate(props.dateTo)"
|
||||||
precision="day"
|
precision="day"
|
||||||
bar-start="startDate"
|
bar-start="startDate"
|
||||||
bar-end="endDate"
|
bar-end="endDate"
|
||||||
@ -40,11 +41,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {computed, ref, watch, watchEffect, shallowReactive} from 'vue'
|
import {computed, ref, watch, watchEffect, shallowReactive, type CSSProperties} from 'vue'
|
||||||
import {useRouter} from 'vue-router'
|
import {useRouter} from 'vue-router'
|
||||||
import {format, parse} from 'date-fns'
|
import {format, parse} from 'date-fns'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import isToday from 'dayjs/plugin/isToday'
|
import isToday from 'dayjs/plugin/isToday'
|
||||||
|
import cloneDeep from 'lodash.clonedeep'
|
||||||
|
|
||||||
import {useDayjsLanguageSync} from '@/i18n'
|
import {useDayjsLanguageSync} from '@/i18n'
|
||||||
import TaskCollectionService from '@/services/taskCollection'
|
import TaskCollectionService from '@/services/taskCollection'
|
||||||
@ -68,6 +70,7 @@ import Loading from '@/components/misc/loading.vue'
|
|||||||
import TaskForm from '@/components/tasks/TaskForm.vue'
|
import TaskForm from '@/components/tasks/TaskForm.vue'
|
||||||
|
|
||||||
import {useBaseStore} from '@/stores/base'
|
import {useBaseStore} from '@/stores/base'
|
||||||
|
import { error, success } from '@/message'
|
||||||
|
|
||||||
export type DateRange = {
|
export type DateRange = {
|
||||||
dateFrom: string,
|
dateFrom: string,
|
||||||
@ -84,6 +87,8 @@ export interface GanttChartProps {
|
|||||||
|
|
||||||
// export const DATE_FORMAT = 'yyyy-LL-dd HH:mm'
|
// export const DATE_FORMAT = 'yyyy-LL-dd HH:mm'
|
||||||
|
|
||||||
|
const DAYJS_ISO_DATE_FORMAT = 'YYYY-MM-DD'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<GanttChartProps>(), {
|
const props = withDefaults(defineProps<GanttChartProps>(), {
|
||||||
showTasksWithoutDates: false,
|
showTasksWithoutDates: false,
|
||||||
})
|
})
|
||||||
@ -100,12 +105,12 @@ const router = useRouter()
|
|||||||
const taskCollectionService = shallowReactive(new TaskCollectionService())
|
const taskCollectionService = shallowReactive(new TaskCollectionService())
|
||||||
const taskService = shallowReactive(new TaskService())
|
const taskService = shallowReactive(new TaskService())
|
||||||
|
|
||||||
const dateFromDate = computed(() => parse(props.dateFrom, 'yyyy-LL-dd', new Date(new Date().setHours(0,0,0,0))))
|
const dateFromDate = computed(() => new Date(new Date(props.dateFrom).setHours(0,0,0,0)))
|
||||||
const dateToDate = computed(() => parse(props.dateTo, 'yyyy-LL-dd', new Date(new Date().setHours(23,59,0,0))))
|
const dateToDate = computed(() => new Date(new Date(props.dateTo).setHours(23,59,0,0)))
|
||||||
|
|
||||||
const DAY_WIDTH_PIXELS = 30
|
const DAY_WIDTH_PIXELS = 30
|
||||||
const ganttChartWidth = computed(() => {
|
const ganttChartWidth = computed(() => {
|
||||||
const dateDiff = Math.floor((dateToDate.value - dateFromDate.value) / (1000 * 60 * 60 * 24))
|
const dateDiff = Math.floor((dateToDate.value.valueOf() - dateFromDate.value.valueOf()) / (1000 * 60 * 60 * 24))
|
||||||
|
|
||||||
return dateDiff * DAY_WIDTH_PIXELS
|
return dateDiff * DAY_WIDTH_PIXELS
|
||||||
})
|
})
|
||||||
@ -131,15 +136,16 @@ function isoToKebabDate(isoDate: DateISO) {
|
|||||||
return format(new Date(isoDate), DATE_FORMAT_KEBAB) as DateKebab
|
return format(new Date(isoDate), DATE_FORMAT_KEBAB) as DateKebab
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultStartDate = new Date().toISOString()
|
const now = new Date()
|
||||||
const defaultEndDate = new Date((new Date()).setDate((new Date()).getDate() + 7)).toISOString()
|
const defaultStartDate = new Date(now)
|
||||||
|
const defaultEndDate = new Date(now.setDate(now.getDate() + 7))
|
||||||
|
|
||||||
function transformTaskToGanttBar(t: ITask) {
|
function transformTaskToGanttBar(t: ITask) {
|
||||||
const black = 'var(--grey-800)'
|
const black = 'var(--grey-800)'
|
||||||
console.log(t)
|
console.log(t)
|
||||||
return [{
|
return [{
|
||||||
startDate: isoToKebabDate(new Date(t.startDate ? t.startDate : defaultStartDate).toISOString()),
|
startDate: isoToKebabDate(t.startDate ? t.startDate.toISOString() : defaultStartDate.toISOString()),
|
||||||
endDate: isoToKebabDate(new Date(t.endDate ? t.endDate : defaultEndDate).toISOString()),
|
endDate: isoToKebabDate(t.endDate ? t.endDate.toISOString() : defaultEndDate.toISOString()),
|
||||||
ganttBarConfig: {
|
ganttBarConfig: {
|
||||||
id: String(t.id),
|
id: String(t.id),
|
||||||
label: t.title,
|
label: t.title,
|
||||||
@ -190,7 +196,7 @@ async function loadTasks({
|
|||||||
order_by: ['asc', 'asc', 'desc'],
|
order_by: ['asc', 'asc', 'desc'],
|
||||||
filter_by: ['start_date', 'start_date'],
|
filter_by: ['start_date', 'start_date'],
|
||||||
filter_comparator: ['greater_equals', 'less_equals'],
|
filter_comparator: ['greater_equals', 'less_equals'],
|
||||||
filter_value: [dateFrom, dateTo],
|
filter_value: [isoToKebabDate(dateFrom), isoToKebabDate(dateTo)],
|
||||||
filter_concat: 'and',
|
filter_concat: 'and',
|
||||||
filter_include_nulls: showTasksWithoutDates,
|
filter_include_nulls: showTasksWithoutDates,
|
||||||
}
|
}
|
||||||
@ -227,20 +233,35 @@ async function updateTask(e: {
|
|||||||
|
|
||||||
if (!task) return
|
if (!task) return
|
||||||
|
|
||||||
console.log(task.startDate.toISOString())
|
|
||||||
console.log(dayjs(task.startDate), "YYYY-MM-DD HH:mm").toISOString()
|
|
||||||
console.log(dayjs(task.startDate, "YYYY-MM-DDTHH:mm:ssZ[Z]").toISOString())
|
|
||||||
console.log(task.startDate)
|
|
||||||
console.log(dayjs(e.bar.startDate).toDate())
|
|
||||||
console.log(e.bar.startDate)
|
|
||||||
console.log(task.endDate.toISOString())
|
|
||||||
console.log(task.endDate)
|
|
||||||
console.log(dayjs(e.bar.startDate).toDate())
|
|
||||||
console.log(e.bar.endDate)
|
|
||||||
|
|
||||||
// task.startDate = e.bar.startDate
|
const startDate = parse(e.bar.startDate, 'yyyy-MM-dd', new Date())
|
||||||
// task.endDate = e.bar.endDate
|
const endDate = parse(e.bar.endDate, 'yyyy-MM-dd', new Date())
|
||||||
const updatedTask = await taskService.update(task)
|
|
||||||
|
const oldTask = cloneDeep(task)
|
||||||
|
|
||||||
|
const newTask: ITask = {
|
||||||
|
...task,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
}
|
||||||
|
|
||||||
|
const newTaskCopy = cloneDeep(task)
|
||||||
|
|
||||||
|
tasks.value.set(newTask.id, newTask)
|
||||||
|
|
||||||
|
// try {
|
||||||
|
const updatedTask = await taskService.update(newTask)
|
||||||
|
// tasks.value.set(updatedTask.id, updatedTask)
|
||||||
|
success('Saved')
|
||||||
|
// } catch(e: any) {
|
||||||
|
// error('Saved')
|
||||||
|
// tasks.value.set(task.id, oldTask)
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// for (let [idStr, currentTask] of tasks.value) {
|
||||||
|
// const id: ITask['id'] = Number(idStr)
|
||||||
|
// }
|
||||||
|
|
||||||
// ganttBars.value.map(gantBar => {
|
// ganttBars.value.map(gantBar => {
|
||||||
// return Number(gantBar[0].ganttBarConfig.id) === task.id
|
// return Number(gantBar[0].ganttBarConfig.id) === task.id
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
<pre>{{new Date(dateRange.dateTo).toISOString()}}</pre>
|
<pre>{{new Date(dateRange.dateTo).toISOString()}}</pre>
|
||||||
<gantt-chart
|
<gantt-chart
|
||||||
:list-id="filters.listId"
|
:list-id="filters.listId"
|
||||||
:date-from="isoToKebabDate(filters.dateFrom)"
|
:date-from="filters.dateFrom"
|
||||||
:date-to="isoToKebabDate(filters.dateTo)"
|
:date-to="filters.dateTo"
|
||||||
:show-tasks-without-dates="showTasksWithoutDates"
|
:show-tasks-without-dates="showTasksWithoutDates"
|
||||||
/>
|
/>
|
||||||
</card>
|
</card>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user