]> git.localhorst.tv Git - alttp.git/commitdiff
option to hide round numbers
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 24 Feb 2024 14:03:04 +0000 (15:03 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 24 Feb 2024 14:03:04 +0000 (15:03 +0100)
app/Http/Controllers/TournamentController.php
app/Models/Protocol.php
app/Models/Tournament.php
database/migrations/2024_02_24_134620_tournament_hide_round_numbers.php [new file with mode: 0644]
resources/js/components/protocol/Item.js
resources/js/components/rounds/Item.js
resources/js/components/tournament/SettingsDialog.js
resources/js/i18n/de.js
resources/js/i18n/en.js
routes/api.php

index f53dad4b644e5aee03481c5e670424ea6e8fe1ac..2dc7e51a84ae104597626dd05950b4383c55e873 100644 (file)
@@ -102,6 +102,22 @@ class TournamentController extends Controller
                return $rounds->toArray();
        }
 
+       public function settings(Request $request, Tournament $tournament) {
+               $this->authorize('update', $tournament);
+               $validatedData = $request->validate([
+                       'show_numbers' => 'boolean|nullable',
+               ]);
+               if (array_key_exists('show_numbers', $validatedData)) {
+                       $tournament->show_numbers = $validatedData['show_numbers'];
+               }
+               $tournament->save();
+               if ($tournament->wasChanged()) {
+                       TournamentChanged::dispatch($tournament);
+                       Protocol::tournamentSettings($tournament, $request->user());
+               }
+               return $tournament->toJson();
+       }
+
        public function open(Request $request, Tournament $tournament) {
                $this->authorize('update', $tournament);
                $tournament->accept_applications = true;
index b747b1258d147472ad0a158d97f80e319f915943..60b25f2ad8cd6cd21c4003fc747e40c808e1b132 100644 (file)
@@ -217,6 +217,18 @@ class Protocol extends Model
                ProtocolAdded::dispatch($protocol);
        }
 
