coolify/app/Http/Livewire/Project/Application/Deployments.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2023-05-24 14:26:50 +02:00
<?php
namespace App\Http\Livewire\Project\Application;
use App\Models\Application;
use Illuminate\Support\Collection;
2023-05-24 14:26:50 +02:00
use Livewire\Component;
class Deployments extends Component
{
2023-06-30 11:42:59 +02:00
public Application $application;
public Array|Collection $deployments = [];
2023-05-31 14:57:42 +02:00
public int $deployments_count = 0;
2023-05-24 14:26:50 +02:00
public string $current_url;
2023-05-31 14:24:20 +02:00
public int $skip = 0;
public int $default_take = 40;
2023-06-02 12:34:45 +02:00
public bool $show_next = false;
public ?string $pull_request_id = null;
protected $queryString = ['pull_request_id'];
2023-05-24 14:26:50 +02:00
public function mount()
{
$this->current_url = url()->current();
$this->show_pull_request_only();
2023-06-30 11:42:59 +02:00
$this->show_more();
}
private function show_pull_request_only() {
if ($this->pull_request_id) {
$this->deployments = $this->deployments->where('pull_request_id', $this->pull_request_id);
}
}
2023-06-30 11:42:59 +02:00
private function show_more()
{
if (count($this->deployments) !== 0) {
$this->show_next = true;
if (count($this->deployments) < $this->default_take) {
$this->show_next = false;
}
return;
}
2023-05-24 14:26:50 +02:00
}
2023-05-31 14:24:20 +02:00
public function reload_deployments()
2023-05-24 14:26:50 +02:00
{
2023-05-31 14:24:20 +02:00
$this->load_deployments();
2023-05-24 14:26:50 +02:00
}
2023-05-31 14:24:20 +02:00
public function load_deployments(int|null $take = null)
2023-05-24 14:26:50 +02:00
{
2023-05-31 14:24:20 +02:00
if ($take) {
$this->skip = $this->skip + $take;
}
$take = $this->default_take;
2023-06-30 11:42:59 +02:00
['deployments' => $deployments, 'count' => $count] = $this->application->deployments($this->skip, $take);
2023-05-31 14:57:42 +02:00
$this->deployments = $deployments;
$this->deployments_count = $count;
$this->show_pull_request_only();
2023-06-30 11:42:59 +02:00
$this->show_more();
2023-05-24 14:26:50 +02:00
}
}