mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-17 04:59:30 +00:00
cleanup all.php
This commit is contained in:
@@ -18,7 +18,7 @@ class All extends Component
|
||||
|
||||
protected $listeners = [
|
||||
'saveKey' => 'submit',
|
||||
//'environmentVariableDeleted' => 'refreshEnvs',
|
||||
'environmentVariableDeleted' => 'refreshEnvs',
|
||||
];
|
||||
|
||||
protected $rules = [
|
||||
@@ -41,24 +41,24 @@ class All extends Component
|
||||
{
|
||||
$sortBy = 'key'; // Always sort by key
|
||||
$this->resource->load(['environment_variables', 'environment_variables_preview']);
|
||||
$this->resource->environment_variables = $this->resource->environment_variables->sortBy(function ($item) use ($sortBy) {
|
||||
return strtolower($item->key);
|
||||
}, SORT_NATURAL | SORT_FLAG_CASE)->values();
|
||||
$this->resource->environment_variables_preview = $this->resource->environment_variables_preview->sortBy(function ($item) use ($sortBy) {
|
||||
return strtolower($item->key);
|
||||
}, SORT_NATURAL | SORT_FLAG_CASE)->values();
|
||||
$this->resource->environment_variables = $this->sortEnvironmentVariables($this->resource->environment_variables, $sortBy);
|
||||
$this->resource->environment_variables_preview = $this->sortEnvironmentVariables($this->resource->environment_variables_preview, $sortBy);
|
||||
$this->getDevView();
|
||||
}
|
||||
|
||||
private function sortEnvironmentVariables($variables, $sortBy)
|
||||
{
|
||||
return $variables->sortBy(function ($item) use ($sortBy) {
|
||||
return strtolower($item->key);
|
||||
}, SORT_NATURAL | SORT_FLAG_CASE)->values();
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
{
|
||||
if ($this->resourceClass === 'App\Models\Application' && data_get($this->resource, 'build_pack') !== 'dockercompose') {
|
||||
$this->resource->settings->save();
|
||||
$this->sortMe();
|
||||
$this->dispatch('success', 'Environment variable settings updated.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getDevView()
|
||||
{
|
||||
@@ -91,6 +91,19 @@ class All extends Component
|
||||
{
|
||||
try {
|
||||
if ($data === null) {
|
||||
$this->handleBulkSubmit();
|
||||
} else {
|
||||
$this->handleSingleSubmit($data);
|
||||
}
|
||||
|
||||
$this->sortMe();
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleBulkSubmit()
|
||||
{
|
||||
$variables = parseEnvFormatToArray($this->variables);
|
||||
$this->deleteRemovedVariables(false, $variables);
|
||||
$this->updateOrCreateVariables(false, $variables);
|
||||
@@ -101,15 +114,23 @@ class All extends Component
|
||||
$this->updateOrCreateVariables(true, $previewVariables);
|
||||
}
|
||||
|
||||
$this->sortMe();
|
||||
$this->dispatch('success', 'Environment variables updated.');
|
||||
} else {
|
||||
}
|
||||
|
||||
private function handleSingleSubmit($data)
|
||||
{
|
||||
$found = $this->resource->environment_variables()->where('key', $data['key'])->first();
|
||||
if ($found) {
|
||||
$this->dispatch('error', 'Environment variable already exists.');
|
||||
return;
|
||||
}
|
||||
|
||||
$environment = $this->createEnvironmentVariable($data);
|
||||
$environment->save();
|
||||
}
|
||||
|
||||
private function createEnvironmentVariable($data)
|
||||
{
|
||||
$environment = new EnvironmentVariable;
|
||||
$environment->key = $data['key'];
|
||||
$environment->value = $data['value'];
|
||||
@@ -125,13 +146,7 @@ class All extends Component
|
||||
$environment->$resourceIdField = $this->resource->id;
|
||||
}
|
||||
|
||||
$environment->save();
|
||||
}
|
||||
|
||||
$this->sortMe();
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
return $environment;
|
||||
}
|
||||
|
||||
private function getResourceIdField($resourceType)
|
||||
|
||||
Reference in New Issue
Block a user