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

61 lines
1.7 KiB
PHP
Raw Normal View History

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