From 6fe6cd1272c87bf7f89aa9ba59362e98c790c564 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 30 Mar 2022 11:34:27 +0200 Subject: [PATCH] round rolled by --- app/Models/Round.php | 8 +++++ .../2022_03_30_083212_round_rolled_by.php | 32 +++++++++++++++++++ resources/js/components/rounds/Item.js | 3 ++ .../js/components/rounds/SeedRolledBy.js | 23 +++++++++++++ resources/js/helpers/User.js | 4 ++- resources/js/i18n/de.js | 1 + resources/js/i18n/en.js | 1 + resources/sass/rounds.scss | 13 +++++++- 8 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2022_03_30_083212_round_rolled_by.php create mode 100644 resources/js/components/rounds/SeedRolledBy.js diff --git a/app/Models/Round.php b/app/Models/Round.php index 2c1a439..3c191bc 100644 --- a/app/Models/Round.php +++ b/app/Models/Round.php @@ -57,6 +57,10 @@ class Round extends Model return $this->hasMany(Result::class); } + public function rolled_by_user() { + return $this->belongsTo(User::class, 'rolled_by'); + } + public function tournament() { return $this->belongsTo(Tournament::class); } @@ -74,4 +78,8 @@ class Round extends Model 'tournament_id', ]; + protected $with = [ + 'rolled_by_user', + ]; + } diff --git a/database/migrations/2022_03_30_083212_round_rolled_by.php b/database/migrations/2022_03_30_083212_round_rolled_by.php new file mode 100644 index 0000000..2b6aed3 --- /dev/null +++ b/database/migrations/2022_03_30_083212_round_rolled_by.php @@ -0,0 +1,32 @@ +foreignId('rolled_by')->nullable()->default(null)->constrained('users'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('rounds', function(Blueprint $table) { + $table->dropColumn('rolled_by'); + }); + } +}; diff --git a/resources/js/components/rounds/Item.js b/resources/js/components/rounds/Item.js index fa29f54..c318eb7 100644 --- a/resources/js/components/rounds/Item.js +++ b/resources/js/components/rounds/Item.js @@ -5,6 +5,7 @@ import { withTranslation } from 'react-i18next'; import LockButton from './LockButton'; import SeedButton from './SeedButton'; import SeedCode from './SeedCode'; +import SeedRolledBy from './SeedRolledBy'; import List from '../results/List'; import ReportButton from '../results/ReportButton'; import { isRunner } from '../../helpers/permissions'; @@ -56,6 +57,8 @@ const Item = ({ round={round} tournament={tournament} /> + {' '} +

{isRunner(user, tournament) ?

diff --git a/resources/js/components/rounds/SeedRolledBy.js b/resources/js/components/rounds/SeedRolledBy.js new file mode 100644 index 0000000..cf73401 --- /dev/null +++ b/resources/js/components/rounds/SeedRolledBy.js @@ -0,0 +1,23 @@ +import PropTypes from 'prop-types'; +import React from 'react'; + +import { getAvatarUrl, getUserName } from '../../helpers/User'; +import i18n from '../../i18n'; + +const SeedRolledBy = ({ round }) => round.rolled_by_user ? + + {getUserName(round.rolled_by_user)} + +: null; + +SeedRolledBy.propTypes = { + round: PropTypes.shape({ + rolled_by_user: PropTypes.shape({ + }), + }), +}; + +export default SeedRolledBy; diff --git a/resources/js/helpers/User.js b/resources/js/helpers/User.js index c6a99c9..222e0f6 100644 --- a/resources/js/helpers/User.js +++ b/resources/js/helpers/User.js @@ -4,10 +4,12 @@ export const findResult = (user, round) => { return round.results.find(result => result.user_id == user.id); }; -export const getAvatarUrl = user => user.avatar +export const getAvatarUrl = user => user && user.avatar ? `//cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png` : '/default-avatar.png'; +export const getUserName = user => (user && (user.nickname || user.username)) || ''; + export const hasFinishedRound = (user, round) => { const result = findResult(user, round); return result && result.has_finished; diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 17cb41f..09d6db7 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -166,6 +166,7 @@ export default { lockError: 'Fehler beim Sperren', lockIncompleteWarning: 'Achtung: Noch nicht alle Runner haben ihr Ergebnis für diese Runde eingereicht!', lockSuccess: 'Runde gesperrt', + rolledBy: 'Gerollt von {{name}}', seed: 'Seed', setSeed: 'Seed eintragen', setSeedError: 'Seed konnte nicht eintragen werden', diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index f0c6871..72548f6 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -166,6 +166,7 @@ export default { lockError: 'Error locking round', lockIncompleteWarning: 'Warning: Not all runners have submitted their results for this round yet!', lockSuccess: 'Round locked', + rolledBy: 'Rolled by {{name}}', seed: 'Seed', setSeed: 'Set seed', setSeedError: 'Seed could not be set', diff --git a/resources/sass/rounds.scss b/resources/sass/rounds.scss index 4145523..d8d117d 100644 --- a/resources/sass/rounds.scss +++ b/resources/sass/rounds.scss @@ -20,7 +20,18 @@ font-size: 125%; } - .seed-code, .btn { + .rolled-by { + display: inline-block; + vertical-align: middle; + + img { + max-height: 2rem; + width: auto; + border-radius: 50%; + } + } + + .seed-code, .btn, .rolled-by { margin-bottom: 1ex; } } -- 2.39.2