122 lines
5.0 KiB
PHP
122 lines
5.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Livewire\Admin;
|
||
|
|
||
|
use App\Models\SongLibraryCache;
|
||
|
use Illuminate\Support\Carbon;
|
||
|
use Illuminate\Database\Eloquent\Builder;
|
||
|
use PowerComponents\LivewirePowerGrid\Button;
|
||
|
use PowerComponents\LivewirePowerGrid\Column;
|
||
|
use PowerComponents\LivewirePowerGrid\Facades\Filter;
|
||
|
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
|
||
|
use PowerComponents\LivewirePowerGrid\PowerGridFields;
|
||
|
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
|
||
|
|
||
|
final class SongLibraryCacheTable extends PowerGridComponent
|
||
|
{
|
||
|
public string $tableName = 'song-library-cache-table';
|
||
|
public string $primaryKey = 'song_id';
|
||
|
public string $sortField = 'song_id';
|
||
|
public bool $useQueryBuilderPagination = true;
|
||
|
|
||
|
public bool $canDownload;
|
||
|
|
||
|
public function boot(): void
|
||
|
{
|
||
|
config(['livewire-powergrid.filter' => 'outside']);
|
||
|
|
||
|
}
|
||
|
|
||
|
public function setUp(): array
|
||
|
{
|
||
|
|
||
|
$actions = [];
|
||
|
|
||
|
$header = PowerGrid::header()
|
||
|
->withoutLoading()
|
||
|
->showToggleColumns();
|
||
|
|
||
|
$header->includeViewOnTop('livewire.admin.song-library-cache-header');
|
||
|
|
||
|
$actions[]=$header;
|
||
|
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
|
||
|
return $actions;
|
||
|
}
|
||
|
|
||
|
public function datasource(): Builder
|
||
|
{
|
||
|
return SongLibraryCache::query()->orderBy('song_id');
|
||
|
}
|
||
|
|
||
|
public function relationSearch(): array
|
||
|
{
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
public function fields(): PowerGridFields
|
||
|
{
|
||
|
return PowerGrid::fields()
|
||
|
->add('song_id')
|
||
|
->add('song_name')
|
||
|
->add('song_simplified')
|
||
|
->add('phonetic_abbr')
|
||
|
->add('pinyin_abbr')
|
||
|
->add('strokes_abbr')
|
||
|
->add('song_number')
|
||
|
->add('artistA')
|
||
|
->add('artistB')
|
||
|
->add('artistA_simplified')
|
||
|
->add('artistB_simplified')
|
||
|
->add('artistA_category')
|
||
|
->add('artistB_category')
|
||
|
->add('artist_category')
|
||
|
->add('song_filename')
|
||
|
->add('song_category')
|
||
|
->add('language_name')
|
||
|
->add('add_date_formatted', fn (SongLibraryCache $model) => Carbon::parse($model->add_date)->format('d/m/Y'))
|
||
|
->add('situation')
|
||
|
->add('vocal')
|
||
|
->add('db_change')
|
||
|
->add('song_counts')
|
||
|
->add('updated_at_formatted', fn (SongLibraryCache $model) => Carbon::parse($model->updated_at)->format('d/m/Y H:i:s'));
|
||
|
}
|
||
|
|
||
|
public function columns(): array
|
||
|
{
|
||
|
$column=[];
|
||
|
$column[]=Column::make('Song id', 'song_id');
|
||
|
$column[]=Column::make('Song name', 'song_name')->sortable()->searchable();
|
||
|
$column[]=Column::make('Song simplified', 'song_simplified')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('Phonetic abbr', 'phonetic_abbr')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('Pinyin abbr', 'pinyin_abbr')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('Strokes abbr', 'strokes_abbr')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('Song number', 'song_number')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('ArtistA', 'artistA')->sortable()->searchable();
|
||
|
$column[]=Column::make('ArtistB', 'artistB')->sortable()->searchable();
|
||
|
$column[]=Column::make('ArtistA simplified', 'artistA_simplified')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('ArtistB simplified', 'artistB_simplified')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('ArtistA category', 'artistA_category')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('ArtistB category', 'artistB_category')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('Artist category', 'artist_category')->sortable()->searchable()->hidden(true, false);
|
||
|
$column[]=Column::make('Song filename', 'song_filename')->sortable()->searchable();
|
||
|
$column[]=Column::make('Song category', 'song_category')->sortable()->searchable();
|
||
|
$column[]=Column::make('Language name', 'language_name')->sortable()->searchable();
|
||
|
$column[]=Column::make('Add date', 'add_date_formatted', 'add_date')->sortable();
|
||
|
$column[]=Column::make('Situation', 'situation')->sortable()->searchable();
|
||
|
$column[]=Column::make('Vocal', 'vocal')->sortable()->searchable();
|
||
|
$column[]=Column::make('Db change', 'db_change')->sortable()->searchable();
|
||
|
$column[]=Column::make('Song counts', 'song_counts')->sortable()->searchable();
|
||
|
$column[]=Column::make('Updated at', 'updated_at_formatted', 'updated_at')->sortable()->hidden(true, false);
|
||
|
return $column;
|
||
|
}
|
||
|
|
||
|
public function filters(): array
|
||
|
{
|
||
|
return [
|
||
|
Filter::datepicker('add_date'),
|
||
|
Filter::datetimepicker('updated_at'),
|
||
|
];
|
||
|
}
|
||
|
|
||
|
}
|