+       public static function tournamentSettings(Tournament $tournament, User $user = null) {
+               $protocol = static::create([
+                       'tournament_id' => $tournament->id,
+                       'user_id' => $user ? $user->id : null,
+                       'type' => 'tournament.settings',
+                       'details' => [
+                               'tournament' => static::tournamentMemo($tournament),
+                       ],
+               ]);
+               ProtocolAdded::dispatch($protocol);
+       }
+
        public static function tournamentUnlocked(Tournament $tournament, User $user = null) {
                $protocol = static::create([
                        'tournament_id' => $tournament->id,
index 6f0feb1237db7a8693c20bf7e73e7c44f62e3fa7..96e89b8939358aea1b88acfdfa8f1c89270e86aa 100644 (file)
@@ -86,6 +86,7 @@ class Tournament extends Model
                'accept_applications' => 'boolean',
                'locked' => 'boolean',
                'no_record' => 'boolean',
+               'show_numbers' => 'boolean',
        ];
 
 }
diff --git a/database/migrations/2024_02_24_134620_tournament_hide_round_numbers.php b/database/migrations/2024_02_24_134620_tournament_hide_round_numbers.php
new file mode 100644 (file)
index 0000000..7672371
--- /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('tournaments', function(Blueprint $table) {
+                       $table->boolean('show_numbers')->default(true);
+               });
+       }
+
+       /**
+        * Reverse the migrations.
+        *
+        * @return void
+        */
+       public function down()
+       {
+               Schema::table('tournaments', function(Blueprint $table) {
+                       $table->dropColumn('show_numbers');
+               });
+       }
+};
index 00da2ef472c27afb8b8be1c55de2c9cd9e361e0a..7dba2a3bed06c7aeacb0ccae6db90efd7415e3f1 100644 (file)
@@ -83,6 +83,7 @@ const getEntryDescription = entry => {
                case 'tournament.discord':
                case 'tournament.lock':
                case 'tournament.open':
+               case 'tournament.settings':
                case 'tournament.unlock':
                        return i18n.t(
                                `protocol.description.${entry.type}`,
index 949eeb2f2ec910e99b94ba9bf0a01c67a5549ba3..0ef77c5d2c5ce6b9bec1c8798ddba6c184b43a77 100644 (file)
@@ -48,7 +48,7 @@ return <li className={getClassName(round, tournament, user)}>
                <div className="d-flex">
                        <div className="info">
                                <p className="date">
-                                       {round.number ? `#${round.number} ` : '#?'}
+                                       {tournament.show_numbers && round.number ? `#${round.number} ` : ''}
                                        {t('rounds.date', { date: new Date(round.created_at) })}
                                </p>
                                <p className="seed">
@@ -104,6 +104,7 @@ Item.propTypes = {
        tournament: PropTypes.shape({
                participants: PropTypes.arrayOf(PropTypes.shape({
                })),
+               show_numbers: PropTypes.bool,
                type: PropTypes.string,
        }),
 };
index 362cd6fbab36595da9754e1784eb4325911984d9..46fbfd87ecae299ec5aef94bddebbf71c691af9b 100644 (file)
@@ -57,6 +57,15 @@ const setDiscord = async (tournament, guild_id) => {
        }
 };
 
+const settings = async (tournament, params) => {
+       try {
+               await axios.post(`/api/tournaments/${tournament.id}/settings`, params);
+               toastr.success(i18n.t('tournaments.settingsSuccess'));
+       } catch (e) {
+               toastr.error(i18n.t('tournaments.settingsError'));
+       }
+};
+
 const inviteUrl = 'https://discordapp.com/oauth2/authorize?client_id=951113702839549982&scope=bot';
 
 const SettingsDialog = ({
@@ -96,6 +105,14 @@ const SettingsDialog = ({
                                                value={tournament.locked}
                                        />
                                </div>
+                               <div className="d-flex align-items-center justify-content-between mb-3">
+                                       <span>{i18n.t('tournaments.showNumbers')}</span>
+                                       <ToggleSwitch
+                                               onChange={({ target: { value } }) =>
+                                                       settings(tournament, { show_numbers: value })}
+                                               value={tournament.show_numbers}
+                                       />
+                               </div>
                                <div className="d-flex align-items-center justify-content-between">
                                        <div>
                                                <p>{i18n.t('tournaments.discord')}</p>
@@ -140,6 +157,7 @@ SettingsDialog.propTypes = {
                accept_applications: PropTypes.bool,
                discord: PropTypes.string,
                locked: PropTypes.bool,
+               show_numbers: PropTypes.bool,
        }),
 };
 
index 0d17d73e71ebf32832b66e34825f5e891f0bdcc8..080a6dd13d90e9210ee99e8191d8d0c03fa106ab 100644 (file)
@@ -357,6 +357,7 @@ export default {
                                        discord: 'Discord Server verknüpft',
                                        lock: 'Turnier gesperrt',
                                        open: 'Anmeldung geöffnet',
+                                       settings: 'Einstellungen geändert',
                                        unlock: 'Turnier entsperrt',
                                },
                                unknown: 'Unbekannter Protokolleintrag vom Typ {{type}}.',
@@ -483,6 +484,9 @@ export default {
                        scoreboard: 'Scoreboard',
                        scoreChart: 'Turnierverlauf',
                        settings: 'Einstellungen',
+                       settingsError: 'Fehler beim Speichern',
+                       settingsSuccess: 'Einstellungen gespeichert',
+                       showNumbers: 'Nummern einblenden',
                        unlockError: 'Fehler beim Entsperren',
                        unlockSuccess: 'Turnier entsperrt',
                },
index 37229910076de037692957d672ccb8ad0fca00ad..f722332ba30bc65e218d7fdd603b79d414e4a9b6 100644 (file)
@@ -357,6 +357,7 @@ export default {
                                        discord: 'Discord server connected',
                                        lock: 'Tournament locked',
                                        open: 'Registration opened',
+                                       settings: 'Modified settings',
                                        unlock: 'Tournament unlocked',
                                },
                                unknown: 'Unknown protocol entry of type {{type}}.',
@@ -483,6 +484,9 @@ export default {
                        scoreboard: 'Scoreboard',
                        scoreChart: 'Score chart',
                        settings: 'Settings',
+                       settingsError: 'Error saving settings',
+                       settingsSuccess: 'Settings saved successfully',
+                       showNumbers: 'Show numbers',
                        unlockError: 'Error unlocking tournaments',
                        unlockSuccess: 'Tournament unlocked',
                },
index ca02e369cc8652608556a9e6ca16a7db728d8cad..84cbf733cc5e611d8d8d2556e1ddf3228987b15e 100644 (file)
@@ -77,6 +77,7 @@ Route::post('tournaments/{tournament}/discord', 'App\Http\Controllers\Tournament
 Route::post('tournaments/{tournament}/discord-settings', 'App\Http\Controllers\TournamentController@discordSettings');
 Route::post('tournaments/{tournament}/lock', 'App\Http\Controllers\TournamentController@lock');
 Route::post('tournaments/{tournament}/open', 'App\Http\Controllers\TournamentController@open');
+Route::post('tournaments/{tournament}/settings', 'App\Http\Controllers\TournamentController@settings');
 Route::post('tournaments/{tournament}/unlock', 'App\Http\Controllers\TournamentController@unlock');
 
 Route::get('users', 'App\Http\Controllers\UserController@search');