From c6a9f80839486a3724af53c7ec123030f1f4d651 Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Fri, 5 Sep 2025 14:25:27 +0800 Subject: [PATCH] =?UTF-8?q?202509051423=20=E9=82=8F=E8=BC=AF=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/Tables/ArtistTable.php | 61 ++++----- app/Livewire/Tables/SongTable.php | 76 ++++++----- app/Livewire/Tables/UserTable.php | 126 ++++++++---------- .../livewire-powergrid/zh-tw/datatable.php | 4 +- resources/lang/zh-tw/artists.php | 8 +- resources/lang/zh-tw/songs.php | 8 +- 6 files changed, 135 insertions(+), 148 deletions(-) diff --git a/app/Livewire/Tables/ArtistTable.php b/app/Livewire/Tables/ArtistTable.php index 707fad5..3ec3e03 100644 --- a/app/Livewire/Tables/ArtistTable.php +++ b/app/Livewire/Tables/ArtistTable.php @@ -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,22 +96,7 @@ final class ArtistTable extends PowerGridComponent { return PowerGrid::fields() ->add('id') - ->add('category_str', function (Artist $model) { - if ($this->canEdit) { - return Blade::render( - '', - [ - 'options' => ArtistCategory::options(), - 'modelId' => intval($model->id), - 'fieldName'=>'category', - 'selected' => $model->category->value - ] - ); - } - // 沒有權限就顯示對應的文字 - - return $model->category->labelPowergridFilter(); // 假設 label() 會回傳顯示文字 - } ) + ->add('category_str', fn (Artist $model) => $this->renderCategory($model)) ->add('name') ->add('simplified') ->add('phonetic_abbr') @@ -118,6 +105,21 @@ final class ArtistTable extends PowerGridComponent ->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( + '', + [ + 'options' => ArtistCategory::options(), + 'modelId' => intval($model->id), + 'fieldName'=>'category', + 'selected' => $model->category->value + ] + ); + } + 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'), diff --git a/app/Livewire/Tables/SongTable.php b/app/Livewire/Tables/SongTable.php index f129798..2c50000 100644 --- a/app/Livewire/Tables/SongTable.php +++ b/app/Livewire/Tables/SongTable.php @@ -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( - '', - [ - '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( - '', - [ - '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( + '', + [ + '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( + '', + [ + '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'), diff --git a/app/Livewire/Tables/UserTable.php b/app/Livewire/Tables/UserTable.php index b3f814c..7bd4d03 100644 --- a/app/Livewire/Tables/UserTable.php +++ b/app/Livewire/Tables/UserTable.php @@ -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,84 +86,64 @@ 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) { - if ($this->canEdit) { - return Blade::render( - '', - [ - 'options' => UserGender::options(), - 'modelId' => intval($model->id), - 'fieldName'=>'gender', - 'selected' => $model->gender->value - ] - ); - } - // 沒有權限就顯示對應的文字 - - return $model->gender->labelPowergridFilter(); // 假設 label() 會回傳顯示文字 - } ) - ->add('status_str', function (User $model) { - if ($this->canEdit) { - return Blade::render( - '', - [ - 'options' => UserStatus::options(), - 'modelId' => intval($model->id), - 'fieldName'=>'status', - 'selected' => $model->status->value - ] - ); - } - // 沒有權限就顯示對應的文字 - - return $model->status->labelPowergridFilter(); // 假設 label() 會回傳顯示文字 - } ) + ->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( + '', + [ + 'options' => UserGender::options(), + 'modelId' => intval($model->id), + 'fieldName'=>'gender', + 'selected' => $model->gender->value + ] + ); + } + return $model->gender->labelPowergridFilter(); + } + + private function renderStatus(User $model): string + { + if ($this->canEdit) { + return Blade::render( + '', + [ + 'options' => UserStatus::options(), + 'modelId' => intval($model->id), + 'fieldName'=>'status', + 'selected' => $model->status->value + ] + ); + } + 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'), ]; } diff --git a/resources/lang/vendor/livewire-powergrid/zh-tw/datatable.php b/resources/lang/vendor/livewire-powergrid/zh-tw/datatable.php index f5da8e8..29d3848 100644 --- a/resources/lang/vendor/livewire-powergrid/zh-tw/datatable.php +++ b/resources/lang/vendor/livewire-powergrid/zh-tw/datatable.php @@ -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.', diff --git a/resources/lang/zh-tw/artists.php b/resources/lang/zh-tw/artists.php index b6cd0b8..4e3f17f 100644 --- a/resources/lang/zh-tw/artists.php +++ b/resources/lang/zh-tw/artists.php @@ -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' =>'選擇類別', diff --git a/resources/lang/zh-tw/songs.php b/resources/lang/zh-tw/songs.php index f1a48f6..a5ade70 100644 --- a/resources/lang/zh-tw/songs.php +++ b/resources/lang/zh-tw/songs.php @@ -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' =>'輸入搜尋歌手',