mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 22:14:45 +02:00

* Init * Health Page * Admin API Keys * Update API Keys * Database Hosts * Mounts * remove `s` * Users * Webhooks * Server never again... * Fix Server * Settings * Update Mounts * Update Databasehost * Update Server * Oops, Update Server * Nodes * Update User * Dashboard * Update Server * Profile * Egg * Role & Update Egg * Add base Laravel lang files * update apikey * remove html back to settings, remove comment * add `:resource` to create_action * Update Egg * Update Egg v2 * Update 1 * trans cf info label * Update charts * more trans * Update Webhook * update Health * Update Server * Update Role * Fixes * Bulk Update * AnotherOne * Fix relation button label * rename `admin1` to `admin` Leftover from testing... oops * More Translations * Updates * `pint` + Relation Manager Titles
88 lines
2.8 KiB
PHP
88 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Components\Actions;
|
|
|
|
use App\Models\Egg;
|
|
use App\Services\Eggs\Sharing\EggImporterService;
|
|
use Exception;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\Tabs;
|
|
use Filament\Forms\Components\Tabs\Tab;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Notifications\Notification;
|
|
|
|
class ImportEggAction extends Action
|
|
{
|
|
public static function getDefaultName(): ?string
|
|
{
|
|
return 'import';
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->label(trans('filament-actions::import.modal.actions.import.label'));
|
|
|
|
$this->authorize(fn () => auth()->user()->can('import egg'));
|
|
|
|
$this->form([
|
|
Tabs::make('Tabs')
|
|
->contained(false)
|
|
->tabs([
|
|
Tab::make(trans('admin/egg.import.file'))
|
|
->icon('tabler-file-upload')
|
|
->schema([
|
|
FileUpload::make('egg')
|
|
->label('Egg')
|
|
->hint(trans('admin/egg.import.egg_help'))
|
|
->acceptedFileTypes(['application/json'])
|
|
->storeFiles(false)
|
|
->multiple(),
|
|
]),
|
|
Tab::make(trans('admin/egg.import.url'))
|
|
->icon('tabler-world-upload')
|
|
->schema([
|
|
TextInput::make('url')
|
|
->default(fn (Egg $egg) => $egg->update_url)
|
|
->label(trans('admin/egg.import.url'))
|
|
->hint(trans('admin/egg.import.url_help'))
|
|
->url(),
|
|
]),
|
|
]),
|
|
]);
|
|
|
|
$this->action(function (array $data, EggImporterService $eggImportService): void {
|
|
try {
|
|
if (!empty($data['egg'])) {
|
|
$eggFile = $data['egg'];
|
|
|
|
foreach ($eggFile as $file) {
|
|
$eggImportService->fromFile($file);
|
|
}
|
|
}
|
|
|
|
if (!empty($data['url'])) {
|
|
$eggImportService->fromUrl($data['url']);
|
|
}
|
|
} catch (Exception $exception) {
|
|
Notification::make()
|
|
->title(trans('admin/egg.import.import_failed'))
|
|
->body($exception->getMessage())
|
|
->danger()
|
|
->send();
|
|
|
|
report($exception);
|
|
|
|
return;
|
|
}
|
|
|
|
Notification::make()
|
|
->title(trans('admin/egg.import.import_success'))
|
|
->success()
|
|
->send();
|
|
});
|
|
}
|
|
}
|