210 lines
6.4 KiB
PHP
210 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use App\Models\Song;
|
|
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;
|
|
use PowerComponents\LivewirePowerGrid\Traits\WithExport;
|
|
use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable;
|
|
use PowerComponents\LivewirePowerGrid\Facades\Rule;
|
|
use Livewire\Attributes\On;
|
|
|
|
final class SongTable extends PowerGridComponent
|
|
{
|
|
public string $tableName = 'song-table';
|
|
|
|
public bool $showFilters = false;
|
|
|
|
public function boot(): void
|
|
{
|
|
config(['livewire-powergrid.filter' => 'outside']);
|
|
}
|
|
|
|
public function setUp(): array
|
|
{
|
|
$this->showCheckBox();
|
|
|
|
return [
|
|
PowerGrid::exportable(fileName: 'song-file')
|
|
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV),
|
|
PowerGrid::header()
|
|
->showSoftDeletes()
|
|
->showToggleColumns()
|
|
->showSearchInput(),
|
|
PowerGrid::footer()
|
|
->showPerPage()
|
|
->showRecordCount(),
|
|
];
|
|
}
|
|
|
|
public function header(): array
|
|
{
|
|
return [
|
|
Button::add('bulk-delete')
|
|
->slot('Bulk delete (<span x-text="window.pgBulkActions.count(\'' . $this->tableName . '\')"></span>)')
|
|
->icon('solid-trash',['id' => 'my-custom-icon-id', 'class' => 'font-bold'])
|
|
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
|
|
->dispatch('bulkDelete.' . $this->tableName, []),
|
|
];
|
|
}
|
|
|
|
public function datasource(): Builder
|
|
{
|
|
return Song::query();
|
|
}
|
|
|
|
public function relationSearch(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function fields(): PowerGridFields
|
|
{
|
|
return PowerGrid::fields()
|
|
->add('id')
|
|
->add('name')
|
|
->add('adddate_formatted', fn (Song $model) => Carbon::parse($model->adddate)->format('d/m/Y'))
|
|
->add('filename')
|
|
->add('language_type')
|
|
->add('db_change')
|
|
->add('vocal')
|
|
->add('situation')
|
|
->add('copyright01')
|
|
->add('copyright02')
|
|
->add('note01')
|
|
->add('note02')
|
|
->add('note03')
|
|
->add('note04')
|
|
->add('enable')
|
|
->add('unnamed_21')
|
|
->add('simplified')
|
|
->add('phonetic_abbr')
|
|
->add('pinyin_abbr')
|
|
->add('created_at_formatted', fn (Song $model) => Carbon::parse($model->created_at)->format('d/m/Y H:i:s'));
|
|
}
|
|
|
|
public function columns(): array
|
|
{
|
|
return [
|
|
Column::make(__('songs.id'), 'id'),
|
|
Column::make(__('songs.name'), 'name')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.adddate'), 'adddate_formatted', 'adddate')
|
|
->sortable(),
|
|
|
|
Column::make(__('songs.filename'), 'filename')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.language_type'), 'language_type'),
|
|
Column::make('Db change', 'db_change'),
|
|
Column::make(__('songs.vocal'), 'vocal'),
|
|
Column::make(__('songs.situation'), 'situation')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.copyright01'), 'copyright01')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.copyright02'), 'copyright02')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.note01'), 'note01')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.note02'), 'note02')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.note03'), 'note03')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.note04'), 'note04')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.enable'), 'enable'),
|
|
Column::make('Unnamed 21', 'unnamed_21')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.simplified'), 'simplified')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.name.phinetic'), 'phonetic_abbr')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make(__('songs.name.pinyin'), 'pinyin_abbr')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
Column::make('Created at', 'created_at_formatted', 'created_at')
|
|
->sortable(),
|
|
|
|
Column::action(__('songs.actions'))
|
|
];
|
|
}
|
|
|
|
public function filters(): array
|
|
{
|
|
return [
|
|
Filter::datepicker('adddate'),
|
|
Filter::datetimepicker('created_at'),
|
|
];
|
|
}
|
|
|
|
#[On('bulkDelete.{tableName}')]
|
|
public function bulkDelete(): void
|
|
{
|
|
$this->js('alert(window.pgBulkActions.get(\'' . $this->tableName . '\'))');
|
|
if($this->checkboxValues){
|
|
Artist::destroy($this->checkboxValues);
|
|
$this->js('window.pgBulkActions.clearAll()'); // clear the count on the interface.
|
|
}
|
|
}
|
|
|
|
public function actions(Song $row): array
|
|
{
|
|
return [
|
|
|
|
Button::add('edit')
|
|
->slot(__('songs.edit'))
|
|
->icon('solid-pencil-square')
|
|
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
|
|
->dispatchTo('admin.song-form', 'openEditSongModal', ['id' => $row->id]),
|
|
Button::add('delete')
|
|
->slot(__('songs.delete'))
|
|
->icon('solid-trash')
|
|
->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
|
|
->dispatchTo('admin.song-form', 'deleteSong', ['id' => $row->id]),
|
|
];
|
|
}
|
|
|
|
/*
|
|
public function actionRules($row): array
|
|
{
|
|
return [
|
|
// Hide button edit for ID 1
|
|
Rule::button('edit')
|
|
->when(fn($row) => $row->id === 1)
|
|
->hide(),
|
|
];
|
|
}
|
|
*/
|
|
}
|