]> git.localhorst.tv Git - alttp.git/commitdiff
round rolled by
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 30 Mar 2022 09:34:27 +0000 (11:34 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 30 Mar 2022 09:34:27 +0000 (11:34 +0200)
app/Models/Round.php
database/migrations/2022_03_30_083212_round_rolled_by.php [new file with mode: 0644]
resources/js/components/rounds/Item.js
resources/js/components/rounds/SeedRolledBy.js [new file with mode: 0644]
resources/js/helpers/User.js
resources/js/i18n/de.js
resources/js/i18n/en.js
resources/sass/rounds.scss

index 2c1a43963897563cfe2686245418dc5f9c149e38..3c191bc17efb200d65b1263371dec4599d93b508 100644 (file)
@@ -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 (file)
index 0000000..2b6aed3
--- /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('rounds', function(Blueprint $table) {
+                       $table->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');
+               });
+       }
+};
index fa29f5404daeb71e71a5a5265292cfdc3faf5ccf..c318eb7910d3347b771f5101969f1416c12fff90 100644 (file)
@@ -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}
                        />
+                       {' '}
+                       <SeedRolledBy round={round} />
                </p>
                {isRunner(user, tournament) ?
                        <p className="report">
diff --git a/resources/js/components/rounds/SeedRolledBy.js b/resources/js/components/rounds/SeedRolledBy.js
new file mode 100644 (file)
index 0000000..cf73401
--- /dev/null
@@ -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 ?
+       <span
+               className="rolled-by"
+               title={i18n.t('rounds.rolledBy', { name: getUserName(round.rolled_by_user) })}
+       >
+               <img alt={getUserName(round.rolled_by_user)} src={getAvatarUrl(round.rolled_by_user)} />
+       </span>
+: null;
+
+SeedRolledBy.propTypes = {
+       round: PropTypes.shape({
+               rolled_by_user: PropTypes.shape({
+               }),
+       }),
+};
+
+export default SeedRolledBy;
index c6a99c9dfe4d60e5918ef93a345615111ecc6316..222e0f6af392681756aaf1a46a222318aec34c01 100644 (file)
@@ -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;
index 17cb41f0cc49e96fe30d77a3f17d01d91a5324ed..09d6db7ea1690b0c244b58a37f68dcfe4f6697c3 100644 (file)
@@ -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',
index f0c6871e1ef499e075721bb15b82536b5f1fe97a..72548f6a815801752217ea7bb687fd8211b9d1a6 100644 (file)
@@ -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',
index 414552363f85ef1d2802924e856eb6aad8e08d5c..d8d117db805f729859c1a0b4bf98c883401369d5 100644 (file)
                                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;
                        }
                }