feat: replace our home-grown gantt implementation with ganttastic #2180

Merged
konrad merged 78 commits from feature/ganttastic into main 2022-10-27 16:03:27 +00:00
2 changed files with 68 additions and 2 deletions
Showing only changes of commit ef4689335b - Show all commits

View File

@ -15,17 +15,42 @@
:bars="bar"
/>
</g-gantt-chart>
<form
@submit.prevent="createTask()"
class="add-new-task"
v-if="canWrite"
>
<transition name="width">
<input
@blur="hideCreateNewTask"
@keyup.esc="newTaskFieldActive = false"
class="input"
ref="newTaskTitleField"
type="text"
v-if="newTaskFieldActive"
v-model="newTaskTitle"
/>
</transition>
<x-button @click="showCreateNewTask" :shadow="false" icon="plus">
{{ $t('list.list.newTaskCta') }}
</x-button>
</form>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import {computed, nextTick, ref} from 'vue'
import TaskCollectionService from '@/services/taskCollection'
import {format} from 'date-fns'
import {colorIsDark} from '@/helpers/color/colorIsDark'
import TaskService from '@/services/task'
import {useStore} from 'vuex'
import Rights from '../../models/constants/rights.json'
import TaskModel from '@/models/task'
const dateFormat = 'yyyy-LL-dd kk:mm'
const store = useStore()
const props = defineProps({
listId: {
type: Number,
@ -45,6 +70,8 @@ const props = defineProps({
},
})
const canWrite = computed(() => store.state.currentList.maxRight > Rights.READ)
const tasks = ref([])
const ganttBars = ref([])
@ -54,6 +81,7 @@ const defaultEndDate = format(new Date((new Date()).setDate((new Date()).getDate
// We need a "real" ref object for the gantt bars to instantly update the tasks when they are dragged on the chart.
// A computed won't work directly.
function mapGanttBars() {
ganttBars.value = []
tasks.value.forEach(t => ganttBars.value.push([{
startDate: t.startDate ? format(t.startDate, dateFormat) : defaultStartDate,
endDate: t.endDate ? format(t.endDate, dateFormat) : defaultEndDate,
@ -113,6 +141,45 @@ async function updateTask(e) {
await taskService.update(task)
// TODO: Loading animation
}
konrad marked this conversation as resolved Outdated

define types

define types

Done.

Done.
const newTaskFieldActive = ref(false)
const newTaskTitleField = ref()
const newTaskTitle = ref('')
function showCreateNewTask() {
if (!newTaskFieldActive.value) {
// Timeout to not send the form if the field isn't even shown
setTimeout(() => {
newTaskFieldActive.value = true
nextTick(() => newTaskTitleField.value.focus())
}, 100)
}
}
function hideCreateNewTask() {
if (newTaskTitle.value === '') {
nextTick(() => (newTaskFieldActive.value = false))
}
}
async function createTask() {
if (!newTaskFieldActive.value) {
return
}
let task = new TaskModel({
title: newTaskTitle.value,
listId: props.listId,
startDate: defaultStartDate,
endDate: defaultEndDate,
})
const taskService = new TaskService()
konrad marked this conversation as resolved Outdated

This and the three lines below should be combined to one watcher that trigger immediately.

loadTasks should accept these three as params, so that it's clear that these are needed to reload.

Something like:

watchEffect(() => loadTasks({
	dateTo: props.dateTo,
    dateFrom: props.dateFrom,
    showTasksWithoutDates: props.showTasksWithoutDates,
})
This and the three lines below should be combined to one watcher that trigger immediately. `loadTasks` should accept these three as params, so that it's clear that these are needed to reload. Something like: ``` watchEffect(() => loadTasks({ dateTo: props.dateTo, dateFrom: props.dateFrom, showTasksWithoutDates: props.showTasksWithoutDates, }) ```

Done.

Done.
const r = await taskService.create(task)
tasks.value.set(r.id, r)
mapGanttBars()
newTaskTitle.value = ''
hideCreateNewTask()
}
</script>
<style>

View File

@ -56,7 +56,6 @@
:date-to="dateTo"
:precision="precision"
:list-id="props.listId"
:show-taskswithout-dates="showTaskswithoutDates"
/>
</card>