]> git.localhorst.tv Git - alttp.git/commitdiff
schedule event filter
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 22 Feb 2023 08:44:12 +0000 (09:44 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 22 Feb 2023 08:44:12 +0000 (09:44 +0100)
app/Http/Controllers/EpisodeController.php
database/migrations/2023_02_22_083016_event_short.php [new file with mode: 0644]
resources/js/components/episodes/Filter.js
resources/js/components/pages/Schedule.js
resources/js/i18n/de.js
resources/js/i18n/en.js

index d1e7e85612d08c7c1417fdda2df2f07f4a0bbaef..6de7d676a496c6b6ee6aaa89ccff01d9540a5b42 100644 (file)
@@ -13,6 +13,8 @@ class EpisodeController extends Controller
                $validatedData = $request->validate([
                        'after' => 'nullable|date',
                        'before' => 'nullable|date',
+                       'event' => 'nullable|array',
+                       'event.*' => 'numeric',
                ]);
                $after = isset($validatedData['after']) ? $validatedData['after'] : Carbon::now()->sub(2, 'hours');
                $before = isset($validatedData['before']) ? $validatedData['before'] : Carbon::now()->add(1, 'days');
@@ -25,6 +27,9 @@ class EpisodeController extends Controller
                        ->where('events.visible', '=', true)
                        ->orderBy('episodes.start')
                        ->limit(1000);
+               if (!empty($validatedData['event'])) {
+                       $episodes = $episodes->whereIn('episodes.event_id', $validatedData['event']);
+               }
                if ($request->user() && $request->user()->isPrivileged()) {
                        $episodes = $episodes->with(['crew', 'crew.user']);
                } else {
diff --git a/database/migrations/2023_02_22_083016_event_short.php b/database/migrations/2023_02_22_083016_event_short.php
new file mode 100644 (file)
index 0000000..071bca5
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+       /**
+        * Run the migrations.
+        *
+        * @return void
+        */
+       public function up()
+       {
+               Schema::table('events', function(Blueprint $table) {
+                       $table->string('short')->default('');
+               });
+       }
+
+       /**
+        * Reverse the migrations.
+        *
+        * @return void
+        */
+       public function down()
+       {
+               Schema::table('events', function(Blueprint $table) {
+                       $table->dropColumn('short');
+               });
+       }
+};
index b411f82193574c9036b3ff8d22bbe6d4b99a940e..06dcf13f65501839f08090b58754c69d35fafa1f 100644 (file)
@@ -16,7 +16,9 @@ const Filter = ({ filter, setFilter }) => {
                                before: moment().startOf('day').add(8, 'days').toISOString(),
                        },
                }).then(response => {
-                       const newEvents = response.data || [];
+                       const newEvents = (response.data || []).sort(
+                               (a, b) => (a.short || a.title).localeCompare(b.short || b.title)
+                       );
                        setEvents(newEvents);
                }).catch(e => {
                        if (!axios.isCancel(e)) {
@@ -50,15 +52,16 @@ const Filter = ({ filter, setFilter }) => {
 
        if (!events || !events.length) return null;
 
-       return <div className="episode-filter">
+       return <div className="episode-filter button-bar text-end">
                {events.map(event =>
                        <Button
                                active={isEventSelected(event)}
                                key={event.id}
                                onClick={() => toggleEvent(event)}
+                               title={event.short ? event.title : null}
                                variant="outline-secondary"
                        >
-                               {event.title}
+                               {event.short || event.title}
                        </Button>
                )}
        </div>;
index 06d471fbeca0d3abacdbfb17627f272a121963b4..0e0170154e8ae8e86c4948f256a797d0d8fe28cd 100644 (file)
@@ -1,7 +1,7 @@
 import axios from 'axios';
 import moment from 'moment';
 import React from 'react';
-import { Container } from 'react-bootstrap';
+import { Alert, Container } from 'react-bootstrap';
 import { Helmet } from 'react-helmet';
 import { useTranslation } from 'react-i18next';
 
@@ -11,7 +11,7 @@ import Filter from '../episodes/Filter';
 import List from '../episodes/List';
 
 const Schedule = () => {
-       const [ahead, setAhead] = React.useState(6);
+       const [ahead, setAhead] = React.useState(14);
        const [behind, setBehind] = React.useState(0);
        const [episodes, setEpisodes] = React.useState([]);
        const [filter, setFilter] = React.useState({});
@@ -67,10 +67,20 @@ const Schedule = () => {
                        <meta name="description" content={t('schedule.description')} />
                </Helmet>
                <CanonicalLinks base="/schedule" />
-               <h1>{t('schedule.heading')}</h1>
+               <div className="d-flex align-items-start justify-content-between">
+                       <h1>{t('schedule.heading')}</h1>
+                       <div className="mt-5">
+                               <Filter filter={filter} setFilter={updateFilter} />
+                       </div>
+               </div>
                <ErrorBoundary>
-                       <Filter filter={filter} setFilter={updateFilter} />
-                       <List episodes={episodes} />
+                       {episodes.length ?
+                               <List episodes={episodes} />
+                       :
+                               <Alert variant="info">
+                                       {t('episodes.empty')}
+                               </Alert>
+                       }
                </ErrorBoundary>
        </Container>;
 };
index aff46ec38e07be24b73344c1d5810a25eb0005d6..32cc3709dc8043cef32571f7940a246de7f4dc5b 100644 (file)
@@ -264,6 +264,7 @@ export default {
                },
                episodes: {
                        commentary: 'Kommentar',
+                       empty: 'Keine anstehenden Termine.',
                        setup: 'Setup',
                        tracking: 'Tracking',
                },
index cb63f602c56070123c1982ba532f115bd794689c..200e9888db9e1f41695a2a4ee92fcfe8cb6ad17a 100644 (file)
@@ -264,6 +264,7 @@ export default {
                },
                episodes: {
                        commentary: 'Commentary',
+                       empty: 'No dates coming up.',
                        setup: 'Setup',
                        tracking: 'Tracking',
                },