202509051423
邏輯整理
This commit is contained in:
parent
10b8a8c95c
commit
c6a9f80839
@ -26,10 +26,12 @@ final class ArtistTable extends PowerGridComponent
|
||||
use WithExport, WireUiActions;
|
||||
|
||||
public string $tableName = 'artist-table';
|
||||
public bool $canCreate;
|
||||
public bool $canEdit;
|
||||
public bool $canDownload;
|
||||
public bool $canDelect;
|
||||
public bool $canCreate = false;
|
||||
public bool $canEdit = false;
|
||||
public bool $canDownload = false;
|
||||
public bool $canDelect = false;
|
||||
|
||||
public ?string $category = null;
|
||||
|
||||
//public bool $deferLoading = true;
|
||||
//public string $loadingComponent = 'components.power-grid-loading';
|
||||
@ -94,7 +96,17 @@ final class ArtistTable extends PowerGridComponent
|
||||
{
|
||||
return PowerGrid::fields()
|
||||
->add('id')
|
||||
->add('category_str', function (Artist $model) {
|
||||
->add('category_str', fn (Artist $model) => $this->renderCategory($model))
|
||||
->add('name')
|
||||
->add('simplified')
|
||||
->add('phonetic_abbr')
|
||||
->add('pinyin_abbr')
|
||||
->add('strokes_abbr')
|
||||
->add('enable')
|
||||
->add('created_at_formatted', fn (Artist $model) => Carbon::parse($model->created_at)->format('Y-m-d H:i:s'));
|
||||
}
|
||||
private function renderCategory(Artist $model): string
|
||||
{
|
||||
if ($this->canEdit) {
|
||||
return Blade::render(
|
||||
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
@ -106,17 +118,7 @@ final class ArtistTable extends PowerGridComponent
|
||||
]
|
||||
);
|
||||
}
|
||||
// 沒有權限就顯示對應的文字
|
||||
|
||||
return $model->category->labelPowergridFilter(); // 假設 label() 會回傳顯示文字
|
||||
} )
|
||||
->add('name')
|
||||
->add('simplified')
|
||||
->add('phonetic_abbr')
|
||||
->add('pinyin_abbr')
|
||||
->add('strokes_abbr')
|
||||
->add('enable')
|
||||
->add('created_at_formatted', fn (Artist $model) => Carbon::parse($model->created_at)->format('Y-m-d H:i:s'));
|
||||
return $model->category->labelPowergridFilter();
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
@ -125,16 +127,11 @@ final class ArtistTable extends PowerGridComponent
|
||||
$column[]=Column::make(__('artists.no'), 'id');
|
||||
$column[]=Column::make(__('artists.category'),'category_str', 'artists.category')->searchable();
|
||||
$column[]=Column::make(__('artists.name'), 'name')->sortable()->searchable()
|
||||
->editOnClick(
|
||||
hasPermission: $this->canEdit,
|
||||
dataField: 'name',
|
||||
fallback: 'N/A',
|
||||
saveOnMouseOut: true
|
||||
);
|
||||
$column[]=Column::make(__('artists.name.simplified'), 'simplified')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('artists.name.phinetic'), 'phonetic_abbr')->sortable()->searchable();
|
||||
$column[]=Column::make(__('artists.name.pinyin'), 'pinyin_abbr')->sortable()->searchable();
|
||||
$column[]=Column::make(__('artists.name.strokes'), 'strokes_abbr')->sortable()->searchable();
|
||||
->editOnClick(hasPermission: $this->canEdit, dataField: 'name', fallback: 'N/A', saveOnMouseOut: true);
|
||||
$column[]=Column::make(__('artists.name_simplified'), 'simplified')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('artists.name_phinetic'), 'phonetic_abbr')->sortable()->searchable();
|
||||
$column[]=Column::make(__('artists.name_pinyin'), 'pinyin_abbr')->sortable()->searchable();
|
||||
$column[]=Column::make(__('artists.name_strokes'), 'strokes_abbr')->sortable()->searchable();
|
||||
$column[]=Column::make(__('artists.enable'), 'enable')->toggleable(hasPermission: $this->canEdit, trueLabel: 'yes', falseLabel: 'no');
|
||||
$column[]=Column::make('Created at', 'created_at_formatted', 'created_at')->sortable()->hidden(true, false);
|
||||
$column[]=Column::action(__('artists.actions'));
|
||||
@ -194,8 +191,8 @@ final class ArtistTable extends PowerGridComponent
|
||||
->datasource(ArtistCategory::cases())
|
||||
->optionLabel('artists.category'),
|
||||
Filter::inputText('name')->placeholder(__('artists.name')),
|
||||
Filter::inputText('phonetic_abbr')->placeholder(__('artists.name.phinetic')),
|
||||
Filter::inputText('pinyin_abbr')->placeholder(__('artists.name.pinyin')),
|
||||
Filter::inputText('phonetic_abbr')->placeholder(__('artists.name_phinetic')),
|
||||
Filter::inputText('pinyin_abbr')->placeholder(__('artists.name_pinyin')),
|
||||
Filter::number('strokes_abbr')->thousands('.')->decimal(','),
|
||||
Filter::boolean('enable')->label('✅', '❌'),
|
||||
Filter::datetimepicker('created_at'),
|
||||
|
@ -27,10 +27,13 @@ final class SongTable extends PowerGridComponent
|
||||
use WithExport, WireUiActions;
|
||||
|
||||
public string $tableName = 'song-table';
|
||||
public bool $canCreate;
|
||||
public bool $canEdit;
|
||||
public bool $canDownload;
|
||||
public bool $canDelect;
|
||||
public bool $canCreate = false;
|
||||
public bool $canEdit = false;
|
||||
public bool $canDownload = false;
|
||||
public bool $canDelect = false;
|
||||
|
||||
public ?string $language_type = null;
|
||||
public ?string $situation = null;
|
||||
|
||||
/* public bool $deferLoading = true;
|
||||
|
||||
@ -102,31 +105,11 @@ final class SongTable extends PowerGridComponent
|
||||
->add('filename')
|
||||
->add('adddate_formatted', fn (Song $model) => Carbon::parse($model->adddate)->format('Y-m-d'))
|
||||
->add('song_artists' ,fn(Song $model)=> $model->str_artists())
|
||||
//->add('language_type_str', fn (Song $model) => SongLanguageType::from($model->language_type->value)->labels())
|
||||
->add('language_type_str', function (Song $model) {
|
||||
return Blade::render(
|
||||
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
[
|
||||
'options' => SongLanguageType::options(),
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'language_type',
|
||||
'selected' => $model->language_type->value
|
||||
]);
|
||||
} )
|
||||
->add('language_type_str', fn (Song $model) => $this->renderLanguageType($model))
|
||||
->add('song_categories', fn(Song $model) => $model->str_categories())
|
||||
->add('db_change')
|
||||
->add('vocal')
|
||||
//->add('situation_str', fn (Song $model) => SongSituation::from($model->situation->value)->labels())
|
||||
->add('situation_str', function (Song $model){
|
||||
return Blade::render(
|
||||
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
[
|
||||
'options' => SongSituation::options(),
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'situation',
|
||||
'selected' => $model->situation->value
|
||||
]);
|
||||
} )
|
||||
->add('status_str', fn (Song $model) => $this->renderSituation($model))
|
||||
->add('copyright01')
|
||||
->add('copyright02')
|
||||
->add('note01')
|
||||
@ -136,6 +119,35 @@ final class SongTable extends PowerGridComponent
|
||||
->add('enable')
|
||||
->add('created_at_formatted', fn (Song $model) => Carbon::parse($model->created_at)->format('Y-m-d H:i:s'));
|
||||
}
|
||||
private function renderLanguageType(Song $model): string
|
||||
{
|
||||
if ($this->canEdit) {
|
||||
return Blade::render(
|
||||
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
[
|
||||
'options' => SongLanguageType::options(),
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'language_type',
|
||||
'selected' => $model->language_type->value
|
||||
]);
|
||||
}
|
||||
return $model->language_type->labelPowergridFilter();
|
||||
}
|
||||
|
||||
private function renderSituation(Song $model): string
|
||||
{
|
||||
if ($this->canEdit) {
|
||||
return Blade::render(
|
||||
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
[
|
||||
'options' => SongSituation::options(),
|
||||
'modelId' => intval($model->id),
|
||||
'fieldName'=>'situation',
|
||||
'selected' => $model->situation->value
|
||||
]);
|
||||
}
|
||||
return $model->situation->labelPowergridFilter();
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
{
|
||||
@ -144,10 +156,10 @@ final class SongTable extends PowerGridComponent
|
||||
->editOnClick(hasPermission: $this->canEdit, dataField: 'id', fallback: 'N/A', saveOnMouseOut: true);
|
||||
$column[]=Column::make(__('songs.name'), 'name')->sortable()->searchable()
|
||||
->editOnClick(hasPermission: $this->canEdit, dataField: 'name', fallback: 'N/A', saveOnMouseOut: true);
|
||||
$column[]=Column::make(__('songs.simplified'), 'simplified')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.name.phinetic'), 'phonetic_abbr')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.name.pinyin'), 'pinyin_abbr')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.name.strokes'), 'strokes_abbr')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.name_simplified'), 'simplified')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.name_phinetic'), 'phonetic_abbr')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.name_pinyin'), 'pinyin_abbr')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.name_strokes'), 'strokes_abbr')->sortable()->searchable()->hidden(true, false);
|
||||
$column[]=Column::make(__('songs.filename'), 'filename')->sortable()->searchable()
|
||||
->editOnClick(hasPermission: $this->canEdit, dataField: 'filename', fallback: 'N/A', saveOnMouseOut: true);
|
||||
$column[]=Column::make(__('songs.adddate'), 'adddate_formatted', 'adddate')->sortable();
|
||||
@ -181,8 +193,8 @@ final class SongTable extends PowerGridComponent
|
||||
return [
|
||||
Filter::number('id')->placeholder(0,9999999),
|
||||
Filter::inputText('name')->placeholder(__('songs.name')),
|
||||
Filter::inputText('phonetic_abbr')->placeholder(__('songs.name.phinetic')),
|
||||
Filter::inputText('pinyin_abbr')->placeholder(__('songs.name.pinyin_abbr')),
|
||||
Filter::inputText('phonetic_abbr')->placeholder(__('songs.name_phinetic')),
|
||||
Filter::inputText('pinyin_abbr')->placeholder(__('songs.name_pinyin')),
|
||||
Filter::number('strokes_abbr'),
|
||||
Filter::inputText('filename')->placeholder(__('songs.filename')),
|
||||
Filter::datepicker('adddate'),
|
||||
|
@ -28,10 +28,13 @@ final class UserTable extends PowerGridComponent
|
||||
public string $tableName = 'user-table';
|
||||
|
||||
public bool $showFilters = false;
|
||||
public bool $canCreate;
|
||||
public bool $canEdit;
|
||||
public bool $canDownload;
|
||||
public bool $canDelect;
|
||||
public bool $canCreate = false;
|
||||
public bool $canEdit = false;
|
||||
public bool $canDownload = false;
|
||||
public bool $canDelect = false;
|
||||
|
||||
public ?string $gender = null;
|
||||
public ?string $status = null;
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
@ -52,8 +55,7 @@ final class UserTable extends PowerGridComponent
|
||||
$actions = [];
|
||||
$actions[] =PowerGrid::exportable(fileName: $this->tableName.'-file')
|
||||
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
|
||||
$header = PowerGrid::header()
|
||||
->showToggleColumns();
|
||||
$header = PowerGrid::header()->showToggleColumns();
|
||||
$header->includeViewOnTop('livewire.headers.user');
|
||||
$actions[]=$header;
|
||||
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
|
||||
@ -84,14 +86,20 @@ final class UserTable extends PowerGridComponent
|
||||
|
||||
public function fields(): PowerGridFields
|
||||
{
|
||||
|
||||
return PowerGrid::fields()
|
||||
->add('id')
|
||||
->add('name')
|
||||
->add('email')
|
||||
->add('phone')
|
||||
->add('birthday_formatted',fn (User $model) => Carbon::parse($model->birthday)->format('Y-m-d'))
|
||||
->add('gender_str', function (User $model) {
|
||||
->add('gender_str', fn (User $model) => $this->renderGender($model))
|
||||
->add('status_str', fn (User $model) => $this->renderStatus($model))
|
||||
->add('roles' ,fn(User $model)=> $model->roles->pluck('name')->implode(', '))
|
||||
->add('created_at_formatted', fn (User $model) => Carbon::parse($model->created_at)->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
private function renderGender(User $model): string
|
||||
{
|
||||
if ($this->canEdit) {
|
||||
return Blade::render(
|
||||
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
@ -103,11 +111,11 @@ final class UserTable extends PowerGridComponent
|
||||
]
|
||||
);
|
||||
}
|
||||
// 沒有權限就顯示對應的文字
|
||||
return $model->gender->labelPowergridFilter();
|
||||
}
|
||||
|
||||
return $model->gender->labelPowergridFilter(); // 假設 label() 會回傳顯示文字
|
||||
} )
|
||||
->add('status_str', function (User $model) {
|
||||
private function renderStatus(User $model): string
|
||||
{
|
||||
if ($this->canEdit) {
|
||||
return Blade::render(
|
||||
'<x-select-dropdown type="occurrence" :options=$options :modelId=$modelId :fieldName=$fieldName :selected=$selected/>',
|
||||
@ -119,49 +127,23 @@ final class UserTable extends PowerGridComponent
|
||||
]
|
||||
);
|
||||
}
|
||||
// 沒有權限就顯示對應的文字
|
||||
|
||||
return $model->status->labelPowergridFilter(); // 假設 label() 會回傳顯示文字
|
||||
} )
|
||||
->add('roles' ,fn(User $model)=> $model->roles->pluck('name')->implode(', '))
|
||||
->add('created_at_formatted', fn (User $model) => Carbon::parse($model->created_at)->format('Y-m-d H:i:s'));
|
||||
return $model->status->labelPowergridFilter();
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
{
|
||||
return [
|
||||
Column::make('ID', 'id'),
|
||||
Column::make(__('users.name'), 'name')
|
||||
->sortable()
|
||||
->searchable()
|
||||
->editOnClick(
|
||||
hasPermission: $this->canEdit,
|
||||
dataField: 'name',
|
||||
fallback: 'N/A',
|
||||
saveOnMouseOut: true
|
||||
),
|
||||
Column::make('Email', 'email')
|
||||
->sortable()
|
||||
->searchable()
|
||||
->editOnClick(
|
||||
hasPermission: $this->canEdit,
|
||||
dataField: 'email',
|
||||
fallback: 'N/A',
|
||||
saveOnMouseOut: true
|
||||
),
|
||||
Column::make(__('users.phone'), 'phone')
|
||||
->sortable()
|
||||
->searchable()
|
||||
->editOnClick(
|
||||
hasPermission: $this->canEdit,
|
||||
dataField: 'phone',
|
||||
fallback: 'N/A',
|
||||
saveOnMouseOut: true
|
||||
),
|
||||
Column::make(__('users.name'), 'name')->sortable()->searchable()
|
||||
->editOnClick(hasPermission: $this->canEdit, dataField: 'name', fallback: 'N/A', saveOnMouseOut: true),
|
||||
Column::make('Email', 'email')->sortable()->searchable()
|
||||
->editOnClick(hasPermission: $this->canEdit, dataField: 'email', fallback: 'N/A', saveOnMouseOut: true),
|
||||
Column::make(__('users.phone'), 'phone')->sortable()->searchable()
|
||||
->editOnClick(hasPermission: $this->canEdit, dataField: 'phone', fallback: 'N/A', saveOnMouseOut: true),
|
||||
|
||||
Column::make(__('users.gender'), 'gender_str','users.gender'),
|
||||
Column::make(__('users.gender'), 'gender_str','users.gender')->sortable()->searchable(),
|
||||
Column::make(__('users.birthday'), 'birthday_formatted')->sortable()->searchable(),
|
||||
Column::make(__('users.status'), 'status_str','users.status'),
|
||||
Column::make(__('users.status'), 'status_str','users.status')->sortable()->searchable(),
|
||||
Column::make(__('users.role'), 'roles'),
|
||||
Column::make('建立時間', 'created_at_formatted', 'created_at')->sortable(),
|
||||
Column::action('操作')
|
||||
@ -218,13 +200,9 @@ final class UserTable extends PowerGridComponent
|
||||
Filter::inputText('name')->placeholder(__('users.name')),
|
||||
Filter::inputText('email')->placeholder('Email'),
|
||||
Filter::inputText('phone')->placeholder(__('users.phone')),
|
||||
Filter::enumSelect('gender_str','users.gender')
|
||||
->datasource(UserGender::cases())
|
||||
->optionLabel('users.gender'),
|
||||
Filter::enumSelect('gender_str','users.gender')->datasource(UserGender::cases())->optionLabel('users.gender'),
|
||||
Filter::datepicker('birthday'),
|
||||
Filter::enumSelect('status_str', 'users.status')
|
||||
->datasource(UserStatus::cases())
|
||||
->optionLabel('users.status'),
|
||||
Filter::enumSelect('status_str', 'users.status')->datasource(UserStatus::cases())->optionLabel('users.status'),
|
||||
Filter::datetimepicker('created_at'),
|
||||
];
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ return [
|
||||
'is_not_blank' => 'Is not blank',
|
||||
],
|
||||
'export' => [
|
||||
'exporting' => 'Please wait!',
|
||||
'completed' => 'Export completed! Your files are ready for download',
|
||||
'exporting' => '請稍等!',
|
||||
'completed' => '匯出完成!您的文件已準備好下載',
|
||||
],
|
||||
'soft_deletes' => [
|
||||
'message_with_trashed' => 'Displaying all records, including deleted ones.',
|
||||
|
@ -13,10 +13,10 @@ return [
|
||||
'no' => '編號',
|
||||
'category' => '類別',
|
||||
'name' => '名稱',
|
||||
'name.simplified' => '簡體',
|
||||
'name.phinetic' => '注音',
|
||||
'name.pinyin' => '拼音',
|
||||
'name.strokes' => '筆劃',
|
||||
'name_simplified' => '簡體',
|
||||
'name_phinetic' => '注音',
|
||||
'name_pinyin' => '拼音',
|
||||
'name_strokes' => '筆劃',
|
||||
'enable' => '狀態',
|
||||
|
||||
'select_category' =>'選擇類別',
|
||||
|
@ -17,9 +17,9 @@ return [
|
||||
'filename' => '歌曲檔名',
|
||||
'adddate' => '新增日期',
|
||||
'categorys' => '分類',
|
||||
'name.phinetic' => '歌曲注音',
|
||||
'name.pinyin' => '歌曲拼音',
|
||||
'name.strokes' => '歌曲筆劃',
|
||||
'name_phinetic' => '歌曲注音',
|
||||
'name_pinyin' => '歌曲拼音',
|
||||
'name_strokes' => '歌曲筆劃',
|
||||
'language_type' => '語別',
|
||||
'copyright01' => '版權01',
|
||||
'copyright02' => '版權02',
|
||||
@ -32,7 +32,7 @@ return [
|
||||
'db_change'=>'分貝增減',
|
||||
'vocal' => '人聲',
|
||||
'situation' => '情境',
|
||||
'simplified' => '歌名簡體',
|
||||
'name_simplified' => '歌名簡體',
|
||||
|
||||
|
||||
'select_artists' =>'輸入搜尋歌手',
|
||||
|
Loading…
x
Reference in New Issue
Block a user