Skip to content
Snippets Groups Projects
Commit 8cd743de authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix: hide outdated schedules in schedule overview

We don’t want to show schedules that are in the past because they
clutter the overview.

refs #120
parent 424ae625
No related branches found
No related tags found
No related merge requests found
Pipeline #3060 passed
<template>
<div
v-if="schedules.length > 0"
v-if="relevantSchedules.length > 0"
:class="{
'show-schedules': true,
expandable: isExpandable,
......@@ -15,16 +15,18 @@
{{ uppercaseFirst(t('showSchedules.schedule')) }}
</th>
<th class="top-header text-right font-weight-normal">
{{ schedules.length }}
{{ relevantSchedules.length }}
{{
schedules.length === 1 ? t('showSchedules.schedule') : t('showSchedules.schedules')
relevantSchedules.length === 1
? t('showSchedules.schedule')
: t('showSchedules.schedules')
}}
</th>
</tr>
</thead>
<tbody>
<tr v-for="schedule in schedules" :key="schedule.id">
<tr v-for="schedule in relevantSchedules" :key="schedule.id">
<td>
{{ renderRruleForSchedule(schedule) }}
</td>
......@@ -64,10 +66,23 @@ const { prettyWeekday, prettyDate, prettyHours } = usePretty()
const store = useStore()
const selectedShow = useSelectedShow()
const schedules = computed(() => store.state.shows.schedules)
const isExpandable = computed(() => schedules.value.length > 2)
const relevantSchedules = computed(() => schedules.value.filter((s) => !isPossiblyPastSchedule(s)))
const isExpandable = computed(() => relevantSchedules.value.length > 2)
const isCollapsed = ref(true)
function isPossiblyPastSchedule(schedule) {
// Recurrence rules get very complex very fast, so we only give
// a definitive answer if a last_date is set for this schedule.
if (!schedule.last_date) {
return false
}
const lastDate = parseISO(schedule.last_date)
const [hours, minutes, seconds] = (schedule.end_time ?? '00:00:00').split(':')
lastDate.setHours(parseInt(hours ?? '0'), parseInt(minutes ?? '0'), parseInt(seconds ?? '0'))
return new Date() > lastDate
}
function updateSchedules() {
if (selectedShow.value) {
store.dispatch('shows/fetchSchedules', { show: selectedShow.value.id })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment