diff --git a/app/Livewire/Tags/Index.php b/app/Livewire/Tags/Index.php deleted file mode 100644 index 116f19e4e..000000000 --- a/app/Livewire/Tags/Index.php +++ /dev/null @@ -1,82 +0,0 @@ - '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); - } - } -} diff --git a/app/Livewire/Tags/Show.php b/app/Livewire/Tags/Show.php index 0dffcce57..fc5b13374 100644 --- a/app/Livewire/Tags/Show.php +++ b/app/Livewire/Tags/Show.php @@ -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([]); diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index ae98f85cb..8a2f4d5d6 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -215,7 +215,7 @@
  • + href="{{ route('tags.show') }}"> diff --git a/resources/views/livewire/tags/index.blade.php b/resources/views/livewire/tags/index.blade.php deleted file mode 100644 index 3a98519a7..000000000 --- a/resources/views/livewire/tags/index.blade.php +++ /dev/null @@ -1,64 +0,0 @@ -
    -

    Tags

    -
    -
    diff --git a/resources/views/livewire/tags/show.blade.php b/resources/views/livewire/tags/show.blade.php index f135a8246..9127278ef 100644 --- a/resources/views/livewire/tags/show.blade.php +++ b/resources/views/livewire/tags/show.blade.php @@ -1,87 +1,96 @@
    -
    +

    Tags

    +
    Tags help you to perform actions on multiple resources.
    -
    -
    Available tags
    -
    - @forelse ($tags as $oneTag) - {{ $oneTag->name }} - @empty -
    No tags yet defined yet. Go to a resource and add a tag there.
    - @endforelse -
    +
    + @forelse ($tags as $oneTag) + {{ $oneTag->name }} + @empty +
    No tags yet defined yet. Go to a resource and add a tag there.
    + @endforelse
    -
    -

    Details

    -
    -
    - + @if (isset($tag)) +
    +

    Details

    +
    +
    + +
    +
    - -
    - -
    -

    Deployments

    - @if (count($deployments_per_tag_per_server) > 0) - - @endif -
    -
    - @forelse ($deployments_per_tag_per_server as $server_name => $deployments) -

    {{ $server_name }}

    - + @endif
    diff --git a/routes/web.php b/routes/web.php index 6ea3bc857..0a7cbaf7e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -127,8 +127,8 @@ Route::middleware(['auth', 'verified'])->group(function () { Route::get('/profile', ProfileIndex::class)->name('profile'); Route::prefix('tags')->group(function () { - Route::get('/', TagsIndex::class)->name('tags.index'); - Route::get('/{tag_name}', TagsShow::class)->name('tags.show'); + // Route::get('/', TagsIndex::class)->name('tags.index'); + Route::get('/{tagName?}', TagsShow::class)->name('tags.show'); }); Route::prefix('notifications')->group(function () {