Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 53 additions & 38 deletions web/src/components/features/calendar/CalendarTaskCard.vue
Original file line number Diff line number Diff line change
@@ -1,66 +1,78 @@
<template>
<div
ref="card"
class="tv-calendar-card group relative flex w-full min-w-0 gap-1.5 rounded-10 border px-1.5 text-default"
class="tv-calendar-card group @container relative flex w-full min-w-0 gap-1.5 rounded-10 border px-1.5 text-default"
:class="[
short ? 'items-center py-0 text-xs' : 'items-start py-1 text-sm',
// A tall event: the checkbox and the time on top, the title wrapping below for as many lines as the height allows
{ 'flex-wrap content-start gap-y-0.5': tall || showProject },
// Everywhere the same order: the checkbox, the title, the time, the assignees.
// A tall event and a week card wrap the title and put the time and the assignees on a line under it
{ 'flex-wrap content-start gap-y-0.5': showProject || metaBelow },
{ 'opacity-60': task.complete && !lifted, 'pr-3': resizable, 'shadow-lg': lifted, 'h-full overflow-hidden': fill },
]"
:style="{ backgroundColor: tint.backgroundColor, borderColor: tint.borderColor }"
:data-testid="`calendar-task-${task.id}`"
>
<CalendarTaskCompleteCheckbox
v-if="canComplete && !lifted && !tall"
v-if="hasCheckbox"
:complete="!!task.complete"
:class="{ 'h-lh': !short }"
@toggle="emit('toggleComplete', $event)"
/>

<CalendarTaskCardAssignees
v-if="assignees.length && !showTimeRow"
v-if="assignees.length"
:emails="assignees"
class="order-3"
:class="{ 'h-lh items-center': !short }"
/>

<!-- One line: the whole time range always shows, the title takes what is left and truncates -->
<!-- One line: the title truncates, the time range follows it where the card is wide enough for both -->
<span
v-if="short"
class="flex min-w-0 flex-1 items-center gap-x-1.5 leading-snug"
:title="cardTitle"
>
<span
v-if="timeText"
class="shrink-0 text-muted tabular-nums"
>{{ timeText }}</span>
<span
class="min-w-0 truncate"
class="min-w-0 flex-1 truncate"
:class="{ 'line-through text-muted': task.complete }"
>{{ task.description }}</span>
<CalendarTaskCardTime
v-if="timeRange"
:time-range="timeRange"
inline
/>
</span>

<template v-else>
<span
v-if="timeText && !tall"
class="mt-px shrink-0 text-xs text-muted tabular-nums"
>{{ timeText }}</span>
<span
ref="title"
class="min-w-0 leading-snug"
class="min-w-0 flex-1 leading-snug"
:class="[
tall ? 'line-clamp-1 basis-full break-words hyphens-auto' : ['flex-1', compact ? 'truncate' : 'line-clamp-2 break-words'],
titleClass,
{ 'line-through text-muted': task.complete },
]"
:style="titleLines ? { WebkitLineClamp: titleLines } : undefined"
:lang="locale"
:title="cardTitle"
>{{ task.description }}</span>
<!-- Ends the title's line, so what follows starts a new one -->
<span
v-if="metaBelow"
class="order-1 basis-full"
aria-hidden="true"
/>
<!-- A month cell is for the title: the time is in the tooltip and in the other views -->
<CalendarTaskCardTime
v-if="timeRange && (metaBelow || !compact)"
:time-range="timeRange"
:inline="!metaBelow"
class="order-2 mt-px text-xs"
/>
</template>

<span
v-if="canViewTaskSubtasks && task.subtasks.length"
class="flex shrink-0 items-center gap-0.5 text-xs text-muted tabular-nums"
class="order-4 flex shrink-0 items-center gap-0.5 text-xs text-muted tabular-nums"
:class="{ 'mt-px': !short }"
:title="t('calendar.subtasks', { count: task.subtasks.length })"
>
Expand All @@ -73,28 +85,16 @@

