mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-04 20:36:52 +01:00
Allow to register "special file" alert banners (#1861)
This commit is contained in:
parent
d61583cd7b
commit
852f7beb39
@ -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,13 +217,15 @@ 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'))
|
||||
->info()
|
||||
->closable()
|
||||
->send();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user