refactor: clone project
This commit is contained in:
		@@ -19,12 +19,14 @@ class CloneProject extends Component
 | 
				
			|||||||
    public $servers;
 | 
					    public $servers;
 | 
				
			||||||
    public ?Environment $environment = null;
 | 
					    public ?Environment $environment = null;
 | 
				
			||||||
    public ?int $selectedServer = null;
 | 
					    public ?int $selectedServer = null;
 | 
				
			||||||
 | 
					    public ?int $selectedDestination = null;
 | 
				
			||||||
    public ?Server $server = null;
 | 
					    public ?Server $server = null;
 | 
				
			||||||
    public $resources = [];
 | 
					    public $resources = [];
 | 
				
			||||||
    public string $newProjectName = '';
 | 
					    public string $newProjectName = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected $messages = [
 | 
					    protected $messages = [
 | 
				
			||||||
        'selectedServer' => 'Please select a server.',
 | 
					        'selectedServer' => 'Please select a server.',
 | 
				
			||||||
 | 
					        'selectedDestination' => 'Please select a server & destination.',
 | 
				
			||||||
        'newProjectName' => 'Please enter a name for the new project.',
 | 
					        'newProjectName' => 'Please enter a name for the new project.',
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
    public function mount($project_uuid)
 | 
					    public function mount($project_uuid)
 | 
				
			||||||
@@ -34,7 +36,7 @@ class CloneProject extends Component
 | 
				
			|||||||
        $this->environment = $this->project->environments->where('name', $this->environment_name)->first();
 | 
					        $this->environment = $this->project->environments->where('name', $this->environment_name)->first();
 | 
				
			||||||
        $this->project_id = $this->project->id;
 | 
					        $this->project_id = $this->project->id;
 | 
				
			||||||
        $this->servers = currentTeam()->servers;
 | 
					        $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()
 | 
					    public function render()
 | 
				
			||||||
@@ -42,9 +44,10 @@ class CloneProject extends Component
 | 
				
			|||||||
        return view('livewire.project.clone-project');
 | 
					        return view('livewire.project.clone-project');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function selectServer($server_id)
 | 
					    public function selectServer($server_id, $destination_id)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->selectedServer = $server_id;
 | 
					        $this->selectedServer = $server_id;
 | 
				
			||||||
 | 
					        $this->selectedDestination = $destination_id;
 | 
				
			||||||
        $this->server = $this->servers->where('id', $server_id)->first();
 | 
					        $this->server = $this->servers->where('id', $server_id)->first();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -52,7 +55,7 @@ class CloneProject extends Component
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            $this->validate([
 | 
					            $this->validate([
 | 
				
			||||||
                'selectedServer' => 'required',
 | 
					                'selectedDestination' => 'required',
 | 
				
			||||||
                'newProjectName' => 'required',
 | 
					                'newProjectName' => 'required',
 | 
				
			||||||
            ]);
 | 
					            ]);
 | 
				
			||||||
            $foundProject = Project::where('name', $this->newProjectName)->first();
 | 
					            $foundProject = Project::where('name', $this->newProjectName)->first();
 | 
				
			||||||
@@ -81,7 +84,8 @@ class CloneProject extends Component
 | 
				
			|||||||
                    'fqdn' => generateFqdn($this->server, $uuid),
 | 
					                    'fqdn' => generateFqdn($this->server, $uuid),
 | 
				
			||||||
                    'status' => 'exited',
 | 
					                    'status' => 'exited',
 | 
				
			||||||
                    'environment_id' => $newEnvironment->id,
 | 
					                    '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();
 | 
					                $newApplication->save();
 | 
				
			||||||
                $environmentVaribles = $application->environment_variables()->get();
 | 
					                $environmentVaribles = $application->environment_variables()->get();
 | 
				
			||||||
@@ -107,7 +111,7 @@ class CloneProject extends Component
 | 
				
			|||||||
                    'status' => 'exited',
 | 
					                    'status' => 'exited',
 | 
				
			||||||
                    'started_at' => null,
 | 
					                    'started_at' => null,
 | 
				
			||||||
                    'environment_id' => $newEnvironment->id,
 | 
					                    'environment_id' => $newEnvironment->id,
 | 
				
			||||||
                    'destination_id' => $this->selectedServer,
 | 
					                    'destination_id' => $this->selectedDestination,
 | 
				
			||||||
                ]);
 | 
					                ]);
 | 
				
			||||||
                $newDatabase->save();
 | 
					                $newDatabase->save();
 | 
				
			||||||
                $environmentVaribles = $database->environment_variables()->get();
 | 
					                $environmentVaribles = $database->environment_variables()->get();
 | 
				
			||||||
