diff --git a/app/Livewire/Forms/ActivityLogTable.php b/app/Livewire/Forms/Tables/ActivityLogTable.php
similarity index 99%
rename from app/Livewire/Forms/ActivityLogTable.php
rename to app/Livewire/Forms/Tables/ActivityLogTable.php
index 650225e..6c54fdd 100644
--- a/app/Livewire/Forms/ActivityLogTable.php
+++ b/app/Livewire/Forms/Tables/ActivityLogTable.php
@@ -1,6 +1,6 @@
'outside']);
+ $this->canCreate = Auth::user()?->can('text-ad-create') ?? false;
+ $this->canEdit = Auth::user()?->can('text-ad-edit') ?? false;
+ $this->canDownload=Auth::user()?->can('text-ad-delete') ?? false;
+ $this->canDelect = Auth::user()?->can('text-ad-delete') ?? false;
+ }
+
+ public function setUp(): array
+ {
+ if($this->canDownload || $this->canDelect){
+ $this->showCheckBox();
+ }
+ $actions = [];
+ if($this->canDownload){
+ $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
+ ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
+ }
+ $header = PowerGrid::header()->showSoftDeletes()->showToggleColumns();
+ if($this->canCreate){
+ $header->includeViewOnTop('livewire.header.text-ad');
+ }
+ $actions[]=$header;
+ $actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
+
+ return $actions;
+ }
+ public function header(): array
+ {
+ $actions = [];
+ if ($this->canDelect) {
+ $actions[]=Button::add('bulk-delete')
+ ->slot('Bulk delete ()')
+ ->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, []);
+ }
+ return $actions;
+ }
+
+ public function datasource(): Builder
+ {
+ return TextAd::query();
+ }
+
+ public function relationSearch(): array
+ {
+ return [];
+ }
+
+ public function fields(): PowerGridFields
+ {
+ return PowerGrid::fields()
+ ->add('id')
+ ->add('content')
+ ->add(
+ 'content_short',
+ fn (TextAd $model) =>
+ '' . e(Str::limit($model->content, 50)) . ''
+ )
+ ->add('color')
+ ->add('color_str', function (TextAd $model) {
+ if ($this->canEdit) {
+ return Blade::render(
+ '',
+ [
+ 'options' => TextAdColors::options(),
+ 'modelId' => intval($model->id),
+ 'fieldName'=>'color',
+ 'selected' => $model->color->value
+ ]
+ );
+ }
+ // 沒有權限就顯示對應的文字
+
+ return $model->color->labelPowergridFilter(); // 假設 label() 會回傳顯示文字
+ } )
+ ->add('duration')
+ ->add('is_active')
+ ->add('created_at');
+ }
+
+ public function columns(): array
+ {
+ $column=[];
+ $column[] = Column::make(__('text_ads.id'), 'id');
+ $column[] = Column::make(__('text_ads.content'), 'content_short', 'text_ads.content')->sortable()->searchable();
+ $column[] = Column::make(__('text_ads.color'),'color_str', 'text-ads.color')->searchable();
+ $column[] = Column::make(__('text_ads.duration'), 'duration')->sortable()->searchable();
+ $column[] = Column::make(__('text_ads.is_active'), 'is_active')->toggleable(hasPermission: $this->canEdit, trueLabel: 'yes', falseLabel: 'no');
+ $column[] = Column::make(__('text_ads.created_at'), 'created_at')->sortable()->searchable();
+ $column[] = Column::action(__('text_ads.actions'));
+ return $column;
+ }
+
+ public function filters(): array
+ {
+ return [
+ ];
+ }
+
+ #[On('bulkDelete.{tableName}')]
+ public function bulkDelete(): void
+ {
+ $this->js('alert(window.pgBulkActions.get(\'' . $this->tableName . '\'))');
+ if($this->checkboxValues){
+ foreach ($this->checkboxValues as $id) {
+ $textAd = TextAd::find($id);
+ if ($textAd) {
+ $textAd->delete();
+ }
+ }
+ $this->js('window.pgBulkActions.clearAll()'); // clear the count on the interface.
+ }
+ }
+ #[On('categoryChanged')]
+ public function categoryChanged($value,$fieldName, $modelId): void
+ {
+ //dd($value,$fieldName, $modelId);
+ if (in_array($fieldName, ['color'])) {
+ $this->noUpdated($modelId,$fieldName,$value);
+ }
+ }
+ #[On('onUpdatedEditable')]
+ public function onUpdatedEditable($id, $field, $value): void
+ {
+ if (in_array($field,[
+ ''
+ ]) && $this->canEdit) {
+ $this->noUpdated($id,$field,$value);
+ }
+ }
+ #[On('onUpdatedToggleable')]
+ public function onUpdatedToggleable($id, $field, $value): void
+ {
+ if (in_array($field,['is_active']) && $this->canEdit) {
+ $this->noUpdated($id,$field,$value);
+ }
+ }
+ private function noUpdated($id,$field,$value){
+ $textAd = TextAd::find($id);
+ if ($textAd) {
+ $textAd->{$field} = $value;
+ $textAd->save(); // 明確觸發 saving
+ }
+ $this->notification()->send([
+ 'icon' => 'success',
+ 'title' => $id.'.'.__('text_ads.'.$field).':'.$value,
+ 'description' => '已經寫入',
+ ]);
+ }
+
+
+ public function actions(TextAd $row): array
+ {
+ $actions = [];
+ if ($this->canEdit) {
+ $actions[]=Button::add('edit')
+ ->slot(__('text_ads.edit'))
+ ->icon('solid-pencil-square')
+ ->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
+ ->dispatchTo('forms.text-ads-form', 'openModal', ['id' => $row->id]);
+ }
+ if($this->canDelect){
+ $actions[]=Button::add('delete')
+ ->slot(__('text_ads.delete'))
+ ->icon('solid-trash')
+ ->class('inline-flex items-center gap-1 px-3 py-1 rounded ')
+ ->dispatchTo('forms.text-ads-form', 'deleteTextAd', ['id' => $row->id]);
+ }
+
+ return $actions;
+ }
+}
diff --git a/app/Livewire/Forms/UserTable.php b/app/Livewire/Forms/Tables/UserTable.php
similarity index 99%
rename from app/Livewire/Forms/UserTable.php
rename to app/Livewire/Forms/Tables/UserTable.php
index 5ba2a80..201c8bb 100644
--- a/app/Livewire/Forms/UserTable.php
+++ b/app/Livewire/Forms/Tables/UserTable.php
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/resources/views/livewire/admin/artists.blade.php b/resources/views/livewire/admin/artists.blade.php
index 54456f5..35a0393 100644
--- a/resources/views/livewire/admin/artists.blade.php
+++ b/resources/views/livewire/admin/artists.blade.php
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
diff --git a/resources/views/livewire/admin/branches.blade.php b/resources/views/livewire/admin/branches.blade.php
index 212a940..24eb182 100644
--- a/resources/views/livewire/admin/branches.blade.php
+++ b/resources/views/livewire/admin/branches.blade.php
@@ -1,7 +1,7 @@
-
+
diff --git a/resources/views/livewire/admin/machine-status.blade.php b/resources/views/livewire/admin/machine-status.blade.php
index 6649302..e7ee07e 100644
--- a/resources/views/livewire/admin/machine-status.blade.php
+++ b/resources/views/livewire/admin/machine-status.blade.php
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
diff --git a/resources/views/livewire/admin/roles.blade.php b/resources/views/livewire/admin/roles.blade.php
index ef004a7..57ac88f 100644
--- a/resources/views/livewire/admin/roles.blade.php
+++ b/resources/views/livewire/admin/roles.blade.php
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/resources/views/livewire/admin/room-status-log.blade.php b/resources/views/livewire/admin/room-status-log.blade.php
index c4f0ae6..f99cd49 100644
--- a/resources/views/livewire/admin/room-status-log.blade.php
+++ b/resources/views/livewire/admin/room-status-log.blade.php
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
diff --git a/resources/views/livewire/admin/rooms.blade.php b/resources/views/livewire/admin/rooms.blade.php
index 547420c..a7fb514 100644
--- a/resources/views/livewire/admin/rooms.blade.php
+++ b/resources/views/livewire/admin/rooms.blade.php
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
diff --git a/resources/views/livewire/admin/songs.blade.php b/resources/views/livewire/admin/songs.blade.php
index 173f46c..536d714 100644
--- a/resources/views/livewire/admin/songs.blade.php
+++ b/resources/views/livewire/admin/songs.blade.php
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
diff --git a/resources/views/livewire/admin/users.blade.php b/resources/views/livewire/admin/users.blade.php
index 1f789a6..d9b3988 100644
--- a/resources/views/livewire/admin/users.blade.php
+++ b/resources/views/livewire/admin/users.blade.php
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file