2023-05-24 12:26:50 +00:00
|
|
|
<?php
|
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
namespace App\Livewire\Project\Application\Deployment;
|
2023-05-24 12:26:50 +00:00
|
|
|
|
|
|
|
use App\Models\Application;
|
2023-11-01 14:39:47 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2023-05-24 12:26:50 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
class Index extends Component
|
2023-05-24 12:26:50 +00:00
|
|
|
{
|
2023-06-30 09:42:59 +00:00
|
|
|
public Application $application;
|
2024-01-07 15:23:41 +00:00
|
|
|
public array|Collection $deployments = [];
|
2023-05-31 12:57:42 +00:00
|
|
|
public int $deployments_count = 0;
|
2023-05-24 12:26:50 +00:00
|
|
|
public string $current_url;
|
2023-05-31 12:24:20 +00:00
|
|
|
public int $skip = 0;
|
2023-11-01 14:39:47 +00:00
|
|
|
public int $default_take = 40;
|
2023-06-02 10:34:45 +00:00
|
|
|
public bool $show_next = false;
|
2024-01-29 12:06:26 +00:00
|
|
|
public bool $show_prev = false;
|
2023-11-01 14:39:47 +00:00
|
|
|
public ?string $pull_request_id = null;
|
|
|
|
protected $queryString = ['pull_request_id'];
|
2023-05-24 12:26:50 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2024-01-07 15:23:41 +00:00
|
|
|
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
|
|
|
if (!$project) {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
|
|
|
|
if (!$environment) {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
|
|
|
|
if (!$application) {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
['deployments' => $deployments, 'count' => $count] = $application->deployments(0, 40);
|
|
|
|
$this->application = $application;
|
|
|
|
$this->deployments = $deployments;
|
|
|
|
$this->deployments_count = $count;
|
2023-05-24 12:26:50 +00:00
|
|
|
$this->current_url = url()->current();
|
2023-11-01 14:39:47 +00:00
|
|
|
$this->show_pull_request_only();
|
2023-06-30 09:42:59 +00:00
|
|
|
$this->show_more();
|
|
|
|
}
|
2024-01-07 15:23:41 +00:00
|
|
|
private function show_pull_request_only()
|
|
|
|
{
|
2023-11-01 14:39:47 +00:00
|
|
|
if ($this->pull_request_id) {
|
|
|
|
$this->deployments = $this->deployments->where('pull_request_id', $this->pull_request_id);
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 09:42:59 +00: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 12:26:50 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-31 12:24:20 +00:00
|
|
|
public function reload_deployments()
|
2023-05-24 12:26:50 +00:00
|
|
|
{
|
2023-05-31 12:24:20 +00:00
|
|
|
$this->load_deployments();
|
2023-05-24 12:26:50 +00:00
|
|
|
}
|
2024-01-29 12:06:26 +00:00
|
|
|
public function previous_page(?int $take = null)
|
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-01-29 12:06:26 +00:00
|
|
|
if ($take) {
|
|
|
|
$this->skip = $this->skip - $take;
|
|
|
|
}
|
|
|
|
$this->skip = $this->skip - $this->default_take;
|
|
|
|
if ($this->skip < 0) {
|
|
|
|
$this->show_prev = false;
|
|
|
|
$this->skip = 0;
|
|
|
|
}
|
|
|
|
$this->load_deployments();
|
|
|
|
}
|
|
|
|
public function next_page(?int $take = null)
|
2023-05-24 12:26:50 +00:00
|
|
|
{
|
2023-05-31 12:24:20 +00:00
|
|
|
if ($take) {
|
|
|
|
$this->skip = $this->skip + $take;
|
|
|
|
}
|
2024-01-29 12:06:26 +00:00
|
|
|
$this->show_prev = true;
|
|
|
|
$this->load_deployments();
|
|
|
|
}
|
|
|
|
public function load_deployments()
|
|
|
|
{
|
|
|
|
['deployments' => $deployments, 'count' => $count] = $this->application->deployments($this->skip, $this->default_take);
|
2023-05-31 12:57:42 +00:00
|
|
|
$this->deployments = $deployments;
|
|
|
|
$this->deployments_count = $count;
|
2023-11-01 14:39:47 +00:00
|
|
|
$this->show_pull_request_only();
|
2023-06-30 09:42:59 +00:00
|
|
|
$this->show_more();
|
2023-05-24 12:26:50 +00:00
|
|
|
}
|
2024-01-07 15:23:41 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.application.deployment.index');
|
|
|
|
}
|
2023-05-24 12:26:50 +00:00
|
|
|
}
|