From e1ecc76c1c6d527502d6576ee19be06df2a15bb7 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sat, 24 Feb 2024 15:03:04 +0100 Subject: [PATCH] option to hide round numbers --- app/Http/Controllers/TournamentController.php | 16 ++++++++++ app/Models/Protocol.php | 12 +++++++ app/Models/Tournament.php | 1 + ...4_134620_tournament_hide_round_numbers.php | 32 +++++++++++++++++++ resources/js/components/protocol/Item.js | 1 + resources/js/components/rounds/Item.js | 3 +- .../components/tournament/SettingsDialog.js | 18 +++++++++++ resources/js/i18n/de.js | 4 +++ resources/js/i18n/en.js | 4 +++ routes/api.php | 1 + 10 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2024_02_24_134620_tournament_hide_round_numbers.php diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index f53dad4..2dc7e51 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -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; diff --git a/app/Models/Protocol.php b/app/Models/Protocol.php index b747b12..60b25f2 100644 --- a/app/Models/Protocol.php +++ b/app/Models/Protocol.php @@ -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, diff --git a/app/Models/Tournament.php b/app/Models/Tournament.php index 6f0feb1..96e89b8 100644 --- a/app/Models/Tournament.php +++ b/app/Models/Tournament.php @@ -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 index 0000000..7672371 --- /dev/null +++ b/database/migrations/2024_02_24_134620_tournament_hide_round_numbers.php @@ -0,0 +1,32 @@ +boolean('show_numbers')->default(true); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tournaments', function(Blueprint $table) { + $table->dropColumn('show_numbers'); + }); + } +}; diff --git a/resources/js/components/protocol/Item.js b/resources/js/components/protocol/Item.js index 00da2ef..7dba2a3 100644 --- a/resources/js/components/protocol/Item.js +++ b/resources/js/components/protocol/Item.js @@ -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}`, diff --git a/resources/js/components/rounds/Item.js b/resources/js/components/rounds/Item.js index 949eeb2..0ef77c5 100644 --- a/resources/js/components/rounds/Item.js +++ b/resources/js/components/rounds/Item.js @@ -48,7 +48,7 @@ return
  • - {round.number ? `#${round.number} ` : '#?'} + {tournament.show_numbers && round.number ? `#${round.number} ` : ''} {t('rounds.date', { date: new Date(round.created_at) })}

    @@ -104,6 +104,7 @@ Item.propTypes = { tournament: PropTypes.shape({ participants: PropTypes.arrayOf(PropTypes.shape({ })), + show_numbers: PropTypes.bool, type: PropTypes.string, }), }; diff --git a/resources/js/components/tournament/SettingsDialog.js b/resources/js/components/tournament/SettingsDialog.js index 362cd6f..46fbfd8 100644 --- a/resources/js/components/tournament/SettingsDialog.js +++ b/resources/js/components/tournament/SettingsDialog.js @@ -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} />

    +
    + {i18n.t('tournaments.showNumbers')} + + settings(tournament, { show_numbers: value })} + value={tournament.show_numbers} + /> +

    {i18n.t('tournaments.discord')}

    @@ -140,6 +157,7 @@ SettingsDialog.propTypes = { accept_applications: PropTypes.bool, discord: PropTypes.string, locked: PropTypes.bool, + show_numbers: PropTypes.bool, }), }; diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 0d17d73..080a6dd 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -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', }, diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 3722991..f722332 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -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', }, diff --git a/routes/api.php b/routes/api.php index ca02e36..84cbf73 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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'); -- 2.39.2