387 lines
20 KiB
Vue
387 lines
20 KiB
Vue
<script setup lang="ts">
|
|
import { Form, Head, Link } from '@inertiajs/vue3';
|
|
import { ArrowLeft, ListTodo, Plus } from 'lucide-vue-next';
|
|
import { computed, ref, watch } from 'vue';
|
|
import { move } from '@/actions/App/Http/Controllers/ProjectBoardController';
|
|
import FeedbackState from '@/components/FeedbackState.vue';
|
|
import InputError from '@/components/InputError.vue';
|
|
import { TicketCard } from '@/components/tickets';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Button } from '@/components/ui/button';
|
|
import { useLocalization } from '@/composables/useLocalization';
|
|
import AppLayout from '@/layouts/AppLayout.vue';
|
|
import { ticketStatusLabel } from '@/lib/tickets';
|
|
import { index as backlogIndex } from '@/routes/projects/backlog';
|
|
import { index as boardIndex } from '@/routes/projects/board';
|
|
import { index as projectIndex, show } from '@/routes/projects/index';
|
|
import { create as createTicket } from '@/routes/projects/tickets';
|
|
import type { BreadcrumbItem, ProjectBoardPageProps } from '@/types';
|
|
import type { TicketModel } from '@/types/models/ticket-model';
|
|
|
|
const props = defineProps<ProjectBoardPageProps>();
|
|
const { t } = useLocalization();
|
|
const breadcrumbs = computed<BreadcrumbItem[]>(() => [
|
|
{ title: t('navigation.projects'), href: projectIndex() },
|
|
{ title: props.project.name, href: show(props.project.id) },
|
|
{ title: t('navigation.board'), href: boardIndex(props.project.id) },
|
|
]);
|
|
const selectedColumnId = ref<number>();
|
|
watch(
|
|
() =>
|
|
[
|
|
props.project.id,
|
|
props.boardColumns.map((column) => column.id),
|
|
] as const,
|
|
([projectId, columnIds], previous) => {
|
|
if (
|
|
projectId !== previous?.[0] ||
|
|
!columnIds.includes(selectedColumnId.value ?? -1)
|
|
) {
|
|
selectedColumnId.value = columnIds[0];
|
|
}
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
const columns = computed(() =>
|
|
props.boardColumns.map((column) => {
|
|
const ticketsByStatus = new Map<number | null, TicketModel[]>();
|
|
for (const ticket of column.tickets ?? []) {
|
|
const tickets = ticketsByStatus.get(ticket.ticket_status_id) ?? [];
|
|
tickets.push(ticket);
|
|
ticketsByStatus.set(ticket.ticket_status_id, tickets);
|
|
}
|
|
return {
|
|
...column,
|
|
count: column.tickets?.length ?? 0,
|
|
groups: (column.ticket_statuses ?? []).map((status) => ({
|
|
status,
|
|
tickets: ticketsByStatus.get(status.id) ?? [],
|
|
})),
|
|
};
|
|
}),
|
|
);
|
|
const ticketCount = computed(() =>
|
|
columns.value.reduce((count, column) => count + column.count, 0),
|
|
);
|
|
const allowedTargetStatuses = (ticket: TicketModel) =>
|
|
(ticket.ticket_status?.allowed_target_statuses ?? []).filter(
|
|
(status) => status.id !== ticket.ticket_status_id,
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<AppLayout :breadcrumbs="breadcrumbs">
|
|
<Head :title="t('board.title', { name: project.name })" />
|
|
|
|
<div class="gap-column md:p-page flex min-w-0 flex-1 flex-col p-4">
|
|
<header
|
|
class="flex min-w-0 flex-col gap-4 xl:flex-row xl:items-start xl:justify-between"
|
|
>
|
|
<div class="grid min-w-0 gap-2">
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3">
|
|
<Badge
|
|
variant="outline"
|
|
class="wrap-anywhere max-w-full whitespace-normal"
|
|
>{{ project.key }}</Badge
|
|
>
|
|
<p class="text-caption text-muted-foreground">
|
|
{{ t('tickets.count', { count: ticketCount }) }}
|
|
</p>
|
|
</div>
|
|
<h1
|
|
class="text-headline-mobile md:text-headline wrap-anywhere"
|
|
>
|
|
{{ t('board.title', { name: project.name }) }}
|
|
</h1>
|
|
<p class="text-caption text-muted-foreground max-w-2xl">
|
|
{{ t('board.description') }}
|
|
</p>
|
|
</div>
|
|
<div class="flex flex-wrap gap-2">
|
|
<Button v-if="canCreateTickets" as-child>
|
|
<Link
|
|
:href="
|
|
createTicket(
|
|
{ project: project.id },
|
|
{ query: { source: 'board' } },
|
|
)
|
|
"
|
|
>
|
|
<Plus aria-hidden="true" />{{
|
|
t('navigation.createTicket')
|
|
}}
|
|
</Link>
|
|
</Button>
|
|
<Button as-child variant="outline">
|
|
<Link :href="backlogIndex(project.id)"
|
|
><ListTodo aria-hidden="true" />{{
|
|
t('board.openBacklog')
|
|
}}</Link
|
|
>
|
|
</Button>
|
|
<Button as-child variant="ghost">
|
|
<Link :href="show(project.id)"
|
|
><ArrowLeft aria-hidden="true" />{{
|
|
t('board.backToProject')
|
|
}}</Link
|
|
>
|
|
</Button>
|
|
</div>
|
|
</header>
|
|
|
|
<FeedbackState v-if="status" state="success" :title="status" />
|
|
<FeedbackState
|
|
v-if="columns.length === 0"
|
|
state="empty"
|
|
:title="t('board.empty.title')"
|
|
:description="t('board.empty.description')"
|
|
/>
|
|
|
|
<template v-else>
|
|
<div class="grid min-w-0 gap-2 md:hidden">
|
|
<label for="board-column" class="text-body font-semibold">{{
|
|
t('board.selectColumn')
|
|
}}</label>
|
|
<select
|
|
id="board-column"
|
|
v-model="selectedColumnId"
|
|
class="border-input bg-card text-body min-h-control focus-visible:ring-ring/35 w-full min-w-0 rounded-md border px-3 py-2 focus-visible:outline-none focus-visible:ring-2"
|
|
:aria-controls="`board-column-${selectedColumnId}`"
|
|
>
|
|
<option
|
|
v-for="column in columns"
|
|
:key="column.id"
|
|
:value="column.id"
|
|
>
|
|
{{
|
|
t('board.columnOption', {
|
|
name: column.name,
|
|
count: column.count,
|
|
})
|
|
}}
|
|
</option>
|
|
</select>
|
|
</div>
|
|
<p
|
|
id="board-scroll-hint"
|
|
class="text-caption text-muted-foreground hidden md:block"
|
|
>
|
|
{{ t('board.scrollHint') }}
|
|
</p>
|
|
<section
|
|
:aria-label="t('board.columns')"
|
|
aria-describedby="board-scroll-hint"
|
|
tabindex="0"
|
|
class="gap-column focus-visible:ring-ring/35 flex min-w-0 rounded-md pb-2 focus-visible:outline-none focus-visible:ring-2 md:overflow-x-auto md:overscroll-x-contain"
|
|
>
|
|
<section
|
|
v-for="column in columns"
|
|
:id="`board-column-${column.id}`"
|
|
:key="`${project.id}-${column.id}`"
|
|
:aria-labelledby="`board-column-title-${column.id}`"
|
|
:class="[
|
|
'bg-muted/40 gap-column w-full min-w-0 shrink-0 flex-col self-stretch rounded-md border p-3 md:flex md:w-80',
|
|
selectedColumnId === column.id ? 'flex' : 'hidden',
|
|
]"
|
|
>
|
|
<header
|
|
class="border-primary/25 flex min-w-0 items-start justify-between gap-3 border-b-2 pb-3"
|
|
>
|
|
<h2
|
|
:id="`board-column-title-${column.id}`"
|
|
class="text-title wrap-anywhere"
|
|
>
|
|
{{ column.name }}
|
|
</h2>
|
|
<Badge
|
|
variant="secondary"
|
|
class="shrink-0 tabular-nums"
|
|
:aria-label="
|
|
t('tickets.count', { count: column.count })
|
|
"
|
|
>{{ column.count }}</Badge
|
|
>
|
|
</header>
|
|
<p
|
|
v-if="column.count === 0"
|
|
class="text-caption text-muted-foreground rounded-md border border-dashed p-3"
|
|
>
|
|
{{ t('board.emptyColumn') }}
|
|
</p>
|
|
<p
|
|
v-if="column.groups.length === 0"
|
|
class="text-caption text-muted-foreground"
|
|
>
|
|
{{ t('board.noStatuses') }}
|
|
</p>
|
|
<section
|
|
v-for="group in column.groups"
|
|
:key="group.status.id"
|
|
:aria-labelledby="`board-status-${group.status.id}`"
|
|
class="grid min-w-0 gap-3"
|
|
>
|
|
<div
|
|
class="text-caption text-muted-foreground flex min-w-0 items-center justify-between gap-2"
|
|
>
|
|
<h3
|
|
:id="`board-status-${group.status.id}`"
|
|
class="wrap-anywhere font-semibold"
|
|
>
|
|
{{ group.status.name }}
|
|
</h3>
|
|
<span
|
|
class="shrink-0 tabular-nums"
|
|
:aria-label="
|
|
t('tickets.count', {
|
|
count: group.tickets.length,
|
|
})
|
|
"
|
|
>{{ group.tickets.length }}</span
|
|
>
|
|
</div>
|
|
<p
|
|
v-if="group.tickets.length === 0"
|
|
class="text-caption text-muted-foreground border-border rounded-md border border-dashed p-3"
|
|
>
|
|
{{ t('board.emptyStatus') }}
|
|
</p>
|
|
<ul v-else class="grid min-w-0 gap-3">
|
|
<li
|
|
v-for="ticket in group.tickets"
|
|
:key="ticket.id"
|
|
class="min-w-0"
|
|
>
|
|
<TicketCard
|
|
:project-id="project.id"
|
|
:ticket="ticket"
|
|
:show-status="false"
|
|
>
|
|
<template
|
|
v-if="canEditTickets"
|
|
#actions
|
|
>
|
|
<Form
|
|
v-bind="
|
|
move.form({
|
|
project: project.id,
|
|
ticket: ticket.id,
|
|
})
|
|
"
|
|
v-slot="{ processing, errors }"
|
|
:error-bag="`board-ticket-${ticket.id}`"
|
|
:options="{
|
|
preserveScroll: true,
|
|
}"
|
|
class="grid min-w-0 gap-2"
|
|
>
|
|
<input
|
|
type="hidden"
|
|
name="redirect_to"
|
|
value="board"
|
|
/>
|
|
<label
|
|
:for="`ticket-status-${ticket.id}`"
|
|
class="text-caption text-muted-foreground font-semibold"
|
|
>{{
|
|
t('board.moveTicket', {
|
|
key: ticket.ticket_key,
|
|
})
|
|
}}</label
|
|
>
|
|
<select
|
|
:id="`ticket-status-${ticket.id}`"
|
|
name="ticket_status_id"
|
|
:disabled="
|
|
processing ||
|
|
allowedTargetStatuses(
|
|
ticket,
|
|
).length === 0
|
|
"
|
|
:aria-invalid="
|
|
!!errors.ticket_status_id ||
|
|
undefined
|
|
"
|
|
:aria-describedby="
|
|
errors.ticket_status_id
|
|
? `ticket-status-error-${ticket.id}`
|
|
: undefined
|
|
"
|
|
class="border-input bg-card text-body min-h-control focus-visible:ring-ring/35 w-full min-w-0 rounded-md border px-3 py-2 focus-visible:outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
<option
|
|
v-if="
|
|
allowedTargetStatuses(
|
|
ticket,
|
|
).length === 0
|
|
"
|
|
value=""
|
|
>
|
|
{{ t('board.noMoves') }}
|
|
</option>
|
|
<option
|
|
v-for="target in allowedTargetStatuses(
|
|
ticket,
|
|
)"
|
|
:key="target.id"
|
|
:value="target.id"
|
|
>
|
|
{{
|
|
ticketStatusLabel(
|
|
target,
|
|
t(
|
|
'tickets.noStatus',
|
|
),
|
|
)
|
|
}}
|
|
</option>
|
|
</select>
|
|
<InputError
|
|
:id="`ticket-status-error-${ticket.id}`"
|
|
:message="
|
|
errors.ticket_status_id
|
|
"
|
|
/>
|
|
<Button
|
|
type="submit"
|
|
variant="outline"
|
|
:disabled="
|
|
processing ||
|
|
allowedTargetStatuses(
|
|
ticket,
|
|
).length === 0
|
|
"
|
|
>{{
|
|
t(
|
|
processing
|
|
? 'board.updatingStatus'
|
|
: 'board.updateStatus',
|
|
)
|
|
}}</Button
|
|
>
|
|
<p
|
|
v-if="
|
|
allowedTargetStatuses(
|
|
ticket,
|
|
).length === 0
|
|
"
|
|
class="text-caption text-muted-foreground"
|
|
>
|
|
{{
|
|
t(
|
|
'board.noMovesDescription',
|
|
)
|
|
}}
|
|
</p>
|
|
</Form>
|
|
</template>
|
|
</TicketCard>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
</section>
|
|
</section>
|
|
</template>
|
|
</div>
|
|
</AppLayout>
|
|
</template>
|