order column added to track order of env in the UI
This commit is contained in:
@@ -48,7 +48,7 @@ class All extends Component
|
|||||||
{
|
{
|
||||||
$this->resource->load(['environment_variables', 'environment_variables_preview']);
|
$this->resource->load(['environment_variables', 'environment_variables_preview']);
|
||||||
|
|
||||||
$sortBy = $this->resource->settings->is_env_sorting_enabled ? 'key' : 'id';
|
$sortBy = $this->resource->settings->is_env_sorting_enabled ? 'key' : 'order';
|
||||||
|
|
||||||
$sortFunction = function ($variables) use ($sortBy) {
|
$sortFunction = function ($variables) use ($sortBy) {
|
||||||
if ($sortBy === 'key') {
|
if ($sortBy === 'key') {
|
||||||
@@ -56,7 +56,7 @@ class All extends Component
|
|||||||
return strtolower($item->key);
|
return strtolower($item->key);
|
||||||
}, SORT_NATURAL | SORT_FLAG_CASE)->values();
|
}, SORT_NATURAL | SORT_FLAG_CASE)->values();
|
||||||
} else {
|
} else {
|
||||||
return $variables->sortBy('id')->values();
|
return $variables->sortBy('order')->values();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,12 +102,40 @@ class All extends Component
|
|||||||
$this->handleSingleSubmit($data);
|
$this->handleSingleSubmit($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->updateOrder();
|
||||||
$this->sortEnvironmentVariables();
|
$this->sortEnvironmentVariables();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateOrder()
|
||||||
|
{
|
||||||
|
$variables = parseEnvFormatToArray($this->variables);
|
||||||
|
$order = 1;
|
||||||
|
foreach ($variables as $key => $value) {
|
||||||
|
$env = $this->resource->environment_variables()->where('key', $key)->first();
|
||||||
|
if ($env) {
|
||||||
|
$env->order = $order;
|
||||||
|
$env->save();
|
||||||
|
}
|
||||||
|
$order++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->showPreview) {
|
||||||
|
$previewVariables = parseEnvFormatToArray($this->variablesPreview);
|
||||||
|
$order = 1;
|
||||||
|
foreach ($previewVariables as $key => $value) {
|
||||||
|
$env = $this->resource->environment_variables_preview()->where('key', $key)->first();
|
||||||
|
if ($env) {
|
||||||
|
$env->order = $order;
|
||||||
|
$env->save();
|
||||||
|
}
|
||||||
|
$order++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function handleBulkSubmit()
|
private function handleBulkSubmit()
|
||||||
{
|
{
|
||||||
$variables = parseEnvFormatToArray($this->variables);
|
$variables = parseEnvFormatToArray($this->variables);
|
||||||
@@ -131,7 +159,9 @@ class All extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$maxOrder = $this->resource->environment_variables()->max('order') ?? 0;
|
||||||
$environment = $this->createEnvironmentVariable($data);
|
$environment = $this->createEnvironmentVariable($data);
|
||||||
|
$environment->order = $maxOrder + 1;
|
||||||
$environment->save();
|
$environment->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('environment_variables', function (Blueprint $table) {
|
||||||
|
$table->integer('order')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('environment_variables', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('order');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user