fix: refactor tags view / remove obsolete one

This commit is contained in:
Andras Bacsai
2024-11-05 10:11:15 +01:00
parent 9b578b2003
commit ae7d88df9f
6 changed files with 118 additions and 241 deletions

View File

@@ -1,82 +0,0 @@
<?php
namespace App\Livewire\Tags;
use App\Http\Controllers\Api\DeployController;
use App\Models\Tag;
use Illuminate\Support\Collection;
use Livewire\Attributes\Title;
use Livewire\Attributes\Url;
use Livewire\Component;
#[Title('Tags | Coolify')]
class Index extends Component
{
#[Url()]
public ?string $tag = null;
public Collection $tags;
public Collection $applications;
public Collection $services;
public $webhook = null;
public $deploymentsPerTagPerServer = [];
protected $listeners = ['deployments' => 'updateDeployments'];
public function render()
{
return view('livewire.tags.index');
}
public function mount()
{
$this->tags = Tag::ownedByCurrentTeam()->get()->unique('name')->sortBy('name');
if ($this->tag) {
$this->tagUpdated();
}
}
public function updateDeployments($deployments)
{
$this->deploymentsPerTagPerServer = $deployments;
}
public function tagUpdated()
{
if ($this->tag === '') {
return;
}
$sanitizedTag = htmlspecialchars($this->tag, ENT_QUOTES, 'UTF-8');
$tag = $this->tags->where('name', $sanitizedTag)->first();
if (! $tag) {
$this->dispatch('error', 'Tag ('.e($sanitizedTag).') not found.');
$this->tag = '';
return;
}
$this->webhook = generateTagDeployWebhook($tag->name);
$this->applications = $tag->applications()->get();
$this->services = $tag->services()->get();
}
public function redeployAll()
{
try {
$this->applications->each(function ($resource) {
$deploy = new DeployController;
$deploy->deploy_resource($resource);
});
$this->services->each(function ($resource) {
$deploy = new DeployController;
$deploy->deploy_resource($resource);
});
$this->dispatch('success', 'Mass deployment started.');
} catch (\Exception $e) {
return handleError($e, $this);
}
}
}

View File

@@ -5,43 +5,57 @@ namespace App\Livewire\Tags;
use App\Http\Controllers\Api\DeployController;
use App\Models\ApplicationDeploymentQueue;
use App\Models\Tag;
use Illuminate\Support\Collection;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Title('Tags | Coolify')]
class Show extends Component
{
public $tags;
#[Locked]
public ?string $tagName = null;
public Tag $tag;
#[Locked]
public ?Collection $tags = null;
public $applications;
#[Locked]
public ?Tag $tag = null;
public $services;
#[Locked]
public ?Collection $applications = null;
public $webhook = null;
#[Locked]
public ?Collection $services = null;
public $deployments_per_tag_per_server = [];
#[Locked]
public ?string $webhook = null;
#[Locked]
public ?array $deploymentsPerTagPerServer = null;
public function mount()
{
$this->tags = Tag::ownedByCurrentTeam()->get()->unique('name')->sortBy('name');
$tag = $this->tags->where('name', request()->tag_name)->first();
if (! $tag) {
return redirect()->route('tags.index');
try {
$this->tags = Tag::ownedByCurrentTeam()->get()->unique('name')->sortBy('name');
if (str($this->tagName)->isNotEmpty()) {
$tag = $this->tags->where('name', $this->tagName)->first();
$this->webhook = generateTagDeployWebhook($tag->name);
$this->applications = $tag->applications()->get();
$this->services = $tag->services()->get();
$this->tag = $tag;
$this->getDeployments();
}
} catch (\Exception $e) {
return handleError($e, $this);
}
$this->webhook = generateTagDeployWebhook($tag->name);
$this->applications = $tag->applications()->get();
$this->services = $tag->services()->get();
$this->tag = $tag;
$this->get_deployments();
}
public function get_deployments()
public function getDeployments()
{
try {
$resource_ids = $this->applications->pluck('id');
$this->deployments_per_tag_per_server = ApplicationDeploymentQueue::whereIn('status', ['in_progress', 'queued'])->whereIn('application_id', $resource_ids)->get([
$this->deploymentsPerTagPerServer = ApplicationDeploymentQueue::whereIn('status', ['in_progress', 'queued'])->whereIn('application_id', $resource_ids)->get([
'id',
'application_id',
'application_name',
@@ -56,7 +70,7 @@ class Show extends Component
}
}
public function redeploy_all()
public function redeployAll()
{
try {
$message = collect([]);