From 52d84c5e9ec8eca76580ce5a8fc8ea2e1950bb0e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 13 Dec 2023 14:22:23 +0100 Subject: [PATCH] refactor: clone project --- app/Livewire/Project/CloneProject.php | 16 +++--- .../livewire/project/clone-project.blade.php | 50 +++++++++---------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/app/Livewire/Project/CloneProject.php b/app/Livewire/Project/CloneProject.php index 3a6a1db6f..7ce89f8de 100644 --- a/app/Livewire/Project/CloneProject.php +++ b/app/Livewire/Project/CloneProject.php @@ -19,12 +19,14 @@ class CloneProject extends Component public $servers; public ?Environment $environment = null; public ?int $selectedServer = null; + public ?int $selectedDestination = null; public ?Server $server = null; public $resources = []; public string $newProjectName = ''; protected $messages = [ 'selectedServer' => 'Please select a server.', + 'selectedDestination' => 'Please select a server & destination.', 'newProjectName' => 'Please enter a name for the new project.', ]; public function mount($project_uuid) @@ -34,7 +36,7 @@ public function mount($project_uuid) $this->environment = $this->project->environments->where('name', $this->environment_name)->first(); $this->project_id = $this->project->id; $this->servers = currentTeam()->servers; - $this->newProjectName = $this->project->name . ' (clone)'; + $this->newProjectName = str($this->project->name . '-clone-' . (string)new Cuid2(7))->slug(); } public function render() @@ -42,9 +44,10 @@ public function render() return view('livewire.project.clone-project'); } - public function selectServer($server_id) + public function selectServer($server_id, $destination_id) { $this->selectedServer = $server_id; + $this->selectedDestination = $destination_id; $this->server = $this->servers->where('id', $server_id)->first(); } @@ -52,7 +55,7 @@ public function clone() { try { $this->validate([ - 'selectedServer' => 'required', + 'selectedDestination' => 'required', 'newProjectName' => 'required', ]); $foundProject = Project::where('name', $this->newProjectName)->first(); @@ -81,7 +84,8 @@ public function clone() 'fqdn' => generateFqdn($this->server, $uuid), 'status' => 'exited', 'environment_id' => $newEnvironment->id, - 'destination_id' => $this->selectedServer, + // This is not correct, but we need to set it to something + 'destination_id' => $this->selectedDestination, ]); $newApplication->save(); $environmentVaribles = $application->environment_variables()->get(); @@ -107,7 +111,7 @@ public function clone() 'status' => 'exited', 'started_at' => null, 'environment_id' => $newEnvironment->id, - 'destination_id' => $this->selectedServer, + 'destination_id' => $this->selectedDestination, ]); $newDatabase->save(); $environmentVaribles = $database->environment_variables()->get(); @@ -133,7 +137,7 @@ public function clone() $newService = $service->replicate()->fill([ 'uuid' => $uuid, 'environment_id' => $newEnvironment->id, - 'destination_id' => $this->selectedServer, + 'destination_id' => $this->selectedDestination, ]); $newService->save(); foreach ($newService->applications() as $application) { diff --git a/resources/views/livewire/project/clone-project.blade.php b/resources/views/livewire/project/clone-project.blade.php index 7d1fd9070..3e6203281 100644 --- a/resources/views/livewire/project/clone-project.blade.php +++ b/resources/views/livewire/project/clone-project.blade.php @@ -1,36 +1,36 @@
-
-

Clone

- Clone to a New Project -
-
Quickly clone a project
+

Clone

+
Quickly clone all resources to a new project
+
+
+ + Clone
-

Servers

-
- @foreach ($servers as $srv) -
-
-
{{ $srv->name }}
- @isset($selectedServer) -
- {{ $srv->description }}
- @else -
- {{ $srv->description }}
- @endisset - +
+ @foreach ($servers->sortBy('id') as $server) +
+

{{ $server->name }}

+
{{ $server->description }}
+
Docker Networks
+
+ @foreach ($server->destinations() as $destination) +
+ {{ $destination->name }} +
+ @endforeach
@endforeach
+

Resources

-
+
@foreach ($environment->applications->sortBy('name') as $application) -
+
{{ $application->name }}
{{ $application->description }}
@@ -38,7 +38,7 @@ class="cursor-pointer box-without-bg bg-coolgray-200 group"
@endforeach @foreach ($environment->databases()->sortBy('name') as $database) -
+
{{ $database->name }}
{{ $database->description }}
@@ -46,7 +46,7 @@ class="cursor-pointer box-without-bg bg-coolgray-200 group"
@endforeach @foreach ($environment->services->sortBy('name') as $service) -
+
{{ $service->name }}
{{ $service->description }}