From 0f1ca583dd56734a7639d1f2c0bb4f954e9f4137 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 15 Jul 2024 01:41:06 -0500 Subject: [PATCH] Work on Admin Bonus Score Index #20 Implement bonus scores Index shows a card for each bonus score Include a help modal Include a form to create a new bonus score --- .../Admin/BonusScoreDefinitionController.php | 21 +++++++- app/Models/BonusScoreDefinition.php | 2 + .../factories/BonusScoreDefinitionFactory.php | 25 ++++++++++ ..._bonus_score_audition_assignment_table.php | 7 ++- .../index-add-bonus-score-modal.blade.php | 16 ++++++ .../bonus-scores/index-help-modal.blade.php | 24 +++++++++ .../index-no-bonus-scores-message.blade.php | 22 ++++++++ .../views/admin/bonus-scores/index.blade.php | 20 +++++++- .../views/components/modal-body.blade.php | 8 +-- routes/admin.php | 10 ++-- .../Pages/Setup/BonusScoreIndexTest.php | 50 +++++++++++++++++++ 11 files changed, 191 insertions(+), 14 deletions(-) create mode 100644 database/factories/BonusScoreDefinitionFactory.php create mode 100644 resources/views/admin/bonus-scores/index-add-bonus-score-modal.blade.php create mode 100644 resources/views/admin/bonus-scores/index-help-modal.blade.php create mode 100644 resources/views/admin/bonus-scores/index-no-bonus-scores-message.blade.php diff --git a/app/Http/Controllers/Admin/BonusScoreDefinitionController.php b/app/Http/Controllers/Admin/BonusScoreDefinitionController.php index a83b356..59c8635 100644 --- a/app/Http/Controllers/Admin/BonusScoreDefinitionController.php +++ b/app/Http/Controllers/Admin/BonusScoreDefinitionController.php @@ -3,12 +3,29 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; -use Illuminate\Http\Request; +use App\Models\BonusScoreDefinition; + +use function to_route; class BonusScoreDefinitionController extends Controller { public function index() { - return view('admin.bonus-scores.index'); + $bonusScores = BonusScoreDefinition::all(); + + return view('admin.bonus-scores.index', compact('bonusScores')); + } + + public function store() + { + $validData = request()->validate([ + 'name' => 'required', + 'max_score' => 'required|numeric', + 'weight' => 'required|numeric', + ]); + + BonusScoreDefinition::create($validData); + + return to_route('admin.bonus-scores.index')->with('success', 'Bonus Score Created'); } } diff --git a/app/Models/BonusScoreDefinition.php b/app/Models/BonusScoreDefinition.php index 89cd89a..abe0d32 100644 --- a/app/Models/BonusScoreDefinition.php +++ b/app/Models/BonusScoreDefinition.php @@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model; class BonusScoreDefinition extends Model { use HasFactory; + + protected $fillable = ['name', 'max_score', 'weight']; } diff --git a/database/factories/BonusScoreDefinitionFactory.php b/database/factories/BonusScoreDefinitionFactory.php new file mode 100644 index 0000000..4dbb036 --- /dev/null +++ b/database/factories/BonusScoreDefinitionFactory.php @@ -0,0 +1,25 @@ + + */ +class BonusScoreDefinitionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->word, + 'max_score' => $this->faker->randomNumber(2), + 'weight' => $this->faker->randomFloat(2, 0, 2), + ]; + } +} diff --git a/database/migrations/2024_07_15_042419_create_bonus_score_audition_assignment_table.php b/database/migrations/2024_07_15_042419_create_bonus_score_audition_assignment_table.php index abc600d..e229bb4 100644 --- a/database/migrations/2024_07_15_042419_create_bonus_score_audition_assignment_table.php +++ b/database/migrations/2024_07_15_042419_create_bonus_score_audition_assignment_table.php @@ -15,8 +15,11 @@ return new class extends Migration { Schema::create('bonus_score_audition_assignment', function (Blueprint $table) { $table->id(); - $table->foreignIdFor(BonusScoreDefinition::class)->constrained()->onDelete('cascade')->onUpdate('cascade'); - $table->foreignIdFor(Audition::class)->constrained()->onDelete('cascade')->onUpdate('cascade'); + $table->foreignIdFor(BonusScoreDefinition::class) + ->constrained('bonus_score_definitions', 'id', 'bs_audition_assignment_bonus_score_definition_id') + ->onDelete('cascade')->onUpdate('cascade'); + $table->foreignIdFor(Audition::class) + ->constrained()->onDelete('cascade')->onUpdate('cascade'); $table->timestamps(); }); } diff --git a/resources/views/admin/bonus-scores/index-add-bonus-score-modal.blade.php b/resources/views/admin/bonus-scores/index-add-bonus-score-modal.blade.php new file mode 100644 index 0000000..9f514e3 --- /dev/null +++ b/resources/views/admin/bonus-scores/index-add-bonus-score-modal.blade.php @@ -0,0 +1,16 @@ + + + Add Bonus Score + + + + + + +
+ Create Bonus Score +
+ +
+
+
diff --git a/resources/views/admin/bonus-scores/index-help-modal.blade.php b/resources/views/admin/bonus-scores/index-help-modal.blade.php new file mode 100644 index 0000000..1235f11 --- /dev/null +++ b/resources/views/admin/bonus-scores/index-help-modal.blade.php @@ -0,0 +1,24 @@ + +

