Skip to content

Commit

Permalink
Merge pull request #27 from bezhanSalleh/feature/exception-mass-prunable
Browse files Browse the repository at this point in the history
feature: Exceptions are now Mass Prunable
  • Loading branch information
bezhanSalleh authored Mar 5, 2023
2 parents 14fc857 + 52f25cb commit 4f4dfd2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
13 changes: 13 additions & 0 deletions config/filament-exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@
*/
'active_pill' => 1,

/**-------------------------------------------------
* Here you can define when the exceptions should be pruned
* The default is 7 days (a week)
* The format for providing period should follow carbon's format. i.e.
* 1 day => 'subDay()',
* 3 days => 'subDays(3)',
* 7 days => 'subWeek()',
* 1 month => 'subMonth()',
* 2 months => 'subMonths(2)',
*
*/

'period' => now()->subWeek(),
];
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"author": "Bezhan Salleh",
"license": "MIT",
"devDependencies": {
"@awcodes/filament-plugin-purge": "^1.0.2",
"@tailwindcss/typography": "^0.5.4",
"autoprefixer": "^10.4",
"postcss": "^8.4",
"tailwindcss": "^3.1",
"@awcodes/filament-plugin-purge": "^1.0.2"
"tailwindcss": "^3.1"
}
}
20 changes: 10 additions & 10 deletions resources/views/view-exception.blade.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<x-filament::page :widget-data="['record' => $record]" class="filament-resources-view-record-page">
@php
$method = $record->method;
$methodColor = match($method) {
$methodColor = match ($method) {
'DELETE' => \Illuminate\Support\Arr::toCssClasses(['text-danger-700 bg-danger-500/10', 'dark:text-danger-500' => config('tables.dark_mode')]),
'POST' => \Illuminate\Support\Arr::toCssClasses(['text-primary-700 bg-primary-500/10', 'dark:text-primary-500' => config('tables.dark_mode')]),
'GET' => \Illuminate\Support\Arr::toCssClasses(['text-success-700 bg-success-500/10', 'dark:text-success-500' => config('tables.dark_mode')]),
'PUT' => \Illuminate\Support\Arr::toCssClasses(['text-warning-700 bg-warning-500/10', 'dark:text-warning-500' => config('tables.dark_mode')]),
'PATCH', 'OPTIONS' => \Illuminate\Support\Arr::toCssClasses(['text-gray-700 bg-gray-500/10', 'dark:text-gray-300 dark:bg-gray-500/20' => config('tables.dark_mode')]),
default => \Illuminate\Support\Arr::toCssClasses(['text-gray-700 bg-gray-500/10', 'dark:text-gray-300 dark:bg-gray-500/20' => config('tables.dark_mode')])
}
default => \Illuminate\Support\Arr::toCssClasses(['text-gray-700 bg-gray-500/10', 'dark:text-gray-300 dark:bg-gray-500/20' => config('tables.dark_mode')]),
};
@endphp
<div
class="dark:bg-gray-700 px-4 py-5 border-b dark:border-gray-700 border-gray-200 sm:px-6 bg-white rounded-lg shadow-none">
<h3 class="text-lg leading-6 font-medium dark:text-gray-50 text-gray-900 flex items-center">
<span class="{{ $methodColor }} text-white rounded-md px-4 py-1 mr-2">{{ $method }}</span>
class="px-4 py-5 bg-white border-b border-gray-200 rounded-lg shadow-none dark:bg-gray-700 dark:border-gray-700 sm:px-6">
<h3 class="flex items-center text-lg font-medium leading-6 text-gray-900 dark:text-gray-50">
<span class="{{ $methodColor }} rounded-md px-4 py-1 mr-2">{{ $method }}</span>
<span
class="bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-100 rounded-md px-4 py-1 ml-2">{{ $record->path }}
class="px-4 py-1 ml-2 text-gray-800 bg-gray-100 rounded-md dark:bg-gray-800 dark:text-gray-100">{{ $record->path }}
</span>
</h3>
<div class="mt-1 max-w-2xl text-sm leading-5 text-gray-500 flex items-center">
<span class="text-xs text-gray-600 dark:text-gray-200 font-mono mt-1">
{{__('filament-exceptions::filament-exceptions.columns.occurred_at')}}:
<div class="flex items-center max-w-2xl mt-1 text-sm leading-5 text-gray-500">
<span class="mt-1 font-mono text-xs text-gray-600 dark:text-gray-200">
{{ __('filament-exceptions::filament-exceptions.columns.occurred_at') }}:

{{ $record->created_at->toDateTimeString() }}
</span>
Expand Down
13 changes: 13 additions & 0 deletions src/FilamentExceptionsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace BezhanSalleh\FilamentExceptions;

use BezhanSalleh\FilamentExceptions\Commands\MakeExceptionsInstallCommand;
use BezhanSalleh\FilamentExceptions\Models\Exception;
use BezhanSalleh\FilamentExceptions\Resources\ExceptionResource;
use Filament\PluginServiceProvider;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Http\Request;
use Spatie\LaravelPackageTools\Package;

Expand Down Expand Up @@ -41,4 +43,15 @@ public function packageRegistered(): void
return new FilamentExceptions($app->make(Request::class));
});
}

public function packageBooted(): void
{
parent::packageBooted();

$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
$schedule->command('model:prune', [
'--model' => [Exception::class],
])->daily();
});
}
}
13 changes: 13 additions & 0 deletions src/Models/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

namespace BezhanSalleh\FilamentExceptions\Models;

use Illuminate\Database\Eloquent\MassPrunable;
use Illuminate\Database\Eloquent\Model;

class Exception extends model
{
use MassPrunable;

protected $table = 'filament_exceptions_table';

/**
* @var array
*/
protected $guarded = [];

/**
* Get the prunable model query.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function prunable()
{
return static::where('created_at', '<=', config('filament-exceptions.period'));
}
}
6 changes: 3 additions & 3 deletions src/Resources/ExceptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function getPluralModelLabel(): string

protected static function getNavigationGroup(): ?string
{
return config('filament-exceptions.navigation_group');
return __('filament-exceptions::filament-exceptions.labels.navigation_group');
}

protected static function getNavigationLabel(): string
Expand All @@ -38,7 +38,7 @@ protected static function getNavigationLabel(): string

protected static function getNavigationIcon(): string
{
return config('filament-exceptions::icons.navigation');
return config('filament-exceptions.icons.navigation');
}

public static function getSlug(): string
Expand Down Expand Up @@ -86,7 +86,7 @@ public static function form(Form $form): Form
Forms\Components\View::make('filament-exceptions::exception'),
]),
Pill::make('Headers')
->label(static fn (): string => __('filament-exceptions::filament-exceptions.labels.pills..headers'))
->label(static fn (): string => __('filament-exceptions::filament-exceptions.labels.pills.headers'))
->icon(static fn (): string => config('filament-exceptions.icons.headers'))
->schema([
Forms\Components\View::make('filament-exceptions::headers'),
Expand Down

0 comments on commit 4f4dfd2

Please sign in to comment.