-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
WorkflowHistory.php
113 lines (93 loc) · 3.83 KB
/
WorkflowHistory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Heloufir\FilamentWorkflowManager\Pages;
use Closure;
use Filament\Pages\Page;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Filters\MultiSelectFilter;
use Heloufir\FilamentWorkflowManager\Models\WorkflowStatus;
use Illuminate\Database\Eloquent\Builder;
use Heloufir\FilamentWorkflowManager\Models\WorkflowHistory as WorkflowHistoryModel;
use Illuminate\Support\Facades\Route;
class WorkflowHistory extends Page implements HasTable
{
use InteractsWithTable;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament-workflow-manager::filament.pages.workflow-history';
protected static bool $shouldRegisterNavigation = false;
protected static ?string $slug = 'workflow-history/{id}/{model}';
public string|null $modelable_type = null;
public int|null $modelable_id = null;
protected function getTitle(): string
{
return trans('filament-workflow-manager::filament-workflow-manager.page.history.title');
}
public static function getRoutes(): Closure
{
return function () {
$slug = static::getSlug();
Route::get($slug, static::class)
->middleware(static::getMiddlewares())
->name($slug)
->where('model', '(.*)');
};
}
public function mount($id, $model)
{
$this->modelable_id = $id;
$this->modelable_type = $model;
}
protected function getTableQuery(): Builder
{
$query = WorkflowHistoryModel::query();
$query->where('modelable_type', str_replace('/', '\\', $this->modelable_type));
$query->where('modelable_id', $this->modelable_id);
return $query;
}
protected function getTableColumns(): array
{
return [
TextColumn::make('old_status.name')
->label(trans('filament-workflow-manager::filament-workflow-manager.page.history.table.old_status'))
->searchable()
->sortable(),
TextColumn::make('new_status.name')
->label(trans('filament-workflow-manager::filament-workflow-manager.page.history.table.new_status'))
->searchable()
->sortable(),
TextColumn::make('user.' . config('filament-workflow-manager.user_name'))
->label(trans('filament-workflow-manager::filament-workflow-manager.page.history.table.changed_by'))
->searchable()
->sortable(),
TextColumn::make('executed_at')
->label(trans('filament-workflow-manager::filament-workflow-manager.page.history.table.changed_at'))
->searchable()
->sortable()
->dateTime(trans('filament-workflow-manager::filament-workflow-manager.page.history.data.date_format')),
];
}
protected function getTableFilters(): array
{
return [
MultiSelectFilter::make('statuses')
->label(trans('filament-workflow-manager::filament-workflow-manager.page.history.table.filter.statuses'))
->options(WorkflowStatus::all()->pluck('name', 'id')->toArray())
->query(function (Builder $query, array $state) {
if (isset($state['values']) && sizeof($state['values'])) {
$query->whereIn('old_status_id', $state['values'])
->orWhereIn('new_status_id', $state['values']);
}
return $query;
})
];
}
protected function getDefaultTableSortColumn(): ?string
{
return 'executed_at';
}
protected function getDefaultTableSortDirection(): ?string
{
return 'desc';
}
}