mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 13:14:45 +02:00
Move this over for the import
This commit is contained in:
parent
0af0bea90d
commit
090b2e6f1b
@ -4,16 +4,11 @@ namespace App\Filament\Resources;
|
|||||||
|
|
||||||
use App\Filament\Resources\EggResource\Pages;
|
use App\Filament\Resources\EggResource\Pages;
|
||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
use App\Services\Eggs\Sharing\EggImporterService;
|
|
||||||
use Exception;
|
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Notifications\Notification;
|
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Livewire\Component;
|
|
||||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
||||||
|
|
||||||
class EggResource extends Resource
|
class EggResource extends Resource
|
||||||
{
|
{
|
||||||
@ -178,35 +173,7 @@ class EggResource extends Resource
|
|||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
])
|
])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
Tables\Actions\Action::make('Import Egg')
|
//
|
||||||
->form([
|
|
||||||
Forms\Components\FileUpload::make('egg')->storeFiles(false),
|
|
||||||
])
|
|
||||||
->action(function (array $data, Component $livewire): void {
|
|
||||||
/** @var TemporaryUploadedFile $eggFile */
|
|
||||||
$eggFile = $data['egg'];
|
|
||||||
|
|
||||||
/** @var EggImporterService $eggImportService */
|
|
||||||
$eggImportService = resolve(EggImporterService::class);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$newEgg = $eggImportService->handle($eggFile);
|
|
||||||
} catch (Exception $exception) {
|
|
||||||
Notification::make()
|
|
||||||
->title("Imported egg successfully: {$exception->getMessage()}")
|
|
||||||
->success()
|
|
||||||
->send();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Notification::make()
|
|
||||||
->title("Imported egg successfully: $newEgg->name")
|
|
||||||
->success()
|
|
||||||
->send();
|
|
||||||
|
|
||||||
$livewire->redirect(route('filament.admin.resources.eggs.edit', [$newEgg]));
|
|
||||||
})
|
|
||||||
])
|
])
|
||||||
->bulkActions([
|
->bulkActions([
|
||||||
Tables\Actions\BulkActionGroup::make([
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
@ -3,8 +3,13 @@
|
|||||||
namespace App\Filament\Resources\EggResource\Pages;
|
namespace App\Filament\Resources\EggResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\EggResource;
|
use App\Filament\Resources\EggResource;
|
||||||
|
use App\Services\Eggs\Sharing\EggImporterService;
|
||||||
|
use Exception;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||||
|
|
||||||
class ListEggs extends ListRecords
|
class ListEggs extends ListRecords
|
||||||
{
|
{
|
||||||
@ -14,6 +19,41 @@ class ListEggs extends ListRecords
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Actions\CreateAction::make(),
|
Actions\CreateAction::make(),
|
||||||
|
|
||||||
|
Actions\Action::make('import')
|
||||||
|
->label('Import Egg')
|
||||||
|
->form([
|
||||||
|
Forms\Components\FileUpload::make('egg')
|
||||||
|
->acceptedFileTypes(['application/json'])
|
||||||
|
->storeFiles(false),
|
||||||
|
])
|
||||||
|
->action(function (array $data): void {
|
||||||
|
/** @var TemporaryUploadedFile $eggFile */
|
||||||
|
$eggFile = $data['egg'];
|
||||||
|
|
||||||
|
/** @var EggImporterService $eggImportService */
|
||||||
|
$eggImportService = resolve(EggImporterService::class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$newEgg = $eggImportService->handle($eggFile);
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
Notification::make()
|
||||||
|
->title("Imported egg successfully: {$exception->getMessage()}")
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title("Imported egg successfully: $newEgg->name")
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
redirect()->route('filament.admin.resources.eggs.edit', [$newEgg]);
|
||||||
|
|
||||||
|
// $livewire->redirect(route('filament.admin.resources.eggs.edit', [$newEgg]));
|
||||||
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user