diff --git a/.DS_Store b/.DS_Store
index e28070c..92ed48d 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/app/Livewire/Admin/ActivityLogTable.php b/app/Livewire/Admin/ActivityLogTable.php
index 1dd0b4a..ad22c8b 100644
--- a/app/Livewire/Admin/ActivityLogTable.php
+++ b/app/Livewire/Admin/ActivityLogTable.php
@@ -10,24 +10,43 @@ 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 Spatie\Activitylog\Models\Activity;
final class ActivityLogTable extends PowerGridComponent
{
+ use WithExport;
public string $tableName = 'activity-log-table';
+ public bool $canDownload;
+
+ public bool $showFilters = false;
+ public function boot(): void
+ {
+ config(['livewire-powergrid.filter' => 'outside']);
+ //權限設定
+ $this->canDownload=true;
+ }
public function setUp(): array
{
- $this->showCheckBox();
-
- return [
- PowerGrid::header()
- ->showSearchInput(),
- PowerGrid::footer()
- ->showPerPage()
- ->showRecordCount(),
- ];
+ if($this->canDownload ){
+ $this->showCheckBox();
+ }
+ $actions = [];
+ if($this->canDownload){
+ $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
+ ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
+ }
+ $header = PowerGrid::header()
+ ->withoutLoading()
+ ->showToggleColumns();
+ //->showSoftDeletes()
+ //->showSearchInput()
+ $actions[]=$header;
+ $actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
+ return $actions;
}
public function datasource(): Builder
@@ -50,8 +69,7 @@ final class ActivityLogTable extends PowerGridComponent
->add('subject_type')
->add('subject_id')
->add('description')
- ->add('log_name')
- ->add('changes', function (Activity $model) {
+ ->add('changes_str', function (Activity $model) {
$old = $model->properties['old'] ?? [];
$new = $model->properties['attributes'] ?? [];
@@ -64,7 +82,7 @@ final class ActivityLogTable extends PowerGridComponent
$changes[] = "{$key}: {$oldValue} → {$newValue}";
}
}
-
+ //dd(implode('
', $changes));
return implode('
', $changes);
})
;
@@ -75,12 +93,11 @@ final class ActivityLogTable extends PowerGridComponent
{
$column=[];
$column[]=Column::make('時間', 'created_at_formatted', 'created_at')->sortable()->searchable();
- $column[]=Column::make('操作者', 'causer.name')->sortable()->searchable()->bodyAttribute('whitespace-nowrap');
+ $column[]=Column::make('操作者', 'causer_name')->sortable()->searchable()->bodyAttribute('whitespace-nowrap');
$column[]=Column::make('模型', 'subject_type_label')->sortable()->searchable();
$column[]=Column::make('模型 ID', 'subject_id')->sortable()->searchable();
$column[]=Column::make('動作', 'description')->sortable()->searchable();
- $column[]=Column::make('變更內容', 'changes')->sortable(false)->searchable(false)->bodyAttribute('whitespace-normal text-sm text-gray-700');
- $column[]=Column::make('Log 名稱', 'log_name')->sortable()->searchable();
+ $column[]=Column::make('變更內容', 'changes_str')->sortable(false)->searchable(false)->bodyAttribute('whitespace-normal text-sm text-gray-700');
return $column;
}
@@ -88,6 +105,10 @@ final class ActivityLogTable extends PowerGridComponent
{
return [
Filter::datetimepicker('created_at'),
+ Filter::inputText('causer_name')->placeholder('操作者'),
+ Filter::inputText('subject_type_label')->placeholder('模型'),
+ Filter::number('subject_id'),
+ Filter::inputText('description')->placeholder('動作'),
];
}
diff --git a/app/Livewire/Admin/ArtistTable.php b/app/Livewire/Admin/ArtistTable.php
index e4f39dd..d0fc154 100644
--- a/app/Livewire/Admin/ArtistTable.php
+++ b/app/Livewire/Admin/ArtistTable.php
@@ -23,7 +23,7 @@ use WireUi\Traits\WireUiActions;
final class ArtistTable extends PowerGridComponent
{
- use WireUiActions;
+ use WithExport, WireUiActions;
public string $tableName = 'artist-table';
public bool $canCreate;
@@ -54,7 +54,7 @@ final class ArtistTable extends PowerGridComponent
$actions = [];
if($this->canDownload){
- $actions[]=PowerGrid::exportable(fileName: 'artist-file')
+ $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
}
$header = PowerGrid::header()
diff --git a/app/Livewire/Admin/BranchTable.php b/app/Livewire/Admin/BranchTable.php
index aa31261..e09e442 100644
--- a/app/Livewire/Admin/BranchTable.php
+++ b/app/Livewire/Admin/BranchTable.php
@@ -22,6 +22,7 @@ use WireUi\Traits\WireUiActions;
final class BranchTable extends PowerGridComponent
{
+ use WithExport, WireUiActions;
public string $tableName = 'branch-table';
public bool $canCreate;
public bool $canEdit;
@@ -47,7 +48,7 @@ final class BranchTable extends PowerGridComponent
}
$actions = [];
if($this->canDownload){
- $actions[]=PowerGrid::exportable(fileName: 'branch-file')
+ $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
}
$header = PowerGrid::header()
diff --git a/app/Livewire/Admin/SongTable.php b/app/Livewire/Admin/SongTable.php
index 1792d5e..3b816e9 100644
--- a/app/Livewire/Admin/SongTable.php
+++ b/app/Livewire/Admin/SongTable.php
@@ -24,7 +24,7 @@ use WireUi\Traits\WireUiActions;
final class SongTable extends PowerGridComponent
{
- use WireUiActions;
+ use WithExport, WireUiActions;
public string $tableName = 'song-table';
public bool $canCreate;
@@ -54,7 +54,7 @@ final class SongTable extends PowerGridComponent
}
$actions = [];
if($this->canDownload){
- $actions[]=PowerGrid::exportable(fileName: 'song-file')
+ $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
}
$header = PowerGrid::header()->showSoftDeletes()->showToggleColumns();
diff --git a/app/Livewire/Admin/UserTable.php b/app/Livewire/Admin/UserTable.php
index 10bb107..248d583 100644
--- a/app/Livewire/Admin/UserTable.php
+++ b/app/Livewire/Admin/UserTable.php
@@ -15,7 +15,7 @@ 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\Traits\WithExport;
use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable;
use PowerComponents\LivewirePowerGrid\Facades\Rule;
use Livewire\Attributes\On;
@@ -23,8 +23,7 @@ use WireUi\Traits\WireUiActions;
final class UserTable extends PowerGridComponent
{
- use WireUiActions;
- //use WithExport ;
+ use WithExport, WireUiActions;
public string $tableName = 'user-table';
@@ -51,7 +50,7 @@ final class UserTable extends PowerGridComponent
$this->showCheckBox();
}
$actions = [];
- $actions[] =PowerGrid::exportable(fileName: 'user-file')
+ $actions[] =PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
$header = PowerGrid::header()
->showToggleColumns();
diff --git a/app/Models/User.php b/app/Models/User.php
index c6057b0..584a10e 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -8,11 +8,12 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
use App\Traits\LogsModelActivity;
+use Spatie\Activitylog\Traits\CausesActivity;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
- use HasFactory, Notifiable, HasRoles, LogsModelActivity;
+ use HasFactory, Notifiable, HasRoles, LogsModelActivity,CausesActivity;
/**
* The attributes that are mass assignable.