@@ -133,7 +137,7 @@ class CloneProject extends Component
 | 
				
			|||||||
                $newService = $service->replicate()->fill([
 | 
					                $newService = $service->replicate()->fill([
 | 
				
			||||||
                    'uuid' => $uuid,
 | 
					                    'uuid' => $uuid,
 | 
				
			||||||
                    'environment_id' => $newEnvironment->id,
 | 
					                    'environment_id' => $newEnvironment->id,
 | 
				
			||||||
                    'destination_id' => $this->selectedServer,
 | 
					                    'destination_id' => $this->selectedDestination,
 | 
				
			||||||
                ]);
 | 
					                ]);
 | 
				
			||||||
                $newService->save();
 | 
					                $newService->save();
 | 
				
			||||||
                foreach ($newService->applications() as $application) {
 | 
					                foreach ($newService->applications() as $application) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,36 +1,36 @@
 | 
				
			|||||||
<form wire:submit='clone'>
 | 
					<form wire:submit='clone'>
 | 
				
			||||||
    <div class="flex flex-col">
 | 
					    <div class="flex flex-col">
 | 
				
			||||||
        <div class="flex gap-2">
 | 
					 | 
				
			||||||
        <h1>Clone</h1>
 | 
					        <h1>Clone</h1>
 | 
				
			||||||
            <x-forms.button type="submit">Clone to a New Project</x-forms.button>
 | 
					        <div class="subtitle ">Quickly clone all resources to a new project</div>
 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <div class="subtitle ">Quickly clone a project</div>
 | 
					 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					    <div class="flex items-end gap-2">
 | 
				
			||||||
        <x-forms.input required id="newProjectName" label="New Project Name" />
 | 
					        <x-forms.input required id="newProjectName" label="New Project Name" />
 | 
				
			||||||
 | 
					        <x-forms.button type="submit">Clone</x-forms.button>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
    <h3 class="pt-4 pb-2">Servers</h3>
 | 
					    <h3 class="pt-4 pb-2">Servers</h3>
 | 
				
			||||||
    <div class="grid gap-2 lg:grid-cols-3">
 | 
					    <div class="flex flex-col gap-4">
 | 
				
			||||||
        @foreach ($servers as $srv)
 | 
					        @foreach ($servers->sortBy('id') as $server)
 | 
				
			||||||
            <div wire:click="selectServer('{{ $srv->id }}')"
 | 
					            <div class="p-4 border border-coolgray-500">
 | 
				
			||||||
                class="cursor-pointer box-without-bg bg-coolgray-200 group"
 | 
					                <h3>{{ $server->name }}</h3>
 | 
				
			||||||
                :class="'{{ $selectedServer === $srv->id }}' && 'bg-coollabs'">
 | 
					                <h5>{{ $server->description }}</h5>
 | 
				
			||||||
                <div class="flex flex-col mx-6">
 | 
					                <div class="pt-4 pb-2">Docker Networks</div>
 | 
				
			||||||
                    <div :class="'{{ $selectedServer === $srv->id }}' && 'text-white'"> {{ $srv->name }}</div>
 | 
					                <div class="grid grid-cols-1 gap-2 pb-4 lg:grid-cols-4">
 | 
				
			||||||
                    @isset($selectedServer)
 | 
					                    @foreach ($server->destinations() as $destination)
 | 
				
			||||||
                        <div :class="'{{ $selectedServer === $srv->id }}' && 'text-white pt-2 text-xs font-bold'">
 | 
					                        <div class="cursor-pointer box-without-bg bg-coolgray-200 group"
 | 
				
			||||||
                            {{ $srv->description }}</div>
 | 
					                            :class="'{{ $selectedDestination === $destination->id }}' && 'bg-coollabs text-white'"
 | 
				
			||||||
                    @else
 | 
					                            wire:click="selectServer('{{ $server->id }}', '{{ $destination->id }}')">
 | 
				
			||||||
                        <div class="description">
 | 
					                            {{ $destination->name }}
 | 
				
			||||||
                            {{ $srv->description }}</div>
 | 
					                        </div>
 | 
				
			||||||
                    @endisset
 | 
					                    @endforeach
 | 
				
			||||||
 | 
					 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        @endforeach
 | 
					        @endforeach
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <h3 class="pt-4 pb-2">Resources</h3>
 | 
					    <h3 class="pt-4 pb-2">Resources</h3>
 | 
				
			||||||
    <div class="grid grid-cols-1 gap-2">
 | 
					    <div class="grid grid-cols-1 gap-2 p-4 border border-coolgray-500">
 | 
				
			||||||
        @foreach ($environment->applications->sortBy('name') as $application)
 | 
					        @foreach ($environment->applications->sortBy('name') as $application)
 | 
				
			||||||
            <div class="p-2 border border-coolgray-200">
 | 
					            <div>
 | 
				
			||||||
                <div class="flex flex-col">
 | 
					                <div class="flex flex-col">
 | 
				
			||||||
                    <div class="font-bold text-white">{{ $application->name }}</div>
 | 
					                    <div class="font-bold text-white">{{ $application->name }}</div>
 | 
				
			||||||
                    <div class="description">{{ $application->description }}</div>
 | 
					                    <div class="description">{{ $application->description }}</div>
 | 
				
			||||||
@@ -38,7 +38,7 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        @endforeach
 | 
					        @endforeach
 | 
				
			||||||
        @foreach ($environment->databases()->sortBy('name') as $database)
 | 
					        @foreach ($environment->databases()->sortBy('name') as $database)
 | 
				
			||||||
            <div class="p-2 border border-coolgray-200">
 | 
					            <div>
 | 
				
			||||||
                <div class="flex flex-col">
 | 
					                <div class="flex flex-col">
 | 
				
			||||||
                    <div class="font-bold text-white">{{ $database->name }}</div>
 | 
					                    <div class="font-bold text-white">{{ $database->name }}</div>
 | 
				
			||||||
                    <div class="description">{{ $database->description }}</div>
 | 
					                    <div class="description">{{ $database->description }}</div>
 | 
				
			||||||
@@ -46,7 +46,7 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        @endforeach
 | 
					        @endforeach
 | 
				
			||||||
        @foreach ($environment->services->sortBy('name') as $service)
 | 
					        @foreach ($environment->services->sortBy('name') as $service)
 | 
				
			||||||
            <div class="p-2 border border-coolgray-200">
 | 
					            <div>
 | 
				
			||||||
                <div class="flex flex-col">
 | 
					                <div class="flex flex-col">
 | 
				
			||||||
                    <div class="font-bold text-white">{{ $service->name }}</div>
 | 
					                    <div class="font-bold text-white">{{ $service->name }}</div>
 | 
				
			||||||
                    <div class="description">{{ $service->description }}</div>
 | 
					                    <div class="description">{{ $service->description }}</div>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user