Skip to content

Commit

Permalink
Feat/add score system (#534)
Browse files Browse the repository at this point in the history
* Init Commit

* Pair programming
Co-authored-by: PhilPinsdorf

* Added Random Generator Frontend

* Removed Scaleup Animation because it is not used

* Fix darkmode

* lint code

* Fixed Font

* Add scoresystem

* Fixed AvatarCard

* Fixed Transition Component

* Fixed single-file component element order

* Added Name for Display Route

* Set new Location for AvatarCard

* Fixed isFetchingRandomGenerator

* Fixed Naming

* Fixed Transiotin, Audio and added Riser

* Adjust display of name

* Regenerate components file

* Lint code and fix typo

---------

Co-authored-by: Phil Pinsdorf <[email protected]>
  • Loading branch information
TitusKirch and PhilPinsdorf authored Oct 29, 2023
1 parent 9e03851 commit c22520c
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 80 deletions.
25 changes: 25 additions & 0 deletions app/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,31 @@ public function randomGeneratorState(): JsonResponse
return response()->json(json_decode($state->value));
}

/**
* Return the current state of the score system.
* The state is structured like this:
* {
* "teams": {
* "name": string;
* "score": string;
* }[];
* }
*/
public function scoreSystemState(): JsonResponse
{
// get state with key scoreSystem
$state = State::where('key', 'scoreSystem')->first();

// if state does not exist, return setup
if (! $state) {
return response()->json([
'teams' => [],
]);
}

return response()->json(json_decode($state->value));
}

/**
* Fresh users data
*/
Expand Down
69 changes: 69 additions & 0 deletions app/Http/Controllers/DashboardAdminScoreSystemController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Http\Controllers;

use App\Models\State;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Request;
use Inertia\Inertia;
use Inertia\Response;

class DashboardAdminScoreSystemController extends Controller
{
/**
* Display the dashboard admin score system page
*/
public function index(): Response
{
// check if a state exists or we need to create a new one
$state = State::where('key', 'scoreSystem')->first();
if (! $state) {
$state = new State();
$state->key = 'scoreSystem';
}

return Inertia::render('Dashboard/Admin/ScoreSystem/Index', [
'state' => json_decode($state->value),
]);
}

/**
* Execute the dashboard admin score system submit action
*/
public function indexExecuteSubmit(): JsonResponse
{
// validate the request
$request = Request::validate([
'teams.*.name' => ['required', 'string'],
'teams.*.score' => ['required', 'string'],
]);

// check if a state exists or we need to create a new one
$state = State::where('key', 'scoreSystem')->first();
if (! $state) {
$state = new State();
$state->key = 'scoreSystem';
}

// update the state
$state->value = json_encode([
'teams' => $request['teams'],
]);

// save the state
$state->save();

// return success
return response()->json([
'success' => true,
]);
}

/*
* Display the dashboard admin score system display page
*/
public function display(): Response
{
return Inertia::render('Dashboard/Admin/ScoreSystem/Display');
}
}
4 changes: 4 additions & 0 deletions database/seeders/ModuleDemoSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function run(): void
'key' => 'randomGenerator',
'active' => true,
],
[
'key' => 'scoreSystem',
'active' => true,
],
];

foreach ($modules as $module) {
Expand Down
4 changes: 4 additions & 0 deletions database/seeders/ModuleGerolsteinSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public function run(): void
'key' => 'randomGenerator',
'active' => true,
],
[
'key' => 'scoreSystem',
'active' => true,
],
];

foreach ($modules as $module) {
Expand Down
4 changes: 4 additions & 0 deletions database/seeders/ModuleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function run(): void
'key' => 'randomGenerator',
'active' => false,
],
[
'key' => 'scoreSystem',
'active' => false,
],
];

