2019-04-29 21:41:39 +00:00
|
|
|
<template>
|
2022-11-13 21:04:57 +00:00
|
|
|
<ProjectWrapper class="project-list" :project-id="projectId" viewName="project">
|
2021-11-14 20:33:53 +00:00
|
|
|
<template #header>
|
|
|
|
</template>
|
2020-03-04 19:27:27 +00:00
|
|
|
|
2021-11-14 20:33:53 +00:00
|
|
|
<template #default>
|
|
|
|
<div
|
|
|
|
:class="{ 'is-loading': loading }"
|
|
|
|
class="loader-container is-max-width-desktop list-view"
|
|
|
|
>
|
2021-01-24 14:37:19 +00:00
|
|
|
<card :padding="false" :has-content="false" class="has-overflow">
|
2022-11-17 15:35:18 +00:00
|
|
|
<add-task
|
2022-11-13 21:04:57 +00:00
|
|
|
v-if="!project.isArchived && canWrite"
|
2022-11-17 15:35:18 +00:00
|
|
|
class="list-view__add-task"
|
|
|
|
ref="addTaskRef"
|
|
|
|
:default-position="firstNewPosition"
|
|
|
|
@taskAdded="updateTaskList"
|
|
|
|
/>
|
2019-04-29 21:41:39 +00:00
|
|
|
|
2021-10-25 20:17:23 +00:00
|
|
|
<nothing v-if="ctaVisible && tasks.length === 0 && !loading">
|
2022-11-13 21:04:57 +00:00
|
|
|
{{ $t('project.list.empty') }}
|
2022-06-22 19:53:20 +00:00
|
|
|
<ButtonLink @click="focusNewTaskInput()">
|
2022-11-13 21:04:57 +00:00
|
|
|
{{ $t('project.list.newTaskCta') }}
|
2022-06-22 19:53:20 +00:00
|
|
|
</ButtonLink>
|
2021-01-30 16:17:04 +00:00
|
|
|
</nothing>
|
2020-07-04 17:12:15 +00:00
|
|
|
|
2022-11-17 15:35:18 +00:00
|
|
|
|
|
|
|
<draggable
|
|
|
|
v-if="tasks && tasks.length > 0"
|
|
|
|
v-bind="DRAG_OPTIONS"
|
|
|
|
v-model="tasks"
|
|
|
|
group="tasks"
|
|
|
|
@start="() => drag = true"
|
|
|
|
@end="saveTaskPosition"
|
|
|
|
handle=".handle"
|
|
|
|
:disabled="!canWrite"
|
|
|
|
item-key="id"
|
|
|
|
tag="ul"
|
|
|
|
:component-data="{
|
|
|
|
class: {
|
|
|
|
tasks: true,
|
|
|
|
'dragging-disabled': !canWrite || isAlphabeticalSorting
|
|
|
|
},
|
|
|
|
type: 'transition-group'
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
<template #item="{element: t}">
|
2022-11-13 21:04:57 +00:00
|
|
|
<single-task-in-project
|
2022-11-17 15:35:18 +00:00
|
|
|
:show-list-color="false"
|
2021-07-29 11:05:33 +00:00
|
|
|
:disabled="!canWrite"
|
2022-11-13 21:04:57 +00:00
|
|
|
:can-mark-as-done="canWrite || isSavedFilter(project)"
|
2022-11-17 15:35:18 +00:00
|
|
|
:the-task="t"
|
|
|
|
@taskUpdated="updateTasks"
|
2020-09-05 20:16:17 +00:00
|
|
|
>
|
2022-11-17 15:35:18 +00:00
|
|
|
<template v-if="canWrite">
|
|
|
|
<span class="icon handle">
|
|
|
|
<icon icon="grip-lines"/>
|
|
|
|
</span>
|
2021-08-20 13:46:41 +00:00
|
|
|
</template>
|
2022-11-13 21:04:57 +00:00
|
|
|
</single-task-in-project>
|
2022-11-17 15:35:18 +00:00
|
|
|
</template>
|
|
|
|
</draggable>
|
2019-12-03 18:09:12 +00:00
|
|
|
|
2021-10-25 20:17:23 +00:00
|
|
|
<Pagination
|
|
|
|
:total-pages="totalPages"
|
2021-09-21 19:03:38 +00:00
|
|
|
:current-page="currentPage"
|
|
|
|
/>
|
2021-01-24 13:00:21 +00:00
|
|
|
</card>
|
2021-11-14 20:33:53 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
2022-11-13 21:04:57 +00:00
|
|
|
</ProjectWrapper>
|
2019-04-29 21:41:39 +00:00
|
|
|
</template>
|
|
|
|
|
2022-02-15 12:07:34 +00:00
|
|
|
<script lang="ts">
|
2022-09-28 16:08:23 +00:00
|
|
|
export default { name: 'List' }
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-11-17 15:35:18 +00:00
|
|
|
import {ref, computed, toRef, nextTick, onMounted, type PropType} from 'vue'
|
2022-09-28 16:08:23 +00:00
|
|
|
import draggable from 'zhyswan-vuedraggable'
|
|
|
|
import {useRoute, useRouter} from 'vue-router'
|
2021-10-25 20:17:23 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
import ProjectWrapper from '@/components/project/ProjectWrapper.vue'
|
2022-06-22 19:53:20 +00:00
|
|
|
import ButtonLink from '@/components/misc/ButtonLink.vue'
|
2022-07-12 09:59:39 +00:00
|
|
|
import AddTask from '@/components/tasks/add-task.vue'
|
2022-11-13 21:04:57 +00:00
|
|
|
import SingleTaskInProject from '@/components/tasks/partials/singleTaskInProject.vue'
|
|
|
|
import FilterPopup from '@/components/project/partials/filter-popup.vue'
|
2021-07-25 13:27:15 +00:00
|
|
|
import Nothing from '@/components/misc/nothing.vue'
|
2021-09-21 19:03:38 +00:00
|
|
|
import Pagination from '@/components/misc/pagination.vue'
|
2022-11-13 21:04:57 +00:00
|
|
|
import {ALPHABETICAL_SORT} from '@/components/project/partials/filters.vue'
|
2019-04-29 21:41:39 +00:00
|
|
|
|
2022-10-27 13:47:48 +00:00
|
|
|
import {useTaskList} from '@/composables/useTaskList'
|
2022-09-28 16:08:23 +00:00
|
|
|
import {RIGHTS as Rights} from '@/constants/rights'
|
|
|
|
import {calculateItemPosition} from '@/helpers/calculateItemPosition'
|
2022-09-06 09:36:01 +00:00
|
|
|
import type {ITask} from '@/modelTypes/ITask'
|
2022-10-27 19:56:14 +00:00
|
|
|
import {isSavedFilter} from '@/services/savedFilter'
|
2022-09-24 13:20:40 +00:00
|
|
|
|
|
|
|
import {useBaseStore} from '@/stores/base'
|
2022-09-23 10:55:53 +00:00
|
|
|
import {useTaskStore} from '@/stores/tasks'
|
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
import type {IProject} from '@/modelTypes/IProject'
|
2021-07-28 19:56:29 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
const props = defineProps({
|
2022-11-13 21:04:57 +00:00
|
|
|
projectId: {
|
|
|
|
type: Number as PropType<IProject['id']>,
|
2022-09-28 16:08:23 +00:00
|
|
|
required: true,
|
2021-12-10 14:29:28 +00:00
|
|
|
},
|
2022-09-28 16:08:23 +00:00
|
|
|
})
|
2021-12-10 14:29:28 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
const ctaVisible = ref(false)
|
2021-07-28 19:56:29 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
const drag = ref(false)
|
|
|
|
const DRAG_OPTIONS = {
|
|
|
|
animation: 100,
|
2022-11-17 15:35:18 +00:00
|
|
|
ghostClass: 'task-ghost',
|
2022-09-28 16:08:23 +00:00
|
|
|
} as const
|
2021-10-03 13:54:24 +00:00
|
|
|
|
2023-03-22 16:19:59 +00:00
|
|
|
// TODO_OFFLINE load tasks from somewhere else
|
2022-09-28 16:08:23 +00:00
|
|
|
const {
|
|
|
|
tasks,
|
|
|
|
loading,
|
|
|
|
totalPages,
|
|
|
|
currentPage,
|
|
|
|
loadTasks,
|
2023-03-22 16:19:59 +00:00
|
|
|
// searchTerm,
|
|
|
|
// params,
|
|
|
|
// sortByParam,
|
2022-11-13 21:04:57 +00:00
|
|
|
} = useTaskList(toRef(props, 'projectId'), {position: 'asc' })
|
2021-11-01 17:19:59 +00:00
|
|
|
|
2021-07-28 19:56:29 +00:00
|
|
|
|
2023-03-22 16:19:59 +00:00
|
|
|
const isAlphabeticalSorting = computed(() => false)
|
2021-12-21 16:29:49 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
const firstNewPosition = computed(() => {
|
|
|
|
if (tasks.value.length === 0) {
|
|
|
|
return 0
|
|
|
|
}
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
return calculateItemPosition(null, tasks.value[0].position)
|
|
|
|
})
|
2021-11-13 19:48:06 +00:00
|
|
|
|
2022-09-23 10:55:53 +00:00
|
|
|
const taskStore = useTaskStore()
|
2022-09-24 13:20:40 +00:00
|
|
|
const baseStore = useBaseStore()
|
2022-11-13 21:04:57 +00:00
|
|
|
const project = computed(() => baseStore.currentProject)
|
2021-11-13 19:48:06 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
const canWrite = computed(() => {
|
2022-11-13 21:04:57 +00:00
|
|
|
return project.value.maxRight > Rights.READ && project.value.id > 0
|
2022-09-28 16:08:23 +00:00
|
|
|
})
|
2021-09-07 15:04:46 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
onMounted(async () => {
|
|
|
|
await nextTick()
|
|
|
|
ctaVisible.value = true
|
2021-12-10 14:29:28 +00:00
|
|
|
})
|
2022-09-28 16:08:23 +00:00
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
const router = useRouter()
|
2022-09-23 10:55:53 +00:00
|
|
|
|
2022-09-28 16:08:23 +00:00
|
|
|
const addTaskRef = ref<typeof AddTask | null>(null)
|
|
|
|
function focusNewTaskInput() {
|
|
|
|
addTaskRef.value?.focusTaskInput()
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateTaskList(task: ITask) {
|
|
|
|
if (isAlphabeticalSorting.value ) {
|
|
|
|
// reload tasks with current filter and sorting
|
2022-11-04 13:39:14 +00:00
|
|
|
loadTasks()
|
2022-09-28 16:08:23 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
tasks.value = [
|
|
|
|
task,
|
|
|
|
...tasks.value,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-09-24 13:20:40 +00:00
|
|
|
baseStore.setHasTasks(true)
|
2022-09-28 16:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateTasks(updatedTask: ITask) {
|
|
|
|
for (const t in tasks.value) {
|
|
|
|
if (tasks.value[t].id === updatedTask.id) {
|
|
|
|
tasks.value[t] = updatedTask
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveTaskPosition(e) {
|
|
|
|
drag.value = false
|
|
|
|
|
|
|
|
const task = tasks.value[e.newIndex]
|
|
|
|
const taskBefore = tasks.value[e.newIndex - 1] ?? null
|
|
|
|
const taskAfter = tasks.value[e.newIndex + 1] ?? null
|
|
|
|
|
|
|
|
const newTask = {
|
|
|
|
...task,
|
|
|
|
position: calculateItemPosition(taskBefore !== null ? taskBefore.position : null, taskAfter !== null ? taskAfter.position : null),
|
|
|
|
}
|
|
|
|
|
2022-09-23 10:55:53 +00:00
|
|
|
const updatedTask = await taskStore.update(newTask)
|
2022-09-29 09:44:58 +00:00
|
|
|
tasks.value[e.newIndex] = updatedTask
|
2022-09-28 16:08:23 +00:00
|
|
|
}
|
2021-07-17 21:21:46 +00:00
|
|
|
</script>
|
2021-10-18 12:21:02 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2022-11-17 15:35:18 +00:00
|
|
|
.tasks {
|
|
|
|
padding: .5rem;
|
|
|
|
}
|
2021-10-18 12:22:47 +00:00
|
|
|
|
2022-11-17 15:35:18 +00:00
|
|
|
.task-ghost {
|
|
|
|
border-radius: $radius;
|
|
|
|
background: var(--grey-100);
|
|
|
|
border: 2px dashed var(--grey-300);
|
|
|
|
|
|
|
|
* {
|
|
|
|
opacity: 0;
|
2021-10-18 12:22:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 15:35:18 +00:00
|
|
|
.list-view__add-task {
|
2021-10-18 12:21:02 +00:00
|
|
|
padding: 1rem 1rem 0;
|
|
|
|
}
|
2022-05-08 09:13:19 +00:00
|
|
|
|
|
|
|
.link-share-view .card {
|
|
|
|
border: none;
|
|
|
|
box-shadow: none;
|
|
|
|
}
|
2021-10-18 12:22:47 +00:00
|
|
|
</style>
|