mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 11:26:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Filament\Components\Tables\Actions;
 | 
						|
 | 
						|
use App\Enums\EggFormat;
 | 
						|
use App\Models\Egg;
 | 
						|
use App\Services\Eggs\Sharing\EggExporterService;
 | 
						|
use Filament\Forms\Components\Placeholder;
 | 
						|
use Filament\Support\Enums\Alignment;
 | 
						|
use Filament\Tables\Actions\Action;
 | 
						|
 | 
						|
class ExportEggAction extends Action
 | 
						|
{
 | 
						|
    public static function getDefaultName(): ?string
 | 
						|
    {
 | 
						|
        return 'export';
 | 
						|
    }
 | 
						|
 | 
						|
    protected function setUp(): void
 | 
						|
    {
 | 
						|
        parent::setUp();
 | 
						|
 | 
						|
        $this->label(trans('filament-actions::export.modal.actions.export.label'));
 | 
						|
 | 
						|
        $this->icon('tabler-download');
 | 
						|
 | 
						|
        $this->authorize(fn () => auth()->user()->can('export egg'));
 | 
						|
 | 
						|
        $this->modalHeading(fn (Egg $egg) => trans('filament-actions::export.modal.actions.export.label') . '  ' . $egg->name);
 | 
						|
 | 
						|
        $this->modalIcon($this->icon);
 | 
						|
 | 
						|
        $this->form([
 | 
						|
            Placeholder::make('')
 | 
						|
                ->label(fn (Egg $egg) => trans('admin/egg.export.modal', ['egg' => $egg->name])),
 | 
						|
        ]);
 | 
						|
 | 
						|
        $this->modalFooterActionsAlignment(Alignment::Center);
 | 
						|
 | 
						|
        $this->modalFooterActions([
 | 
						|
            Action::make('json')
 | 
						|
                ->label(trans('admin/egg.export.as') . ' .json')
 | 
						|
                ->action(fn (EggExporterService $service, Egg $egg) => response()->streamDownload(function () use ($service, $egg) {
 | 
						|
                    echo $service->handle($egg->id, EggFormat::JSON);
 | 
						|
                }, 'egg-' . $egg->getKebabName() . '.json'))
 | 
						|
                ->close(),
 | 
						|
            Action::make('yaml')
 | 
						|
                ->label(trans('admin/egg.export.as') . ' .yaml')
 | 
						|
                ->action(fn (EggExporterService $service, Egg $egg) => response()->streamDownload(function () use ($service, $egg) {
 | 
						|
                    echo $service->handle($egg->id, EggFormat::YAML);
 | 
						|
                }, 'egg-' . $egg->getKebabName() . '.yaml'))
 | 
						|
                ->close(),
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
}
 |