<CalendarTaskCardAmount
v-if="amount"
v-show="showAmount"
:amount="amount"
:transaction-type="task.transactionType"
class="order-4"
:class="{ 'mt-px': !short }"
/>

<CalendarTaskCardTimeRow
v-if="showTimeRow"
:complete="!!task.complete"
:can-complete="Boolean(canComplete && !lifted)"
:time-range="timeRange"
@toggle="emit('toggleComplete', $event)"
>
<CalendarTaskCardAssignees
v-if="assignees.length"
:emails="assignees"
class="ms-auto"
/>
</CalendarTaskCardTimeRow>

<span
v-if="showProject"
class="flex min-w-0 basis-full items-center gap-1 text-xs text-muted"
class="order-5 flex min-w-0 basis-full items-center gap-1 text-xs text-muted"
data-testid="calendar-task-project"
>
<UIcon
Expand Down Expand Up @@ -123,17 +123,19 @@ import { useGoalPermissionsFor } from '@/composables/useGoalPermissions'
import { useGoalsStore } from '@/stores/goals.store'
import { useCalendarCardTitleLines } from '@/composables/useCalendarCardTitleLines'
import { useCalendarTaskColor } from '@/composables/useCalendarTaskColor'
import { useCalendarTimeText } from '@/composables/useCalendarTimeText'
import CalendarTaskCompleteCheckbox from './parts/CalendarTaskCompleteCheckbox.vue'
import CalendarTaskCardTimeRow from './parts/CalendarTaskCardTimeRow.vue'
import CalendarTaskCardTime from './parts/CalendarTaskCardTime.vue'
import CalendarTaskCardAmount from './parts/CalendarTaskCardAmount.vue'
import CalendarTaskCardAssignees from './parts/CalendarTaskCardAssignees.vue'
import type { CalendarTimeRange } from '@/types/calendar.types'

