Refactor code and update UI components

This commit is contained in:
Andras Bacsai
2024-03-22 11:34:15 +01:00
parent ca9a2cb13a
commit 8b7e1e4169
51 changed files with 592 additions and 609 deletions

View File

@@ -13,6 +13,7 @@ class ActivityMonitor extends Component
public $activityId;
public $eventToDispatch = 'activityFinished';
public $isPollingActive = false;
public bool $showWaiting = false;
protected $activity;
protected $listeners = ['activityMonitor' => 'newMonitorActivity'];

View File

@@ -5,7 +5,7 @@ namespace App\Livewire\Destination\New;
use App\Models\Server;
use App\Models\StandaloneDocker as ModelsStandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
@@ -14,7 +14,7 @@ class Docker extends Component
public string $name;
public string $network;
public Collection $servers;
public ?Collection $servers = null;
public Server $server;
public ?int $server_id = null;
public bool $is_swarm = false;
@@ -34,6 +34,9 @@ class Docker extends Component
public function mount()
{
if (is_null($this->servers)) {
$this->servers = Server::ownedByCurrentTeam()->get();
}
if (request()->query('server_id')) {
$this->server_id = request()->query('server_id');
} else {

View File

@@ -3,6 +3,8 @@
namespace App\Livewire\Destination;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Support\Collection;
use Livewire\Component;
@@ -11,6 +13,40 @@ class Show extends Component
public Server $server;
public Collection|array $networks = [];
private function createNetworkAndAttachToProxy()
{
$connectProxyToDockerNetworks = connectProxyToNetworks($this->server);
instant_remote_process($connectProxyToDockerNetworks, $this->server, false);
}
public function add($name)
{
if ($this->server->isSwarm()) {
$found = $this->server->swarmDockers()->where('network', $name)->first();
if ($found) {
$this->dispatch('error', 'Network already added to this server.');
return;
} else {
$docker = SwarmDocker::create([
'name' => $this->server->name . "-" . $name,
'network' => $this->name,
'server_id' => $this->server->id,
]);
}
} else {
$found = $this->server->standaloneDockers()->where('network', $name)->first();
if ($found) {
$this->dispatch('error', 'Network already added to this server.');
return;
} else {
$docker = StandaloneDocker::create([
'name' => $this->server->name . "-" . $name,
'network' => $name,
'server_id' => $this->server->id,
]);
}
$this->createNetworkAndAttachToProxy();
}
}
public function scan()
{
if ($this->server->isSwarm()) {
@@ -26,6 +62,8 @@ class Show extends Component
});
if ($this->networks->count() === 0) {
$this->dispatch('success', 'No new networks found.');
return;
}
$this->dispatch('success', 'Scan done.');
}
}

View File

@@ -17,14 +17,6 @@ class LayoutPopups extends Component
{
$this->dispatch('success', 'Realtime events configured!');
}
public function disableSponsorship()
{
auth()->user()->update(['is_notification_sponsorship_enabled' => false]);
}
public function disableNotifications()
{
auth()->user()->update(['is_notification_notifications_enabled' => false]);
}
public function render()
{
return view('livewire.layout-popups');

View File

@@ -2,6 +2,7 @@
namespace App\Livewire\Project;
use App\Models\PrivateKey;
use App\Models\Project;
use App\Models\Server;
use Livewire\Component;
@@ -10,7 +11,9 @@ class Index extends Component
{
public $projects;
public $servers;
public $private_keys;
public function mount() {
$this->private_keys = PrivateKey::ownedByCurrentTeam()->get();
$this->projects = Project::ownedByCurrentTeam()->get();
$this->servers = Server::ownedByCurrentTeam()->count();
}

View File

@@ -26,7 +26,7 @@ class Navbar extends Component
];
}
public function serviceStarted() {
$this->dispatch('success', 'Service started.');
$this->dispatch('success', 'Service status changed.');
}
public function serviceStatusChanged()
{

View File

@@ -59,7 +59,7 @@ class ServiceApplicationView extends Component
$this->validate();
$this->application->save();
updateCompose($this->application);
$this->dispatch('success', 'Application saved.');
$this->dispatch('success', 'Service saved.');
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {

View File

@@ -53,7 +53,7 @@ class ByIp extends Component
public function mount()
{
$this->name = generate_random_name();
$this->private_key_id = $this->private_keys->first()->id;
$this->private_key_id = $this->private_keys->first()?->id;
$this->swarm_managers = Server::isUsable()->get()->where('settings.is_swarm_manager', true);
if ($this->swarm_managers->count() > 0) {
$this->selected_swarm_cluster = $this->swarm_managers->first()->id;

View File

@@ -30,7 +30,7 @@ class License extends Component
}
public function render()
{
return view('livewire.settings.license')->layout('layouts.subscription');
return view('livewire.settings.license');
}
public function submit()
{

View File

@@ -177,9 +177,6 @@ class Team extends Model implements SendsDiscord, SendsEmail
if (isCloud()) {
return true;
}
if (!data_get(auth()->user(), 'is_notification_notifications_enabled')) {
return true;
}
if ($this->smtp_enabled || $this->resend_enabled || $this->discord_enabled || $this->telegram_enabled || $this->use_instance_email_settings) {
return true;
}

View File

@@ -13,7 +13,6 @@ class Button extends Component
*/
public function __construct(
public bool $disabled = false,
public bool $isModal = false,
public bool $noStyle = false,
public ?string $modalId = null,
public string $defaultClass = "button"