Bonus scores are most often used for an improvisation score for jazz band auditions. A bonus score + earned by an entry will be directly added + to that entries final score. When you create a bonus score, you will also specify to which auditions that bonus + score should apply. When a student + earns a bonus score for one entry, that bonus will be applied to all entries that receive that bonus score.

+ +

+ Let's say you create a bonus score called, "Saxophone Improvisation," and assign Jazz Alto, Jazz Tenor, and Jazz + Bari auditions to that bonus + score. If a student is entered on all three saxes, when they receive an improv score on one sax, that score will + apply to all 3. The system + will not allow another improv score to be assigned by the same judge unless the first one is deleted. If you + want that student to improv on each instrument + separately, you will need to create a separate bonus score for each instrument. +

+ +

+ The weight allows you to control how much influence the bonus score has on the outcome of the audition. The + bonus score is + multiplied by the weight then added to the final score. The weight may be any positive number, including + decimals. +

+
diff --git a/resources/views/admin/bonus-scores/index-no-bonus-scores-message.blade.php b/resources/views/admin/bonus-scores/index-no-bonus-scores-message.blade.php new file mode 100644 index 0000000..ed3c5fe --- /dev/null +++ b/resources/views/admin/bonus-scores/index-no-bonus-scores-message.blade.php @@ -0,0 +1,22 @@ +
+ + + +

No bonus scores have been created

+

Get started by creating a new bonus score.

+
+ +
+
+ + diff --git a/resources/views/admin/bonus-scores/index.blade.php b/resources/views/admin/bonus-scores/index.blade.php index b3c1995..60a4797 100644 --- a/resources/views/admin/bonus-scores/index.blade.php +++ b/resources/views/admin/bonus-scores/index.blade.php @@ -1,4 +1,22 @@ - + +Bonus Score Management + + @include('admin.bonus-scores.index-help-modal') + + @if($bonusScores->count() === 0) + @include('admin.bonus-scores.index-no-bonus-scores-message') + @endif + @foreach($bonusScores as $bonusScore) + + + {{ $bonusScore->name }} + + Max Points: {{ $bonusScore->max_score }} | Weight: {{ $bonusScore->weight }} + + + + @endforeach + @include('admin.bonus-scores.index-add-bonus-score-modal') diff --git a/resources/views/components/modal-body.blade.php b/resources/views/components/modal-body.blade.php index 01584c7..a18c886 100644 --- a/resources/views/components/modal-body.blade.php +++ b/resources/views/components/modal-body.blade.php @@ -1,12 +1,12 @@ -@props(['title'=>false]) +@props(['title'=>false, 'showVar'=>'showModal'])
attributes->merge(['class' => 'mr-3 text-black max-w-none']) }}>{{ $title ?? '' }} @endif -