Allow uploading multiple eggs
I'm sure there is a cleaner way to do it, but this works :) Also ran pint...
This commit is contained in:
parent
82c294ab63
commit
05c4610654
@ -21,11 +21,12 @@ class ListEggs extends ListRecords
|
||||
Actions\CreateAction::make(),
|
||||
|
||||
Actions\Action::make('import')
|
||||
->label('Import Egg')
|
||||
->label('Import')
|
||||
->form([
|
||||
Forms\Components\FileUpload::make('egg')
|
||||
->acceptedFileTypes(['application/json'])
|
||||
->storeFiles(false),
|
||||
->storeFiles(false)
|
||||
->multiple(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
/** @var TemporaryUploadedFile $eggFile */
|
||||
@ -35,7 +36,7 @@ class ListEggs extends ListRecords
|
||||
$eggImportService = resolve(EggImporterService::class);
|
||||
|
||||
try {
|
||||
$newEgg = $eggImportService->handle($eggFile);
|
||||
$eggImportService->handle($eggFile);
|
||||
} catch (Exception $exception) {
|
||||
Notification::make()
|
||||
->title('Egg Import Failed')
|
||||
@ -48,11 +49,9 @@ class ListEggs extends ListRecords
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title("Egg Import Success: $newEgg->name")
|
||||
->title('Egg Import Success')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
redirect()->route('filament.admin.resources.eggs.edit', [$newEgg]);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
@ -207,6 +207,7 @@ class ServerResource extends Resource
|
||||
|
||||
// Do not add non numerical ports
|
||||
$update = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -217,7 +218,7 @@ class ServerResource extends Resource
|
||||
}
|
||||
|
||||
$start = max((int) $start, 0);
|
||||
$end = min((int) $end, 2**16-1);
|
||||
$end = min((int) $end, 2 ** 16 - 1);
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
$ports->push($i);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ class Node extends Model
|
||||
$ips = collect();
|
||||
if (is_ip($this->fqdn)) {
|
||||
$ips->push($this->fqdn);
|
||||
} else if ($dnsRecords = gethostbynamel($this->fqdn)) {
|
||||
} elseif ($dnsRecords = gethostbynamel($this->fqdn)) {
|
||||
$ips->concat($dnsRecords);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ namespace App\Services\Eggs\Sharing;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Models\Egg;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use App\Models\EggVariable;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use App\Services\Eggs\EggParserService;
|
||||
@ -21,25 +20,31 @@ class EggImporterService
|
||||
*
|
||||
* @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable
|
||||
*/
|
||||
public function handle(UploadedFile $file): Egg
|
||||
public function handle(array $files): array
|
||||
{
|
||||
$parsed = $this->parser->handle($file);
|
||||
$eggs = [];
|
||||
|
||||
return $this->connection->transaction(function () use ($parsed) {
|
||||
$egg = (new Egg())->forceFill([
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'author' => Arr::get($parsed, 'author'),
|
||||
'copy_script_from' => null,
|
||||
]);
|
||||
foreach ($files as $file) {
|
||||
$parsed = $this->parser->handle($file);
|
||||
|
||||
$egg = $this->parser->fillFromParsed($egg, $parsed);
|
||||
$egg->save();
|
||||
$egg = $this->connection->transaction(function () use ($parsed) {
|
||||
$egg = (new Egg())->forceFill([
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'author' => Arr::get($parsed, 'author'),
|
||||
'copy_script_from' => null,
|
||||
]);
|
||||
|
||||
foreach ($parsed['variables'] ?? [] as $variable) {
|
||||
EggVariable::query()->forceCreate(array_merge($variable, ['egg_id' => $egg->id]));
|
||||
}
|
||||
$egg = $this->parser->fillFromParsed($egg, $parsed);
|
||||
$egg->save();
|
||||
|
||||
return $egg;
|
||||
});
|
||||
foreach ($parsed['variables'] ?? [] as $variable) {
|
||||
EggVariable::query()->forceCreate(array_merge($variable, ['egg_id' => $egg->id]));
|
||||
}
|
||||
|
||||
return $egg;
|
||||
});
|
||||
}
|
||||
|
||||
return $eggs;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
<x-filament-panels::page>
|
||||
|
||||
<x-filament::tabs label="Content tabs">
|
||||
<x-filament::tabs.item disabled>Panel's Resources: </x-filament::tabs.item>
|
||||
<x-filament::tabs disabled>
|
||||
<x-filament::tabs.item disabled>Overview: </x-filament::tabs.item>
|
||||
|
||||
<x-filament::tabs.item
|
||||
icon="tabler-server-2"
|
||||
:active="$activeTab === 'nodes'"
|
||||
wire:click="$set('activeTab', 'nodes')"
|
||||
>
|
||||
Nodes
|
||||
<x-slot name="badge">{{ $nodesCount }}</x-slot>
|
||||
@ -14,8 +12,6 @@
|
||||
|
||||
<x-filament::tabs.item
|
||||
icon="tabler-brand-docker"
|
||||
:active="$activeTab === 'servers'"
|
||||
wire:click="$set('activeTab', 'servers')"
|
||||
>
|
||||
Servers
|
||||
<x-slot name="badge">{{ $serversCount }}</x-slot>
|
||||
@ -23,8 +19,6 @@
|
||||
|
||||
<x-filament::tabs.item
|
||||
icon="tabler-eggs"
|
||||
:active="$activeTab === 'eggs'"
|
||||
wire:click="$set('activeTab', 'eggs')"
|
||||
>
|
||||
Eggs
|
||||
<x-slot name="badge">{{ $eggsCount }}</x-slot>
|
||||
@ -32,8 +26,6 @@
|
||||
|
||||
<x-filament::tabs.item
|
||||
icon="tabler-users"
|
||||
:active="$activeTab === 'users'"
|
||||
wire:click="$set('activeTab', 'users')"
|
||||
>
|
||||
Users
|
||||
<x-slot name="badge">{{ $usersCount }}</x-slot>
|
||||
|
Loading…
x
Reference in New Issue
Block a user