操作記錄 查詢功能補上
檔案下載問題修正 20250512
This commit is contained in:
parent
78bf426459
commit
b9e4064725
@ -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[] = "<strong>{$key}</strong>: {$oldValue} → {$newValue}";
|
||||
}
|
||||
}
|
||||
|
||||
//dd(implode('<br>', $changes));
|
||||
return implode('<br>', $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('動作'),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user