wip: ui for services
This commit is contained in:
30
app/Http/Livewire/Project/Service/Application.php
Normal file
30
app/Http/Livewire/Project/Service/Application.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Service;
|
||||
|
||||
use App\Models\ServiceApplication;
|
||||
use Livewire\Component;
|
||||
|
||||
class Application extends Component
|
||||
{
|
||||
public ServiceApplication $application;
|
||||
protected $rules = [
|
||||
'application.human_name' => 'nullable',
|
||||
'application.fqdn' => 'nullable',
|
||||
];
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.application');
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$this->validate();
|
||||
$this->application->save();
|
||||
} catch (\Throwable $e) {
|
||||
ray($e);
|
||||
} finally {
|
||||
$this->emit('generateDockerCompose');
|
||||
}
|
||||
}
|
||||
}
|
||||
30
app/Http/Livewire/Project/Service/Database.php
Normal file
30
app/Http/Livewire/Project/Service/Database.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Service;
|
||||
|
||||
use App\Models\ServiceApplication;
|
||||
use App\Models\ServiceDatabase;
|
||||
use Livewire\Component;
|
||||
|
||||
class Database extends Component
|
||||
{
|
||||
public ServiceDatabase $database;
|
||||
protected $rules = [
|
||||
'database.human_name' => 'nullable',
|
||||
];
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.database');
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$this->validate();
|
||||
$this->database->save();
|
||||
} catch (\Throwable $e) {
|
||||
ray($e);
|
||||
} finally {
|
||||
$this->emit('generateDockerCompose');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,73 +15,25 @@ class Index extends Component
|
||||
|
||||
public array $parameters;
|
||||
public array $query;
|
||||
public Collection $services;
|
||||
protected $listeners = ['serviceStatusUpdated'];
|
||||
protected $rules = [
|
||||
'services.*.fqdn' => 'nullable',
|
||||
'service.docker_compose_raw' => 'required',
|
||||
'service.docker_compose' => 'required',
|
||||
];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->services = collect([]);
|
||||
$this->parameters = get_route_parameters();
|
||||
$this->query = request()->query();
|
||||
$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();
|
||||
foreach ($this->service->applications as $application) {
|
||||
$this->services->put($application->name, [
|
||||
'fqdn' => $application->fqdn,
|
||||
]);
|
||||
}
|
||||
// foreach ($this->service->databases as $database) {
|
||||
// $this->services->put($database->name, $database->fqdn);
|
||||
// }
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.index')->layout('layouts.app');
|
||||
return view('livewire.project.service.index');
|
||||
}
|
||||
public function serviceStatusUpdated() {
|
||||
ray('serviceStatusUpdated');
|
||||
$this->check_status();
|
||||
}
|
||||
public function check_status()
|
||||
{
|
||||
dispatch_sync(new ContainerStatusJob($this->service->server));
|
||||
$this->service->refresh();
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
if ($this->services->count() === 0) {
|
||||
return;
|
||||
}
|
||||
foreach ($this->services as $name => $value) {
|
||||
$foundService = $this->service->applications()->whereName($name)->first();
|
||||
if ($foundService) {
|
||||
$foundService->fqdn = data_get($value, 'fqdn');
|
||||
$foundService->save();
|
||||
return;
|
||||
}
|
||||
$foundService = $this->service->databases()->whereName($name)->first();
|
||||
if ($foundService) {
|
||||
// $foundService->save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
ray($e);
|
||||
} finally {
|
||||
$this->service->parse();
|
||||
}
|
||||
}
|
||||
public function deploy()
|
||||
{
|
||||
public function save() {
|
||||
$this->service->save();
|
||||
$this->service->parse();
|
||||
$activity = StartService::run($this->service);
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
public function stop() {
|
||||
StopService::run($this->service);
|
||||
$this->service->refresh();
|
||||
$this->emit('refreshEnvs');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
43
app/Http/Livewire/Project/Service/Navbar.php
Normal file
43
app/Http/Livewire/Project/Service/Navbar.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Service;
|
||||
|
||||
use App\Actions\Service\StartService;
|
||||
use App\Actions\Service\StopService;
|
||||
use App\Jobs\ContainerStatusJob;
|
||||
use App\Models\Service;
|
||||
use Livewire\Component;
|
||||
|
||||
class Navbar extends Component
|
||||
{
|
||||
public Service $service;
|
||||
public array $parameters;
|
||||
public array $query;
|
||||
protected $listeners = ['serviceStatusUpdated'];
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.navbar');
|
||||
}
|
||||
public function serviceStatusUpdated()
|
||||
{
|
||||
ray('serviceStatusUpdated');
|
||||
$this->check_status();
|
||||
}
|
||||
public function check_status()
|
||||
{
|
||||
dispatch_sync(new ContainerStatusJob($this->service->server));
|
||||
$this->service->refresh();
|
||||
}
|
||||
public function deploy()
|
||||
{
|
||||
$this->service->parse();
|
||||
$activity = StartService::run($this->service);
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
public function stop()
|
||||
{
|
||||
StopService::run($this->service);
|
||||
$this->service->refresh();
|
||||
}
|
||||
}
|
||||
42
app/Http/Livewire/Project/Service/Show.php
Normal file
42
app/Http/Livewire/Project/Service/Show.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Service;
|
||||
|
||||
use App\Models\Service;
|
||||
use App\Models\ServiceApplication;
|
||||
use App\Models\ServiceDatabase;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Component;
|
||||
|
||||
class Show extends Component
|
||||
{
|
||||
public Service $service;
|
||||
public ServiceApplication $serviceApplication;
|
||||
public ServiceDatabase $serviceDatabase;
|
||||
public array $parameters;
|
||||
public array $query;
|
||||
public Collection $services;
|
||||
protected $listeners = ['generateDockerCompose'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->services = collect([]);
|
||||
$this->parameters = get_route_parameters();
|
||||
$this->query = request()->query();
|
||||
$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();
|
||||
$service = $this->service->applications()->whereName($this->parameters['service_name'])->first();
|
||||
if ($service) {
|
||||
$this->serviceApplication = $service;
|
||||
} else {
|
||||
$this->serviceDatabase = $this->service->databases()->whereName($this->parameters['service_name'])->first();
|
||||
}
|
||||
}
|
||||
public function generateDockerCompose()
|
||||
{
|
||||
$this->service->parse();
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.show');
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,24 @@ class Danger extends Component
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$destination = $this->resource->destination->getMorphClass()::where('id', $this->resource->destination->id)->first();
|
||||
|
||||
instant_remote_process(["docker rm -f {$this->resource->uuid}"], $destination->server);
|
||||
$this->resource->delete();
|
||||
return redirect()->route('project.resources', [
|
||||
'project_uuid' => $this->parameters['project_uuid'],
|
||||
'environment_name' => $this->parameters['environment_name']
|
||||
]);
|
||||
try {
|
||||
if ($this->resource->type() === 'service') {
|
||||
$server = $this->resource->server;
|
||||
} else {
|
||||
$destination = data_get($this->resource, 'destination');
|
||||
if ($destination) {
|
||||
$destination = $this->resource->destination->getMorphClass()::where('id', $this->resource->destination->id)->first();
|
||||
$server = $destination->server;
|
||||
}
|
||||
}
|
||||
instant_remote_process(["docker rm -f {$this->resource->uuid}"], $server);
|
||||
$this->resource->delete();
|
||||
return redirect()->route('project.resources', [
|
||||
'project_uuid' => $this->parameters['project_uuid'],
|
||||
'environment_name' => $this->parameters['environment_name']
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ class Add extends Component
|
||||
|
||||
public function submit()
|
||||
{
|
||||
ray('submitting');
|
||||
$this->validate();
|
||||
$this->emitUp('submit', [
|
||||
'key' => $this->key,
|
||||
|
||||
@@ -53,6 +53,7 @@ class All extends Component
|
||||
$this->resource->environment_variables_preview()->delete();
|
||||
} else {
|
||||
$variables = parseEnvFormatToArray($this->variables);
|
||||
ray($variables);
|
||||
$existingVariables = $this->resource->environment_variables();
|
||||
$this->resource->environment_variables()->delete();
|
||||
}
|
||||
@@ -68,11 +69,16 @@ class All extends Component
|
||||
$environment->value = $variable;
|
||||
$environment->is_build_time = false;
|
||||
$environment->is_preview = $isPreview ? true : false;
|
||||
if ($this->resource->type() === 'application') {
|
||||
$environment->application_id = $this->resource->id;
|
||||
}
|
||||
if ($this->resource->type() === 'standalone-postgresql') {
|
||||
$environment->standalone_postgresql_id = $this->resource->id;
|
||||
switch ($this->resource->type()) {
|
||||
case 'application':
|
||||
$environment->application_id = $this->resource->id;
|
||||
break;
|
||||
case 'standalone-postgresql':
|
||||
$environment->standalone_postgresql_id = $this->resource->id;
|
||||
break;
|
||||
case 'service':
|
||||
$environment->service_id = $this->resource->id;
|
||||
break;
|
||||
}
|
||||
$environment->save();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ class Show extends Component
|
||||
{
|
||||
public $parameters;
|
||||
public ModelsEnvironmentVariable $env;
|
||||
public string|null $modalId = null;
|
||||
public ?string $modalId = null;
|
||||
public string $type;
|
||||
|
||||
protected $rules = [
|
||||
'env.key' => 'required|string',
|
||||
'env.value' => 'required|string',
|
||||
@@ -37,6 +39,7 @@ class Show extends Component
|
||||
$this->validate();
|
||||
$this->env->save();
|
||||
$this->emit('success', 'Environment variable updated successfully.');
|
||||
$this->emit('refreshEnvs');
|
||||
}
|
||||
|
||||
public function delete()
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
|
||||
namespace App\Http\Livewire\Project\Shared\Storages;
|
||||
|
||||
use App\Models\LocalPersistentVolume;
|
||||
use Livewire\Component;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
class Show extends Component
|
||||
{
|
||||
public $storage;
|
||||
public string|null $modalId = null;
|
||||
public LocalPersistentVolume $storage;
|
||||
public bool $isReadOnly = false;
|
||||
public ?string $modalId = null;
|
||||
|
||||
protected $rules = [
|
||||
'storage.name' => 'required|string',
|
||||
'storage.mount_path' => 'required|string',
|
||||
|
||||
Reference in New Issue
Block a user