foreach ($modules as $module) {
Expand Down
4 changes: 4 additions & 0 deletions database/seeders/RoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function run(): void
'manage events',
'manage users',
'manage random generator',
'manage score system',
] as $permission) {
if (! Permission::where('name', $permission)->exists()) {
Permission::create(['name' => $permission]);
Expand All @@ -40,6 +41,7 @@ public function run(): void
}
$stageTutorRole = Role::where('name', 'stage tutor')->first();
$stageTutorRole->givePermissionTo($permissions['manage random generator']);
$stageTutorRole->givePermissionTo($permissions['manage score system']);

// create esa role if it doesn't exist
if (! Role::where('name', 'esa')->exists()) {
Expand All @@ -58,6 +60,7 @@ public function run(): void
$adminRole->givePermissionTo($permissions['view hidden event details']);
$adminRole->givePermissionTo($permissions['manage events']);
$adminRole->givePermissionTo($permissions['manage random generator']);
$adminRole->givePermissionTo($permissions['manage score system']);
$adminRole->givePermissionTo($permissions['manage users']);

// create super admin role if it doesn't exist
Expand All @@ -69,6 +72,7 @@ public function run(): void
$superAdminRole->givePermissionTo($permissions['view hidden event details']);
$superAdminRole->givePermissionTo($permissions['manage events']);
$superAdminRole->givePermissionTo($permissions['manage random generator']);
$superAdminRole->givePermissionTo($permissions['manage score system']);
$superAdminRole->givePermissionTo($permissions['manage users']);

// create special role if it doesn't exist
Expand Down
33 changes: 33 additions & 0 deletions resources/js/components/app/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@
>
Zufallsgenerator
</InertiaLink>
<InertiaLink
v-if="
modules['scoreSystem']?.active &&
user.permissionsArray.includes('manage score system')
"
href="/dashboard/admin/score-system"
:class="{
'border-red-500 text-red-900':
$page.url == '/dashboard/admin/score-system',
'border-transparent text-red-500 hover:border-red-300 hover:text-red-700':
$page.url != '/dashboard/admin/score-system',
}"
class="inline-flex items-center border-b-[3px] px-1 pt-1 text-sm font-medium"
>
Punktesystem
</InertiaLink>
<InertiaLink
v-if="user.permissionsArray.includes('manage users')"
href="/dashboard/admin/users"
Expand Down Expand Up @@ -177,6 +193,23 @@
>
Zufallsgenerator
</DisclosureButton>
<DisclosureButton
v-if="
modules['scoreSystem']?.active &&
user.permissionsArray.includes('manage score system')
"
:as="InertiaLink"
href="/dashboard/admin/score-system"
:class="{
'border-red-500 bg-red-100 text-red-900 dark:bg-black dark:text-red-500':
$page.url == '/dashboard/admin/score-system',
'border-transparent text-red-600 hover:border-red-300 hover:bg-red-50 hover:text-red-800 dark:text-red-400 dark:hover:bg-gray-900 dark:hover:text-red-100':
$page.url != '/dashboard/admin/score-system',
}"
class="block border-l-4 py-2 pl-3 pr-4 text-base font-medium"
>
Punktesystem
</DisclosureButton>
<DisclosureButton
v-if="user.permissionsArray.includes('manage users')"
:as="InertiaLink"
Expand Down
5 changes: 3 additions & 2 deletions resources/js/components/random/generator/user/AvatarCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<img v-if="props.src" :src="props.src" class="h-fit" />
<div
v-else
class="flex h-[30rem] transform items-center justify-center text-center font-eighty-miles text-8xl text-white"
class="flex h-[30rem] transform flex-col items-center justify-center text-center font-eighty-miles text-8xl text-white"
>
<span>{{ props.firstname }} {{ props.lastname }}</span>
<span>{{ props.firstname }}</span>
<span>{{ props.lastname }}</span>
</div>
</div>
</template>
Expand Down
9 changes: 9 additions & 0 deletions resources/js/layouts/DisplayLayout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<div
class="flex h-screen flex-col overflow-hidden bg-slate-950 bg-[url('/images/random-generator/background/comic-yellow.jpg')] bg-cover"
>
<div class="flex-grow">
<slot />
</div>
</div>
</template>
7 changes: 0 additions & 7 deletions resources/js/layouts/RandomGeneratorLayout.vue

This file was deleted.

Loading

0 comments on commit c22520c

Please sign in to comment.