const props = defineProps<{
task: TaskItem
timeText?: string
// Month cells fit a single line; the week columns have room for two
compact?: boolean
// A narrow week column: the title wraps next to the checkbox, the time and the assignees go on a line under it
stacked?: boolean
// Its end can be dragged to change the duration: show a grip on hover
resizable?: boolean
// The copy that follows the pointer while dragging
Expand All @@ -148,7 +150,7 @@ const props = defineProps<{
projectName?: string
// A checkbox marks the task done or reopens it without opening the task
canComplete?: boolean
// When a timed event starts and ends: a tall card shows it above the title
// When a timed event starts and ends
timeRange?: CalendarTimeRange
}>()

Expand All @@ -163,6 +165,7 @@ const goalsStore = useGoalsStore()
const goal = computed(() => goalsStore.goalMap.get(props.task.goalId) ?? null)
const { canViewAssignedUsersToTask, canViewTaskSubtasks } = useGoalPermissionsFor(goal)
const { taskColor } = useCalendarTaskColor()
const { timeText } = useCalendarTimeText()

const tint = computed(() => {
const base = props.color ?? taskColor(props.task)
Expand All @@ -172,19 +175,31 @@ const tint = computed(() => {
}
})

// The line under a tall card's title: 16px and the gap above it
const META_LINE_HEIGHT = 18

const tall = computed(() => Boolean(props.fill && !props.short))
const showTimeRow = computed(() => Boolean(tall.value && (props.timeRange || (props.canComplete && !props.lifted))))
const hasCheckbox = computed(() => Boolean(props.canComplete && !props.lifted))
// A week card and a tall event wrap the title, so the time and the assignees take a line under it
const metaBelow = computed(() => Boolean((props.stacked || tall.value) && !props.short))
const titleClass = computed(() => {
if (tall.value) return 'line-clamp-1 break-words hyphens-auto'
if (metaBelow.value) return 'line-clamp-3 break-words hyphens-auto'
return props.compact ? 'truncate' : 'line-clamp-2 break-words'
})
// Only where the card has room for a second line
const showProject = computed(() => Boolean(props.projectName && !props.short && !tall.value && !props.compact))
const titleLines = useCalendarCardTitleLines({
card: useTemplateRef<HTMLElement>('card'),
title: useTemplateRef<HTMLElement>('title'),
enabled: tall,
reserve: computed(() => (props.timeRange || assignees.value.length ? META_LINE_HEIGHT : 0)),
})

const amount = computed(() => Number(props.task.amount) || 0)
const showAmount = false

const cardTitle = computed(() => (props.timeText ? `${props.timeText} ${props.task.description}` : props.task.description))
const cardTitle = computed(() => (props.timeRange ? `${timeText(props.timeRange).range} ${props.task.description}` : props.task.description))

const assignees = computed(() => {
if (!canViewAssignedUsersToTask.value) return []
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/features/calendar/TaskCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
<CalendarTaskCard
v-if="arg.event.extendedProps.task"
:task="arg.event.extendedProps.task"
:time-text="arg.event.allDay ? undefined : arg.timeText"
:time-range="arg.event.allDay || !arg.event.start ? undefined : { start: arg.event.start, end: arg.event.end }"
:compact="arg.view.type !== FC_VIEWS.week && arg.view.type !== FC_VIEWS.list"
:stacked="arg.view.type === FC_VIEWS.week"
:resizable="arg.isEndResizable"
:lifted="arg.isMirror"
:fill="isTimeGrid(arg.view.type) && !arg.event.allDay"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
>
<CalendarTaskCard
:task="event.extendedProps.task"
:time-text="timeText(event)"
:time-range="timeRange(event)"
:can-complete="canComplete?.(event.extendedProps.task)"
v-bind="cardProps?.(event.extendedProps.task)"
@toggle-complete="emit('toggleComplete', { task: event.extendedProps.task, complete: $event })"
Expand Down Expand Up @@ -54,6 +54,7 @@ import { useI18n } from 'vue-i18n'
import CalendarTaskCard from '../CalendarTaskCard.vue'
import type { TaskCalendarEvent } from '@/helpers/taskCalendarDates'
import type { TaskItem } from '@/types/tasks.types'
import type { CalendarTimeRange } from '@/types/calendar.types'
import type { TaskCompleteArgs } from '../TaskCalendar.types'

const props = defineProps<{
Expand All @@ -75,10 +76,8 @@ const { t, locale } = useI18n()

const dayTitle = computed(() => new Intl.DateTimeFormat(locale.value, { weekday: 'long', day: 'numeric', month: 'long' }).format(props.day))

function timeText(event: TaskCalendarEvent): string | undefined {
function timeRange(event: TaskCalendarEvent): CalendarTimeRange | undefined {
if (event.allDay) return undefined
const time = new Intl.DateTimeFormat(locale.value, { hour: 'numeric', minute: '2-digit' })
const start = time.format(new Date(event.start))
return event.end ? `${start} – ${time.format(new Date(event.end))}` : start
return { start: new Date(event.start), end: event.end ? new Date(event.end) : null }
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<span
class="shrink-0 whitespace-nowrap text-muted tabular-nums"
:class="{ 'hidden @[11rem]:inline': inline }"
:title="text.range"
data-testid="calendar-task-time"
>
<!-- The start alone where the whole range has no room -->
<span :class="inline ? '@[20rem]:hidden' : '@[9rem]:hidden'">{{ text.start }}</span>
<span :class="inline ? 'hidden @[20rem]:inline' : 'hidden @[9rem]:inline'">{{ text.range }}</span>
</span>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useCalendarTimeText } from '@/composables/useCalendarTimeText'
import type { CalendarTimeRange } from '@/types/calendar.types'

const props = defineProps<{
timeRange: CalendarTimeRange
// On the title's line, where the time gives way to the title; otherwise it has a line of its own
inline?: boolean
}>()

const { timeText } = useCalendarTimeText()
const text = computed(() => timeText(props.timeRange))
</script>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const { isMobile } = useTaskView()
const isOpen = ref(false)

const rateFormat = computed(() => new Intl.NumberFormat(locale.value, { maximumFractionDigits: 2 }))
const weeksFormat = computed(() => new Intl.NumberFormat(locale.value, { maximumFractionDigits: 1 }))
const dateFormat = computed(() => new Intl.DateTimeFormat(locale.value, { day: 'numeric', month: 'long', year: 'numeric' }))

const texts = computed(() => (props.variant === 'pace'
Expand Down Expand Up @@ -98,15 +97,17 @@ const steps = computed(() => {
const { weeks, closed } = props.model.paceWindow
const open = props.model.totals.open
const rate = rateFormat.value.format(forecast.weeklyRate)
// Whole weeks, like the forecast line this explains: "2.3 weeks" reads oddly
const weeksLeft = Math.max(Math.round(forecast.weeksLeft), 1)
return [
t('projectDashboard.forecastHelp.pace', { weeks, closed, rate }),
t('projectDashboard.forecastHelp.remaining', { open }),
t('projectDashboard.forecastHelp.result', {
open,
rate,
weeksLeft: weeksFormat.value.format(forecast.weeksLeft),
weeksLeft,
date: dateFormat.value.format(forecast.date),
}),
}, weeksLeft),
]
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ const dateFormat = computed(() => {
? { weekday: 'short', day: 'numeric', month: 'short' }
: { day: 'numeric', month: 'short', year: 'numeric' })
})
const rateFormat = computed(() => new Intl.NumberFormat(locale.value, { maximumFractionDigits: 1 }))
const wholeFormat = computed(() => new Intl.NumberFormat(locale.value, { maximumFractionDigits: 0 }))
const fractionFormat = computed(() => new Intl.NumberFormat(locale.value, { maximumFractionDigits: 1 }))

const weeklyRate = (closed: number) => rateFormat.value.format(closed / props.model.paceWindow.weeks)
// Whole tasks: "3.5 a week" reads oddly. Under one a week the fraction stays, or the pace would show as zero
const formatRate = (rate: number) => (rate >= 1 ? wholeFormat.value : fractionFormat.value).format(rate)
const weeklyRate = (closed: number) => formatRate(closed / props.model.paceWindow.weeks)

const paceHeadline = computed(() => {
const { weeks, closed } = props.model.paceWindow
Expand All @@ -88,7 +91,8 @@ const paceHeadline = computed(() => {
const paceNote = computed(() => {
const { weeks, closed } = props.model.paceWindow
const previous = props.model.previousPaceClosed ?? closed
if (previous === closed) return t('projectDashboard.hero.paceSame', { weeks })
// The same once rounded counts as the same: "4 a week, up from 4 a week" says nothing
if (weeklyRate(previous) === weeklyRate(closed)) return t('projectDashboard.hero.paceSame', { weeks })
return t(previous < closed ? 'projectDashboard.hero.paceUp' : 'projectDashboard.hero.paceDown', {
rate: weeklyRate(previous),
weeks,
Expand All @@ -107,7 +111,7 @@ const note = computed(() => {
const forecast = props.model.forecast
if (forecast) {
return t('projectDashboard.hero.pace', {
rate: rateFormat.value.format(forecast.weeklyRate),
rate: formatRate(forecast.weeklyRate),
weeks: Math.max(Math.round(forecast.weeksLeft), 1),
})
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/composables/useCalendarCardTitleLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useCalendarCardTitleLines(args: CalendarCardTitleLinesArgs): Ref
if (!args.enabled.value || !card || !title || !height.value) return undefined
const lineHeight = parseFloat(getComputedStyle(title).lineHeight)
const paddingTop = parseFloat(getComputedStyle(card).paddingTop)
const room = paddingTop + height.value - title.offsetTop
const room = paddingTop + height.value - title.offsetTop - (args.reserve?.value ?? 0)
return Math.max(1, Math.floor(room / lineHeight))
})
}
Loading
Loading