mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update: add system log filter
This commit is contained in:
parent
2285a7c92f
commit
68db4f51b5
@ -14,6 +14,7 @@ use Laravel\Horizon\Contracts\MetricsRepository;
|
||||
use Laravel\Horizon\Contracts\SupervisorRepository;
|
||||
use Laravel\Horizon\Contracts\WorkloadRepository;
|
||||
use Laravel\Horizon\WaitTimeCalculator;
|
||||
use App\Models\Log as LogModel;
|
||||
|
||||
class SystemController extends Controller
|
||||
{
|
||||
@ -101,5 +102,18 @@ class SystemController extends Controller
|
||||
return $master->status === 'paused';
|
||||
})->count();
|
||||
}
|
||||
}
|
||||
|
||||
public function getSystemLog(Request $request) {
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('page_size') >= 10 ? $request->input('page_size') : 10;
|
||||
$builder = LogModel::orderBy('created_at', 'DESC')
|
||||
->setFilterAllowKeys('level');
|
||||
$total = $builder->count();
|
||||
$res = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
use \App\Scope\FilterScope;
|
||||
protected $table = 'v2_log';
|
||||
protected $dateFormat = 'U';
|
||||
protected $guarded = ['id'];
|
||||
|
50
app/Scope/FilterScope.php
Normal file
50
app/Scope/FilterScope.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Scope;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait FilterScope
|
||||
{
|
||||
public function scopeSetFilterAllowKeys($builder, ...$allowKeys)
|
||||
{
|
||||
$allowKeys = implode(',', $allowKeys);
|
||||
if (!$allowKeys) return $builder;
|
||||
$request = request();
|
||||
$request->validate([
|
||||
'filter.*.key' => "required|in:{$allowKeys}",
|
||||
'filter.*.condition' => 'required|in:in,is,not,like,lt,gt',
|
||||
'filter.*.value' => 'required'
|
||||
]);
|
||||
$filters = $request->input('filter');
|
||||
if ($filters) {
|
||||
foreach ($filters as $k => $filter) {
|
||||
if ($filter['condition'] === 'in') {
|
||||
$builder->whereIn($filter['key'], $filter['value']);
|
||||
continue;
|
||||
}
|
||||
if ($filter['condition'] === 'is') {
|
||||
$builder->where($filter['key'], $filter['value']);
|
||||
continue;
|
||||
}
|
||||
if ($filter['condition'] === 'not') {
|
||||
$builder->where($filter['key'], '!=', $filter['value']);
|
||||
continue;
|
||||
}
|
||||
if ($filter['condition'] === 'gt') {
|
||||
$builder->where($filter['key'], '>', $filter['value']);
|
||||
continue;
|
||||
}
|
||||
if ($filter['condition'] === 'lt') {
|
||||
$builder->where($filter['key'], '<', $filter['value']);
|
||||
continue;
|
||||
}
|
||||
if ($filter['condition'] === 'like') {
|
||||
$builder->where($filter['key'], 'like', "%{$filter['value']}%");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $builder;
|
||||
}
|
||||
}
|
@ -237,5 +237,5 @@ return [
|
||||
| The only modification by laravel config
|
||||
|
|
||||
*/
|
||||
'version' => '1.7.4.1681103823832'
|
||||
'version' => '1.7.5.1685907718051'
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user