KTVCentral/app/Livewire/Tables/SongLibraryCacheTable.php

122 lines
5.5 KiB
PHP
Raw Normal View History

<?php
2025-07-01 10:36:00 +08:00
namespace App\Livewire\Tables;
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();
2025-08-03 22:00:08 +08:00
$header->includeViewOnTop('livewire.headers.song-library-cache');
$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')
2025-06-11 10:26:40 +08:00
->add('add_date_formatted', fn (SongLibraryCache $model) => Carbon::parse($model->add_date)->format('Y-m-d'))
->add('situation')
->add('vocal')
->add('db_change')
->add('song_counts')
2025-06-11 10:26:40 +08:00
->add('updated_at_formatted', fn (SongLibraryCache $model) => Carbon::parse($model->updated_at)->format('Y-m-d H:i:s'));
}
public function columns(): array
{
$column=[];
2025-06-11 10:26:40 +08:00
$column[]=Column::make(__('song-library-cache.id'), 'song_id');
$column[]=Column::make(__('song-library-cache.name'), 'song_name')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.simplified'), 'song_simplified')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.name.phinetic'), 'phonetic_abbr')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.name.pinyin'), 'pinyin_abbr')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.name.strokes'), 'strokes_abbr')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.name_length'), 'song_number')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.artists').'A', 'artistA')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.artists').'B', 'artistB')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.artists_simplified').'A', 'artistA_simplified')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.artists_simplified').'B', 'artistB_simplified')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.artists_category').'A', 'artistA_category')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.artists_category').'B', 'artistB_category')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.artists_category'), 'artist_category')->sortable()->searchable()->hidden(true, false);
$column[]=Column::make(__('song-library-cache.filename'), 'song_filename')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.categorys'), 'song_category')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.language_type'), 'language_name')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.adddate'), 'add_date_formatted', 'add_date')->sortable();
$column[]=Column::make(__('song-library-cache.situation'), 'situation')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.vocal'), 'vocal')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.db_change'), 'db_change')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.counts'), 'song_counts')->sortable()->searchable();
$column[]=Column::make(__('song-library-cache.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'),
];
}
}