Support naming docker images on eggs; closes #4052
Bumps PTDL_v1 export images to PTDL_v2, updates the Minecraft specific eggs to use named images.
This commit is contained in:
parent
53207abcb3
commit
c8faf64059
17 changed files with 212 additions and 261 deletions
|
@ -74,11 +74,7 @@ class EggController extends Controller
|
|||
public function store(EggFormRequest $request): RedirectResponse
|
||||
{
|
||||
$data = $request->normalize();
|
||||
if (!empty($data['docker_images']) && !is_array($data['docker_images'])) {
|
||||
$data['docker_images'] = array_map(function ($value) {
|
||||
return trim($value);
|
||||
}, explode("\n", $data['docker_images']));
|
||||
}
|
||||
$data['docker_images'] = $this->normalizeDockerImages($data['docker_images'] ?? null);
|
||||
|
||||
$egg = $this->creationService->handle($data);
|
||||
$this->alert->success(trans('admin/nests.eggs.notices.egg_created'))->flash();
|
||||
|
@ -91,7 +87,14 @@ class EggController extends Controller
|
|||
*/
|
||||
public function view(Egg $egg): View
|
||||
{
|
||||
return view('admin.eggs.view', ['egg' => $egg]);
|
||||
return view('admin.eggs.view', [
|
||||
'egg' => $egg,
|
||||
'images' => array_map(
|
||||
fn ($key, $value) => $key === $value ? $value : "$key|$value",
|
||||
array_keys($egg->docker_images),
|
||||
$egg->docker_images,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,11 +107,7 @@ class EggController extends Controller
|
|||
public function update(EggFormRequest $request, Egg $egg): RedirectResponse
|
||||
{
|
||||
$data = $request->normalize();
|
||||
if (!empty($data['docker_images']) && !is_array($data['docker_images'])) {
|
||||
$data['docker_images'] = array_map(function ($value) {
|
||||
return trim($value);
|
||||
}, explode("\n", $data['docker_images']));
|
||||
}
|
||||
$data['docker_images'] = $this->normalizeDockerImages($data['docker_images'] ?? null);
|
||||
|
||||
$this->updateService->handle($egg, $data);
|
||||
$this->alert->success(trans('admin/nests.eggs.notices.updated'))->flash();
|
||||
|
@ -129,4 +128,22 @@ class EggController extends Controller
|
|||
|
||||
return redirect()->route('admin.nests.view', $egg->nest_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a string of docker image data into the expected egg format.
|
||||
*/
|
||||
protected function normalizeDockerImages(string $input = null): array
|
||||
{
|
||||
$data = array_map(fn ($value) => trim($value), explode("\n", $input ?? ''));
|
||||
|
||||
$images = [];
|
||||
// Iterate over the image data provided and convert it into a name => image
|
||||
// pairing that is used to improve the display on the front-end.
|
||||
foreach ($data as $value) {
|
||||
$parts = explode('|', $value, 2);
|
||||
$images[$parts[0]] = empty($parts[1]) ? $parts[0] : $parts[1];
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue