From 3544909490592e8c2387f3347ee5e12a8c0414be Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sat, 21 Oct 2023 18:34:38 +0200 Subject: [PATCH] show some past episodes on concluded events --- app/Http/Controllers/EpisodeController.php | 19 +++++++++++++---- resources/js/components/events/Detail.js | 9 +++++++- resources/js/helpers/Event.js | 3 +++ resources/js/i18n/de.js | 2 ++ resources/js/i18n/en.js | 2 ++ resources/js/pages/Event.js | 24 ++++++++++++++++------ 6 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 resources/js/helpers/Event.js diff --git a/app/Http/Controllers/EpisodeController.php b/app/Http/Controllers/EpisodeController.php index 785a241..22ca6dc 100644 --- a/app/Http/Controllers/EpisodeController.php +++ b/app/Http/Controllers/EpisodeController.php @@ -195,18 +195,28 @@ class EpisodeController extends Controller 'before' => 'nullable|date', 'event' => 'nullable|array', 'event.*' => 'numeric', + 'limit' => 'numeric', + 'offset' => 'numeric', + 'reverse' => 'boolean', ]); - $after = isset($validatedData['after']) ? $validatedData['after'] : Carbon::now(); $before = isset($validatedData['before']) ? $validatedData['before'] : Carbon::now()->add(1, 'days'); + $limit = isset($validatedData['limit']) ? $validatedData['limit'] : 100; + $reverse = isset($validatedData['reverse']) ? $validatedData['reverse'] : false; $episodes = Episode::with(['channels', 'event', 'players', 'players.user']) ->select('episodes.*') ->join('events', 'episodes.event_id', '=', 'events.id') ->where('episodes.confirmed', '=', true) - ->where(DB::raw('DATE_ADD(`episodes`.`start`, INTERVAL COALESCE(`episodes`.`estimate`, 0) SECOND)'), '>=', $after) - ->where('episodes.start', '<=', $before) ->where('events.visible', '=', true) - ->orderBy('episodes.start') + ->orderBy('episodes.start', $reverse ? 'DESC' : 'ASC') ->limit(1000); + if (isset($validatedData['after'])) { + $episodes = $episodes->where( + DB::raw('DATE_ADD(`episodes`.`start`, INTERVAL COALESCE(`episodes`.`estimate`, 0) SECOND)'), + '>=', $validatedData['after']); + } + if (isset($validatedData['before'])) { + $episodes = $episodes->where('episodes.start', '<=', $validatedData['before']); + } if (!empty($validatedData['event'])) { $episodes = $episodes->whereIn('episodes.event_id', $validatedData['event']); } @@ -229,6 +239,7 @@ class EpisodeController extends Controller 'crew.user', ]); } + $episodes->limit($limit); return $episodes->get()->toJson(); } diff --git a/resources/js/components/events/Detail.js b/resources/js/components/events/Detail.js index d530006..6589548 100644 --- a/resources/js/components/events/Detail.js +++ b/resources/js/components/events/Detail.js @@ -1,10 +1,11 @@ import PropTypes from 'prop-types'; import React from 'react'; -import { Button } from 'react-bootstrap'; +import { Alert, Button } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; import Icon from '../common/Icon'; import RawHTML from '../common/RawHTML'; +import { hasConcluded } from '../../helpers/Event'; import { getTranslation } from '../../helpers/Technique'; import i18n from '../../i18n'; @@ -32,6 +33,11 @@ const Detail = ({ actions, event }) => { {event.description ? : null} + {hasConcluded(event) ? + + {t('events.concluded')} + + : null} ; }; @@ -42,6 +48,7 @@ Detail.propTypes = { event: PropTypes.shape({ description: PropTypes.shape({ }), + end: PropTypes.string, title: PropTypes.string, }), }; diff --git a/resources/js/helpers/Event.js b/resources/js/helpers/Event.js new file mode 100644 index 0000000..da7a035 --- /dev/null +++ b/resources/js/helpers/Event.js @@ -0,0 +1,3 @@ +import moment from 'moment'; + +export const hasConcluded = event => event && event.end && moment(event.end).isBefore(moment()); diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 79eb371..7908d4f 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -153,6 +153,8 @@ export default { }, }, events: { + concluded: 'Diese Veranstaltung is abgeschlossen.', + pastEpisodes: 'Vergangene Rennen', upcomingEpisodes: 'Anstehende Rennen', }, footer: { diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 997c639..417abf0 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -153,6 +153,8 @@ export default { }, }, events: { + concluded: 'This event has concluded.', + pastEpisodes: 'Past races', upcomingEpisodes: 'Upcoming races', }, footer: { diff --git a/resources/js/pages/Event.js b/resources/js/pages/Event.js index 1a97cdc..c7f0ce5 100644 --- a/resources/js/pages/Event.js +++ b/resources/js/pages/Event.js @@ -15,6 +15,7 @@ import Loading from '../components/common/Loading'; import EpisodeList from '../components/episodes/List'; import Detail from '../components/events/Detail'; import Dialog from '../components/techniques/Dialog'; +import { hasConcluded } from '../helpers/Event'; import { mayEditContent, } from '../helpers/permissions'; @@ -47,13 +48,19 @@ const Event = () => { setEpisodes([]); return; } + const params = { + event: [event.id], + }; + if (hasConcluded(event)) { + params.limit = 25; + params.reverse = '1'; + } else { + params.after = moment().subtract(3, 'hours').toISOString(); + params.before = moment().add(14, 'days').toISOString(); + } axios.get(`/api/episodes`, { signal: controller.signal, - params: { - after: moment().subtract(3, 'hours').toISOString(), - before: moment().add(14, 'days').toISOString(), - event: [event.id], - }, + params, }).then(response => { setEpisodes(response.data || []); }).catch(e => { @@ -141,7 +148,12 @@ const Event = () => { {episodes.length ? <> -

{i18n.t('events.upcomingEpisodes')}

+

+ {i18n.t(hasConcluded(event) + ? 'events.pastEpisodes' + : 'events.upcomingEpisodes' + )} +

: null}
-- 2.39.2