feat(deployment): add pull request filtering and pagination to deployment and backup execution components
fix(ui): make them more stylish yeah
This commit is contained in:
@@ -18,11 +18,13 @@ class Index extends Component
|
||||
|
||||
public int $skip = 0;
|
||||
|
||||
public int $default_take = 10;
|
||||
public int $defaultTake = 10;
|
||||
|
||||
public bool $show_next = false;
|
||||
public bool $showNext = false;
|
||||
|
||||
public bool $show_prev = false;
|
||||
public bool $showPrev = false;
|
||||
|
||||
public int $currentPage = 1;
|
||||
|
||||
public ?string $pull_request_id = null;
|
||||
|
||||
@@ -51,68 +53,111 @@ class Index extends Component
|
||||
if (! $application) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
['deployments' => $deployments, 'count' => $count] = $application->deployments(0, $this->default_take);
|
||||
// Validate pull request ID from URL parameters
|
||||
if ($this->pull_request_id !== null && $this->pull_request_id !== '') {
|
||||
if (! is_numeric($this->pull_request_id) || (float) $this->pull_request_id <= 0 || (float) $this->pull_request_id != (int) $this->pull_request_id) {
|
||||
$this->pull_request_id = null;
|
||||
$this->dispatch('error', 'Invalid Pull Request ID in URL. Filter cleared.');
|
||||
} else {
|
||||
// Ensure it's stored as a string representation of a positive integer
|
||||
$this->pull_request_id = (string) (int) $this->pull_request_id;
|
||||
}
|
||||
}
|
||||
|
||||
['deployments' => $deployments, 'count' => $count] = $application->deployments(0, $this->defaultTake, $this->pull_request_id);
|
||||
$this->application = $application;
|
||||
$this->deployments = $deployments;
|
||||
$this->deployments_count = $count;
|
||||
$this->current_url = url()->current();
|
||||
$this->show_pull_request_only();
|
||||
$this->show_more();
|
||||
$this->updateCurrentPage();
|
||||
$this->showMore();
|
||||
}
|
||||
|
||||
private function show_pull_request_only()
|
||||
{
|
||||
if ($this->pull_request_id) {
|
||||
$this->deployments = $this->deployments->where('pull_request_id', $this->pull_request_id);
|
||||
}
|
||||
}
|
||||
|
||||
private function show_more()
|
||||
private function showMore()
|
||||
{
|
||||
if ($this->deployments->count() !== 0) {
|
||||
$this->show_next = true;
|
||||
if ($this->deployments->count() < $this->default_take) {
|
||||
$this->show_next = false;
|
||||
$this->showNext = true;
|
||||
if ($this->deployments->count() < $this->defaultTake) {
|
||||
$this->showNext = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function reload_deployments()
|
||||
public function reloadDeployments()
|
||||
{
|
||||
$this->load_deployments();
|
||||
$this->loadDeployments();
|
||||
}
|
||||
|
||||
public function previous_page(?int $take = null)
|
||||
public function previousPage(?int $take = null)
|
||||
{
|
||||
if ($take) {
|
||||
$this->skip = $this->skip - $take;
|
||||
}
|
||||
$this->skip = $this->skip - $this->default_take;
|
||||
$this->skip = $this->skip - $this->defaultTake;
|
||||
if ($this->skip < 0) {
|
||||
$this->show_prev = false;
|
||||
$this->showPrev = false;
|
||||
$this->skip = 0;
|
||||
}
|
||||
$this->load_deployments();
|
||||
$this->updateCurrentPage();
|
||||
$this->loadDeployments();
|
||||
}
|
||||
|
||||
public function next_page(?int $take = null)
|
||||
public function nextPage(?int $take = null)
|
||||
{
|
||||
if ($take) {
|
||||
$this->skip = $this->skip + $take;
|
||||
}
|
||||
$this->show_prev = true;
|
||||
$this->load_deployments();
|
||||
$this->showPrev = true;
|
||||
$this->updateCurrentPage();
|
||||
$this->loadDeployments();
|
||||
}
|
||||
|
||||
public function load_deployments()
|
||||
public function loadDeployments()
|
||||
{
|
||||
['deployments' => $deployments, 'count' => $count] = $this->application->deployments($this->skip, $this->default_take);
|
||||
['deployments' => $deployments, 'count' => $count] = $this->application->deployments($this->skip, $this->defaultTake, $this->pull_request_id);
|
||||
$this->deployments = $deployments;
|
||||
$this->deployments_count = $count;
|
||||
$this->show_pull_request_only();
|
||||
$this->show_more();
|
||||
$this->showMore();
|
||||
}
|
||||
|
||||
public function updatedPullRequestId($value)
|
||||
{
|
||||
// Sanitize and validate the pull request ID
|
||||
if ($value !== null && $value !== '') {
|
||||
// Check if it's numeric and positive
|
||||
if (! is_numeric($value) || (float) $value <= 0 || (float) $value != (int) $value) {
|
||||
$this->pull_request_id = null;
|
||||
$this->dispatch('error', 'Invalid Pull Request ID. Please enter a valid positive number.');
|
||||
|
||||
return;
|
||||
}
|
||||
// Ensure it's stored as a string representation of a positive integer
|
||||
$this->pull_request_id = (string) (int) $value;
|
||||
} else {
|
||||
$this->pull_request_id = null;
|
||||
}
|
||||
|
||||
// Reset pagination when filter changes
|
||||
$this->skip = 0;
|
||||
$this->showPrev = false;
|
||||
$this->updateCurrentPage();
|
||||
$this->loadDeployments();
|
||||
}
|
||||
|
||||
public function clearFilter()
|
||||
{
|
||||
$this->pull_request_id = null;
|
||||
$this->skip = 0;
|
||||
$this->showPrev = false;
|
||||
$this->updateCurrentPage();
|
||||
$this->loadDeployments();
|
||||
}
|
||||
|
||||
private function updateCurrentPage()
|
||||
{
|
||||
$this->currentPage = intval($this->skip / $this->defaultTake) + 1;
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Livewire\Project\Database;
|
||||
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\ScheduledDatabaseBackup;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Component;
|
||||
@@ -14,7 +15,19 @@ class BackupExecutions extends Component
|
||||
|
||||
public $database;
|
||||
|
||||
public $executions = [];
|
||||
public ?Collection $executions;
|
||||
|
||||
public int $executions_count = 0;
|
||||
|
||||
public int $skip = 0;
|
||||
|
||||
public int $defaultTake = 10;
|
||||
|
||||
public bool $showNext = false;
|
||||
|
||||
public bool $showPrev = false;
|
||||
|
||||
public int $currentPage = 1;
|
||||
|
||||
public $setDeletableBackup;
|
||||
|
||||
@@ -40,6 +53,20 @@ class BackupExecutions extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function cleanupDeleted()
|
||||
{
|
||||
if ($this->backup) {
|
||||
$deletedCount = $this->backup->executions()->where('local_storage_deleted', true)->count();
|
||||
if ($deletedCount > 0) {
|
||||
$this->backup->executions()->where('local_storage_deleted', true)->delete();
|
||||
$this->refreshBackupExecutions();
|
||||
$this->dispatch('success', "Cleaned up {$deletedCount} backup entries deleted from local storage.");
|
||||
} else {
|
||||
$this->dispatch('info', 'No backup entries found that are deleted from local storage.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteBackup($executionId, $password)
|
||||
{
|
||||
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
|
||||
@@ -85,18 +112,74 @@ class BackupExecutions extends Component
|
||||
|
||||
public function refreshBackupExecutions(): void
|
||||
{
|
||||
if ($this->backup && $this->backup->exists) {
|
||||
$this->executions = $this->backup->executions()->get()->toArray();
|
||||
} else {
|
||||
$this->executions = [];
|
||||
$this->loadExecutions();
|
||||
}
|
||||
|
||||
public function reloadExecutions()
|
||||
{
|
||||
$this->loadExecutions();
|
||||
}
|
||||
|
||||
public function previousPage(?int $take = null)
|
||||
{
|
||||
if ($take) {
|
||||
$this->skip = $this->skip - $take;
|
||||
}
|
||||
$this->skip = $this->skip - $this->defaultTake;
|
||||
if ($this->skip < 0) {
|
||||
$this->showPrev = false;
|
||||
$this->skip = 0;
|
||||
}
|
||||
$this->updateCurrentPage();
|
||||
$this->loadExecutions();
|
||||
}
|
||||
|
||||
public function nextPage(?int $take = null)
|
||||
{
|
||||
if ($take) {
|
||||
$this->skip = $this->skip + $take;
|
||||
}
|
||||
$this->showPrev = true;
|
||||
$this->updateCurrentPage();
|
||||
$this->loadExecutions();
|
||||
}
|
||||
|
||||
private function loadExecutions()
|
||||
{
|
||||
if ($this->backup && $this->backup->exists) {
|
||||
['executions' => $executions, 'count' => $count] = $this->backup->executionsPaginated($this->skip, $this->defaultTake);
|
||||
$this->executions = $executions;
|
||||
$this->executions_count = $count;
|
||||
} else {
|
||||
$this->executions = collect([]);
|
||||
$this->executions_count = 0;
|
||||
}
|
||||
$this->showMore();
|
||||
}
|
||||
|
||||
private function showMore()
|
||||
{
|
||||
if ($this->executions->count() !== 0) {
|
||||
$this->showNext = true;
|
||||
if ($this->executions->count() < $this->defaultTake) {
|
||||
$this->showNext = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private function updateCurrentPage()
|
||||
{
|
||||
$this->currentPage = intval($this->skip / $this->defaultTake) + 1;
|
||||
}
|
||||
|
||||
public function mount(ScheduledDatabaseBackup $backup)
|
||||
{
|
||||
$this->backup = $backup;
|
||||
$this->database = $backup->database;
|
||||
$this->refreshBackupExecutions();
|
||||
$this->updateCurrentPage();
|
||||
$this->loadExecutions();
|
||||
}
|
||||
|
||||
public function server()
|
||||
|
||||
@@ -836,9 +836,14 @@ class Application extends BaseModel
|
||||
return ApplicationDeploymentQueue::where('application_id', $this->id)->where('created_at', '>=', now()->subDays(7))->orderBy('created_at', 'desc')->get();
|
||||
}
|
||||
|
||||
public function deployments(int $skip = 0, int $take = 10)
|
||||
public function deployments(int $skip = 0, int $take = 10, ?string $pullRequestId = null)
|
||||
{
|
||||
$deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->orderBy('created_at', 'desc');
|
||||
|
||||
if ($pullRequestId) {
|
||||
$deployments = $deployments->where('pull_request_id', $pullRequestId);
|
||||
}
|
||||
|
||||
$count = $deployments->count();
|
||||
$deployments = $deployments->skip($skip)->take($take)->get();
|
||||
|
||||
|
||||
@@ -36,6 +36,18 @@ class ScheduledDatabaseBackup extends BaseModel
|
||||
return $this->hasMany(ScheduledDatabaseBackupExecution::class)->where('created_at', '>=', now()->subDays($days))->get();
|
||||
}
|
||||
|
||||
public function executionsPaginated(int $skip = 0, int $take = 10)
|
||||
{
|
||||
$executions = $this->hasMany(ScheduledDatabaseBackupExecution::class)->orderBy('created_at', 'desc');
|
||||
$count = $executions->count();
|
||||
$executions = $executions->skip($skip)->take($take)->get();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'executions' => $executions,
|
||||
];
|
||||
}
|
||||
|
||||
public function server()
|
||||
{
|
||||
if ($this->database) {
|
||||
|
||||
Reference in New Issue
Block a user