feat: migrate kanban card to script setup (#2459)
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2459 Reviewed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
commit
3e21a8ed6e
2 changed files with 43 additions and 68 deletions
|
@ -6,13 +6,13 @@
|
||||||
'draggable': !(loadingInternal || loading),
|
'draggable': !(loadingInternal || loading),
|
||||||
'has-light-text': color !== TASK_DEFAULT_COLOR && !colorIsDark(color),
|
'has-light-text': color !== TASK_DEFAULT_COLOR && !colorIsDark(color),
|
||||||
}"
|
}"
|
||||||
:style="{'background-color': color !== TASK_DEFAULT_COLOR ? color : false}"
|
:style="{'background-color': color !== TASK_DEFAULT_COLOR ? color : undefined}"
|
||||||
@click.exact="openTaskDetail()"
|
@click.exact="openTaskDetail()"
|
||||||
@click.ctrl="() => toggleTaskDone(task)"
|
@click.ctrl="() => toggleTaskDone(task)"
|
||||||
@click.meta="() => toggleTaskDone(task)"
|
@click.meta="() => toggleTaskDone(task)"
|
||||||
>
|
>
|
||||||
<span class="task-id">
|
<span class="task-id">
|
||||||
<Done class="kanban-card__done" :is-done="task.done" variant="small" />
|
<Done class="kanban-card__done" :is-done="task.done" variant="small"/>
|
||||||
<template v-if="task.identifier === ''">
|
<template v-if="task.identifier === ''">
|
||||||
#{{ task.index }}
|
#{{ task.index }}
|
||||||
</template>
|
</template>
|
||||||
|
@ -44,11 +44,11 @@
|
||||||
<priority-label :priority="task.priority" :done="task.done"/>
|
<priority-label :priority="task.priority" :done="task.done"/>
|
||||||
<div class="assignees" v-if="task.assignees.length > 0">
|
<div class="assignees" v-if="task.assignees.length > 0">
|
||||||
<user
|
<user
|
||||||
|
v-for="u in task.assignees"
|
||||||
:avatar-size="24"
|
:avatar-size="24"
|
||||||
:key="task.id + 'assignee' + u.id"
|
:key="task.id + 'assignee' + u.id"
|
||||||
:show-username="false"
|
:show-username="false"
|
||||||
:user="u"
|
:user="u"
|
||||||
v-for="u in task.assignees"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<checklist-summary :task="task"/>
|
<checklist-summary :task="task"/>
|
||||||
|
@ -65,80 +65,55 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import {defineComponent, type PropType} from 'vue'
|
import {ref, computed} from 'vue'
|
||||||
|
import {useRouter} from 'vue-router'
|
||||||
|
|
||||||
import PriorityLabel from '../../../components/tasks/partials/priorityLabel.vue'
|
import PriorityLabel from '@/components/tasks/partials/priorityLabel.vue'
|
||||||
import User from '../../../components/misc/user.vue'
|
import User from '@/components/misc/user.vue'
|
||||||
import Done from '@/components/misc/Done.vue'
|
import Done from '@/components/misc/Done.vue'
|
||||||
import Labels from '../../../components/tasks/partials/labels.vue'
|
import Labels from '@/components/tasks/partials/labels.vue'
|
||||||
import ChecklistSummary from './checklist-summary.vue'
|
import ChecklistSummary from './checklist-summary.vue'
|
||||||
import {TASK_DEFAULT_COLOR} from '@/models/task'
|
|
||||||
|
import {TASK_DEFAULT_COLOR, getHexColor} from '@/models/task'
|
||||||
import type {ITask} from '@/modelTypes/ITask'
|
import type {ITask} from '@/modelTypes/ITask'
|
||||||
|
|
||||||
import {formatDateLong, formatISO, formatDateSince} from '@/helpers/time/formatDate'
|
import {formatDateLong, formatISO, formatDateSince} from '@/helpers/time/formatDate'
|
||||||
import {colorIsDark} from '@/helpers/color/colorIsDark'
|
import {colorIsDark} from '@/helpers/color/colorIsDark'
|
||||||
import {useTaskStore} from '@/stores/tasks'
|
import {useTaskStore} from '@/stores/tasks'
|
||||||
|
|
||||||
export default defineComponent({
|
const router = useRouter()
|
||||||
name: 'kanban-card',
|
|
||||||
components: {
|
const loadingInternal = ref(false)
|
||||||
ChecklistSummary,
|
|
||||||
Done,
|
const props = withDefaults(defineProps<{
|
||||||
PriorityLabel,
|
task: ITask,
|
||||||
User,
|
loading: boolean,
|
||||||
Labels,
|
}>(), {
|
||||||
},
|
loading: false,
|
||||||
data() {
|
})
|
||||||
return {
|
|
||||||
loadingInternal: false,
|
const color = computed(() => getHexColor(props.task.hexColor))
|
||||||
TASK_DEFAULT_COLOR,
|
|
||||||
}
|
async function toggleTaskDone(task: ITask) {
|
||||||
},
|
loadingInternal.value = true
|
||||||
props: {
|
|
||||||
task: {
|
|
||||||
type: Object as PropType<ITask>,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
loading: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
color() {
|
|
||||||
return this.task.getHexColor
|
|
||||||
? this.task.getHexColor()
|
|
||||||
: TASK_DEFAULT_COLOR
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
formatDateLong,
|
|
||||||
formatISO,
|
|
||||||
formatDateSince,
|
|
||||||
colorIsDark,
|
|
||||||
async toggleTaskDone(task: ITask) {
|
|
||||||
this.loadingInternal = true
|
|
||||||
try {
|
try {
|
||||||
const done = !task.done
|
|
||||||
await useTaskStore().update({
|
await useTaskStore().update({
|
||||||
...task,
|
...task,
|
||||||
done,
|
done: !task.done,
|
||||||
})
|
})
|
||||||
} finally {
|
} finally {
|
||||||
this.loadingInternal = false
|
loadingInternal.value = false
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
openTaskDetail() {
|
|
||||||
this.$router.push({
|
function openTaskDetail() {
|
||||||
|
router.push({
|
||||||
name: 'task.detail',
|
name: 'task.detail',
|
||||||
params: { id: this.task.id },
|
params: {id: props.task.id},
|
||||||
state: { backdropView: this.$router.currentRoute.value.fullPath },
|
state: {backdropView: router.currentRoute.value.fullPath},
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
},
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -28,7 +28,7 @@ if (!SUPPORTS_TRIGGERED_NOTIFICATION) {
|
||||||
console.debug('This browser does not support triggered notifications')
|
console.debug('This browser does not support triggered notifications')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHexColor(hexColor: string) {
|
export function getHexColor(hexColor: string): string {
|
||||||
if (hexColor === '' || hexColor === '#') {
|
if (hexColor === '' || hexColor === '#') {
|
||||||
return TASK_DEFAULT_COLOR
|
return TASK_DEFAULT_COLOR
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue