An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor application source view
Andras Bacsai83b3f6fe4978
diff --git a/app/Livewire/Project/Application/Source.php b/app/Livewire/Project/Application/Source.phpindex 426626e558..2d75d91f29 100644--- a/app/Livewire/Project/Application/Source.php+++ b/app/Livewire/Project/Application/Source.php@@ -4,55 +4,92 @@ namespace App\Livewire\Project\Application;use App\Models\Application;use App\Models\PrivateKey;+use Livewire\Attributes\Locked;+use Livewire\Attributes\Rule;use Livewire\Component;class Source extends Component{- public $applicationId;-public Application $application;- public $private_keys;+ #[Locked]+ public $privateKeys;++ #[Rule(['nullable', 'string'])]+ public ?string $privateKeyName = null;++ #[Rule(['nullable', 'integer'])]+ public ?int $privateKeyId = null;- protected $rules = [- 'application.git_repository' => 'required',- 'application.git_branch' => 'required',- 'application.git_commit_sha' => 'nullable',- ];+ #[Rule(['required', 'string'])]+ public string $gitRepository;- protected $validationAttributes = [- 'application.git_repository' => 'repository',- 'application.git_branch' => 'branch',- 'application.git_commit_sha' => 'commit sha',- ];+ #[Rule(['required', 'string'])]+ public string $gitBranch;++ #[Rule(['nullable', 'string'])]+ public ?string $gitCommitSha = null;public function mount(){- $this->get_private_keys();+ try {+ $this->syncData();+ $this->getPrivateKeys();+ } catch (\Throwable $e) {+ handleError($e, $this);+ }+ }++ public function syncData(bool $toModel = false)+ {+ if ($toModel) {+ $this->validate();+ $this->application->update([+ 'git_repository' => $this->gitRepository,+ 'git_branch' => $this->gitBranch,+ 'git_commit_sha' => $this->gitCommitSha,+ 'private_key_id' => $this->privateKeyId,+ ]);+ } else {+ $this->gitRepository = $this->application->git_repository;+ $this->gitBranch = $this->application->git_branch;+ $this->gitCommitSha = $this->application->git_commit_sha;+ $this->privateKeyId = $this->application->private_key_id;+ $this->privateKeyName = data_get($this->application, 'private_key.name');+ }}- private function get_private_keys()+ private function getPrivateKeys(){- $this->private_keys = PrivateKey::whereTeamId(currentTeam()->id)->get()->reject(function ($key) {- return $key->id == $this->application->private_key_id;+ $this->privateKeys = PrivateKey::whereTeamId(currentTeam()->id)->get()->reject(function ($key) {+ return $key->id == $this->privateKeyId;});}- public function setPrivateKey(int $private_key_id)+ public function setPrivateKey(int $privateKeyId){- $this->application->private_key_id = $private_key_id;- $this->application->save();- $this->application->refresh();- $this->get_private_keys();+ try {+ $this->privateKeyId = $privateKeyId;+ $this->syncData(true);+ $this->getPrivateKeys();+ $this->application->refresh();+ $this->privateKeyName = $this->application->private_key->name;+ $this->dispatch('success', 'Private key updated!');+ } catch (\Throwable $e) {+ return handleError($e, $this);+ }}public function submit(){- $this->validate();- if (! $this->application->git_commit_sha) {- $this->application->git_commit_sha = 'HEAD';+ try {+ if (str($this->gitCommitSha)->isEmpty()) {+ $this->gitCommitSha = 'HEAD';+ }+ $this->syncData(true);+ $this->dispatch('success', 'Application source updated!');+ } catch (\Throwable $e) {+ return handleError($e, $this);}- $this->application->save();- $this->dispatch('success', 'Application source updated!');}}diff --git a/resources/views/livewire/project/application/source.blade.php b/resources/views/livewire/project/application/source.blade.phpindex 9a47566e50..4095c63e09 100644--- a/resources/views/livewire/project/application/source.blade.php+++ b/resources/views/livewire/project/application/source.blade.php@@ -27,24 +27,22 @@<div class="flex flex-col gap-2"><div class="flex gap-2">- <x-forms.input placeholder="coollabsio/coolify-example" id="application.git_repository"- label="Repository" />- <x-forms.input placeholder="main" id="application.git_branch" label="Branch" />+ <x-forms.input placeholder="coollabsio/coolify-example" id="gitRepository" label="Repository" />+ <x-forms.input placeholder="main" id="gitBranch" label="Branch" /></div><div class="flex items-end gap-2">- <x-forms.input placeholder="HEAD" id="application.git_commit_sha" placeholder="HEAD"- label="Commit SHA" />+ <x-forms.input placeholder="HEAD" id="gitCommitSha" placeholder="HEAD" label="Commit SHA" /></div></div>- @if (data_get($application, 'private_key_id'))+ @if ($privateKeyId)<h3 class="pt-4">Deploy Key</h3><div class="py-2 pt-4">Currently attached Private Key: <span- class="dark:text-warning">{{ data_get($application, 'private_key.name') }}</span>+ class="dark:text-warning">{{ $privateKeyName }}</span></div><h4 class="py-2 ">Select another Private Key</h4><div class="flex flex-wrap gap-2">- @foreach ($private_keys as $key)+ @foreach ($privateKeys as $key)<x-forms.button wire:click.defer="setPrivateKey('{{ $key->id }}')">{{ $key->name }}</x-forms.button>@endforeach