Allow to register "special file" alert banners (#1861)

This commit is contained in:
Boy132 2025-11-04 12:48:18 +01:00 committed by GitHub
parent d61583cd7b
commit 852f7beb39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 7 deletions

View File

@ -7,11 +7,13 @@ use App\Exceptions\Repository\FileNotEditableException;
use App\Facades\Activity;
use App\Filament\Server\Resources\Files\FileResource;
use App\Livewire\AlertBanner;
use App\Models\File;
use App\Models\Permission;
use App\Models\Server;
use App\Repositories\Daemon\DaemonFileRepository;
use App\Traits\Filament\CanCustomizeHeaderActions;
use App\Traits\Filament\CanCustomizeHeaderWidgets;
use Closure;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Forms\Components\CodeEditor;
@ -215,15 +217,17 @@ class EditFiles extends Page
$this->previousUrl = url()->previous();
if (str($path)->endsWith('.pelicanignore')) {
AlertBanner::make('.pelicanignore_info')
->title(trans('server/file.alerts.pelicanignore.title'))
->body(trans('server/file.alerts.pelicanignore.body'))
foreach (File::getSpecialFiles() as $fileName => $data) {
if ($data['check'] instanceof Closure && $data['check']($path)) {
AlertBanner::make($fileName . '_info')
->title($data['title'])
->body($data['body'])
->info()
->closable()
->send();
}
}
}
protected function authorizeAccess(): void
{

View File

@ -5,6 +5,7 @@ namespace App\Models;
use App\Livewire\AlertBanner;
use App\Repositories\Daemon\DaemonFileRepository;
use Carbon\Carbon;
use Closure;
use Exception;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
@ -54,6 +55,32 @@ class File extends Model
protected static ?string $searchTerm;
/** @var array<string, array<string, string|Closure|null>> */
protected static array $customSpecialFiles = [];
public static function registerSpecialFile(string $fileName, string|Closure $bannerTitle, string|Closure|null $bannerBody = null, ?Closure $nameCheck = null): void
{
static::$customSpecialFiles[$fileName] = [
'title' => $bannerTitle,
'body' => $bannerBody,
'check' => $nameCheck ?? fn (string $path) => str($path)->endsWith($fileName),
];
}
/** @return array<string, array<string, string|Closure|null>> */
public static function getSpecialFiles(): array
{
$specialFiles = [
'.pelicanignore' => [
'title' => fn () => trans('server/file.alerts.pelicanignore.title'),
'body' => fn () => trans('server/file.alerts.pelicanignore.body'),
'check' => fn (string $path) => str($path)->endsWith('.pelicanignore'),
],
];
return array_merge($specialFiles, static::$customSpecialFiles);
}
public static function get(Server $server, string $path = '/', ?string $searchTerm = null): Builder
{
self::$server = $server;