操作記錄 查詢功能補上

檔案下載問題修正
20250512
This commit is contained in:
allen.yan 2025-05-12 16:56:31 +08:00
parent 78bf426459
commit b9e4064725
7 changed files with 47 additions and 25 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -10,24 +10,43 @@ use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid; use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields; use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent; use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Traits\WithExport;
use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable;
use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Models\Activity;
final class ActivityLogTable extends PowerGridComponent final class ActivityLogTable extends PowerGridComponent
{ {
use WithExport;
public string $tableName = 'activity-log-table'; 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 public function setUp(): array
{ {
$this->showCheckBox(); if($this->canDownload ){
$this->showCheckBox();
return [ }
PowerGrid::header() $actions = [];
->showSearchInput(), if($this->canDownload){
PowerGrid::footer() $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->showPerPage() ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
->showRecordCount(), }
]; $header = PowerGrid::header()
->withoutLoading()
->showToggleColumns();
//->showSoftDeletes()
//->showSearchInput()
$actions[]=$header;
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
return $actions;
} }
public function datasource(): Builder public function datasource(): Builder
@ -50,8 +69,7 @@ final class ActivityLogTable extends PowerGridComponent
->add('subject_type') ->add('subject_type')
->add('subject_id') ->add('subject_id')
->add('description') ->add('description')
->add('log_name') ->add('changes_str', function (Activity $model) {
->add('changes', function (Activity $model) {
$old = $model->properties['old'] ?? []; $old = $model->properties['old'] ?? [];
$new = $model->properties['attributes'] ?? []; $new = $model->properties['attributes'] ?? [];
@ -64,7 +82,7 @@ final class ActivityLogTable extends PowerGridComponent
$changes[] = "<strong>{$key}</strong>: {$oldValue}{$newValue}"; $changes[] = "<strong>{$key}</strong>: {$oldValue}{$newValue}";
} }
} }
//dd(implode('<br>', $changes));
return implode('<br>', $changes); return implode('<br>', $changes);
}) })
; ;
@ -75,12 +93,11 @@ final class ActivityLogTable extends PowerGridComponent
{ {
$column=[]; $column=[];
$column[]=Column::make('時間', 'created_at_formatted', 'created_at')->sortable()->searchable(); $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('模型', 'subject_type_label')->sortable()->searchable();
$column[]=Column::make('模型 ID', 'subject_id')->sortable()->searchable(); $column[]=Column::make('模型 ID', 'subject_id')->sortable()->searchable();
$column[]=Column::make('動作', 'description')->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('變更內容', 'changes_str')->sortable(false)->searchable(false)->bodyAttribute('whitespace-normal text-sm text-gray-700');
$column[]=Column::make('Log 名稱', 'log_name')->sortable()->searchable();
return $column; return $column;
} }
@ -88,6 +105,10 @@ final class ActivityLogTable extends PowerGridComponent
{ {
return [ return [
Filter::datetimepicker('created_at'), Filter::datetimepicker('created_at'),
Filter::inputText('causer_name')->placeholder('操作者'),
Filter::inputText('subject_type_label')->placeholder('模型'),
Filter::number('subject_id'),
Filter::inputText('description')->placeholder('動作'),
]; ];
} }

View File

@ -23,7 +23,7 @@ use WireUi\Traits\WireUiActions;
final class ArtistTable extends PowerGridComponent final class ArtistTable extends PowerGridComponent
{ {
use WireUiActions; use WithExport, WireUiActions;
public string $tableName = 'artist-table'; public string $tableName = 'artist-table';
public bool $canCreate; public bool $canCreate;
@ -54,7 +54,7 @@ final class ArtistTable extends PowerGridComponent
$actions = []; $actions = [];
if($this->canDownload){ if($this->canDownload){
$actions[]=PowerGrid::exportable(fileName: 'artist-file') $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
} }
$header = PowerGrid::header() $header = PowerGrid::header()

View File

@ -22,6 +22,7 @@ use WireUi\Traits\WireUiActions;
final class BranchTable extends PowerGridComponent final class BranchTable extends PowerGridComponent
{ {
use WithExport, WireUiActions;
public string $tableName = 'branch-table'; public string $tableName = 'branch-table';
public bool $canCreate; public bool $canCreate;
public bool $canEdit; public bool $canEdit;
@ -47,7 +48,7 @@ final class BranchTable extends PowerGridComponent
} }
$actions = []; $actions = [];
if($this->canDownload){ if($this->canDownload){
$actions[]=PowerGrid::exportable(fileName: 'branch-file') $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
} }
$header = PowerGrid::header() $header = PowerGrid::header()

View File

@ -24,7 +24,7 @@ use WireUi\Traits\WireUiActions;
final class SongTable extends PowerGridComponent final class SongTable extends PowerGridComponent
{ {
use WireUiActions; use WithExport, WireUiActions;
public string $tableName = 'song-table'; public string $tableName = 'song-table';
public bool $canCreate; public bool $canCreate;
@ -54,7 +54,7 @@ final class SongTable extends PowerGridComponent
} }
$actions = []; $actions = [];
if($this->canDownload){ if($this->canDownload){
$actions[]=PowerGrid::exportable(fileName: 'song-file') $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
} }
$header = PowerGrid::header()->showSoftDeletes()->showToggleColumns(); $header = PowerGrid::header()->showSoftDeletes()->showToggleColumns();

View File

@ -15,7 +15,7 @@ use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid; use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields; use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent; use PowerComponents\LivewirePowerGrid\PowerGridComponent;
//use PowerComponents\LivewirePowerGrid\Traits\WithExport; use PowerComponents\LivewirePowerGrid\Traits\WithExport;
use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable; use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable;
use PowerComponents\LivewirePowerGrid\Facades\Rule; use PowerComponents\LivewirePowerGrid\Facades\Rule;
use Livewire\Attributes\On; use Livewire\Attributes\On;
@ -23,8 +23,7 @@ use WireUi\Traits\WireUiActions;
final class UserTable extends PowerGridComponent final class UserTable extends PowerGridComponent
{ {
use WireUiActions; use WithExport, WireUiActions;
//use WithExport ;
public string $tableName = 'user-table'; public string $tableName = 'user-table';
@ -51,7 +50,7 @@ final class UserTable extends PowerGridComponent
$this->showCheckBox(); $this->showCheckBox();
} }
$actions = []; $actions = [];
$actions[] =PowerGrid::exportable(fileName: 'user-file') $actions[] =PowerGrid::exportable(fileName: $this->tableName.'-file')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
$header = PowerGrid::header() $header = PowerGrid::header()
->showToggleColumns(); ->showToggleColumns();

View File

@ -8,11 +8,12 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles; use Spatie\Permission\Traits\HasRoles;
use App\Traits\LogsModelActivity; use App\Traits\LogsModelActivity;
use Spatie\Activitylog\Traits\CausesActivity;
class User extends Authenticatable class User extends Authenticatable
{ {
/** @use HasFactory<\Database\Factories\UserFactory> */ /** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, HasRoles, LogsModelActivity; use HasFactory, Notifiable, HasRoles, LogsModelActivity,CausesActivity;
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.