Update Submissions and add fields

This commit is contained in:
2026-06-10 11:04:26 +02:00
parent 1d8ea70b72
commit 4f9f6c63b3
64 changed files with 2278 additions and 174 deletions

View File

@@ -3,13 +3,16 @@
namespace App\Livewire;
use App\Models\Author;
use App\Models\Category;
use App\Models\Entry;
use App\Models\Game;
use App\Models\Genre;
use App\Models\Language;
use App\Models\Level;
use App\Models\Modification;
use App\Models\Platform;
use App\Models\Status;
use App\Models\System;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;
@@ -114,6 +117,41 @@ class Database extends Component
#[Url(except:'or')]
public string $modificationsMode = 'or';
/**
* Categories IDs filter.
* @var array
*/
#[Url(except:[])]
public array $categories = [];
/**
* Categories mode and/or
* @var string
*/
#[Url(except:['or'])]
public string $categoriesMode = 'or';
/**
* Systems IDs filter.
* @var array
*/
#[Url(except:[])]
public array $systems = [];
/**
* Systems mode and/or
* @var string
*/
#[Url(except:['or'])]
public string $systemsMode = 'or';
/**
* Levels IDs filter.
* @var array
*/
#[Url(except:[])]
public array $levels = [];
/**
* Sort by field.
* @var string
@@ -164,11 +202,16 @@ class Database extends Component
public function updatedLanguagesMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function updatedModifications(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function updatedModificationsMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function updatedCategories(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function updatedCategoriesMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function updatedSystems(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function updatedSystemsMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function updatedLevels(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
public function clearFilters(): void
{
$this->reset([
'search', 'types', 'platforms', 'genres', 'statuses', 'authors', 'authorsMode', 'languages', 'languagesMode', 'modifications', 'modificationsMode'
'search', 'types', 'platforms', 'genres', 'statuses', 'authors', 'authorsMode', 'languages', 'languagesMode', 'modifications', 'modificationsMode', 'categories', 'categoriesMode', 'systems', 'systemsMode', 'levels'
]);
$this->resetPage();
}
@@ -188,7 +231,7 @@ class Database extends Component
private function buildQuery()
{
$query = Entry::query()->published()->with([
'game.platform', 'game.genre', 'status', 'authors', 'languages'
'game.platform', 'game.genre', 'status', 'authors', 'languages', 'level', 'systems', 'categories', 'modifications'
]);
if( $this->search ) {
@@ -253,6 +296,30 @@ class Database extends Component
}
}
if( $this->levels ) {
$query->whereIn('level_id', $this->levels);
}
if( $this->categories ) {
if( $this->categoriesMode === 'and' ) {
foreach ( $this->categories as $categoryId ) {
$query->whereHas('categories', fn($q) => $q->where('categories.id', $categoryId));
}
} else {
$query->whereHas('categories', fn($q) => $q->whereIn('categories.id', $this->categories));
}
}
if( $this->systems ) {
if( $this->systemsMode === 'and' ) {
foreach ( $this->systems as $systemId ) {
$query->whereHas('systems', fn($q) => $q->where('systems.id', $systemId));
}
} else {
$query->whereHas('systems', fn($q) => $q->whereIn('systems.id', $this->systems));
}
}
return $query->orderBy($this->sortBy, $this->sortDir);
}
@@ -267,6 +334,9 @@ class Database extends Component
'allAuthors' => Author::orderBy('name')->get(),
'allLanguages' => Language::orderBy('name')->get(),
'allModifications' => Modification::orderBy('name')->get(),
'allCategories' => Category::orderBy('name')->get(),
'allLevels' => Level::orderBy('name')->get(),
'allSystems' => System::orderBy('name')->get(),
]);
}
}

View File

@@ -16,6 +16,17 @@ class GameSelector extends Component
public const int REQUIRED_CHARS = 3;
/**
* Which section we can change selection mode.
*/
public const array CHANGE_SECTION_MODE = [ 'utilities', 'documents' ];
/**
* Selection mode between game|platform|none.
* @var string
*/
public string $selectionMode = 'game';
/**
* If we are in new game mode.
* @var bool
@@ -70,9 +81,25 @@ class GameSelector extends Component
*/
public bool $dropdown = false;
public function mount( ?int $gameId = null, ?string $newGameTitle = null, ?int $newGamePlatform = null, ?int $newGameGenre = null ): void
/**
* In platform mode.
* @var int|null
*/
public ?int $platformModeId = null;
/**
* In platform mode.
* @var string|null
*/
public ?string $platformModeName = null;
public ?string $section = null;
public function mount( ?int $gameId = null, ?string $newGameTitle = null, ?int $newGamePlatform = null, ?int $newGameGenre = null, ?string $section, ?int $platformOnlyId ): void
{
$this->section = $section;
// If we selected an existent game.
if( $gameId ){
$game = Game::with(['platform','genre'])->find($gameId);
@@ -93,6 +120,36 @@ class GameSelector extends Component
$this->gamePlatformId = is_numeric($newGamePlatform) ? (int) $newGamePlatform : null;
$this->gameGenreId = is_numeric($newGameGenre) ? (int) $newGameGenre : null;
}
if( in_array( $section, self::CHANGE_SECTION_MODE ) ) {
if ($platformOnlyId) {
$this->selectionMode = 'platform';
$this->platformModeId = $platformOnlyId;
$platform = Platform::find($platformOnlyId);
if ($platform) {
$this->platformModeName = $platform->name;
} else {
$this->platformModeId = null;
}
}
}
}
public function setSelectionMode(string $mode): void
{
if( !in_array( $this->section, self::CHANGE_SECTION_MODE ) )
return;
$this->selectionMode = $mode;
if( $mode !== 'game' ){
$this->clearGame();
$this->newGame = false;
}
if( $mode !== 'platform' ){
$this->platformModeId = null;
$this->platformModeName = null;
}
}
/**
@@ -134,6 +191,15 @@ class GameSelector extends Component
}
public function selectPlatformOnly( int $id ): void
{
$platform = Platform::find($id);
if( $platform ){
$this->platformModeId = $platform->id;
$this->platformModeName = $platform->name;
}
}
/**
* Clear existent game selection.
* @return void
@@ -179,6 +245,10 @@ class GameSelector extends Component
}
$data['hasOldNewGame'] = old('new-game-title') || old('new-game-platform') || old('new-game-genre');
$data['canChangeSelection'] = in_array( $this->section, self::CHANGE_SECTION_MODE );
if( in_array( $this->section, self::CHANGE_SECTION_MODE ) )
$data['platforms'] = Platform::orderBy('name')->get();
return view('livewire.game-selector', $data );
}
}