From 85f38b7cb5fd083e08ce91e197c9999bda20d0f1 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:35:20 +0100 Subject: [PATCH] refactor: improve data formatting and UI - move date and duration functions to a shared function - remove duplicate code - redesigned the deployment executions tab - added start and end times for backups, scheduled tasks, deployments and docker cleanup executions - calculated the duration for backups, scheduled tasks, deployments and Docker cleanup executions - redesigned status badges with colors to make it easier to see your current status - removed dependency on dayjs - fixed calculation of execution time was sometimes incorrect --- .../Project/Database/BackupExecutions.php | 23 --- .../Shared/ScheduledTask/Executions.php | 13 -- bootstrap/helpers/timezone.php | 42 +++++ .../application/deployment/index.blade.php | 155 +++++++----------- .../database/backup-executions.blade.php | 36 +++- .../scheduled-task/executions.blade.php | 38 +++-- 6 files changed, 154 insertions(+), 153 deletions(-) create mode 100644 bootstrap/helpers/timezone.php diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php index 7eef1a539..3fc721fda 100644 --- a/app/Livewire/Project/Database/BackupExecutions.php +++ b/app/Livewire/Project/Database/BackupExecutions.php @@ -117,29 +117,6 @@ class BackupExecutions extends Component return null; } - public function getServerTimezone() - { - $server = $this->server(); - if (! $server) { - return 'UTC'; - } - - return $server->settings->server_timezone; - } - - public function formatDateInServerTimezone($date) - { - $serverTimezone = $this->getServerTimezone(); - $dateObj = new \DateTime($date); - try { - $dateObj->setTimezone(new \DateTimeZone($serverTimezone)); - } catch (\Exception) { - $dateObj->setTimezone(new \DateTimeZone('UTC')); - } - - return $dateObj->format('Y-m-d H:i:s T'); - } - public function render() { return view('livewire.project.database.backup-executions', [ diff --git a/app/Livewire/Project/Shared/ScheduledTask/Executions.php b/app/Livewire/Project/Shared/ScheduledTask/Executions.php index 74eac7132..6f62a5b5b 100644 --- a/app/Livewire/Project/Shared/ScheduledTask/Executions.php +++ b/app/Livewire/Project/Shared/ScheduledTask/Executions.php @@ -141,17 +141,4 @@ class Executions extends Component return $lines->count() > ($this->currentPage * $this->logsPerPage); } - - public function formatDateInServerTimezone($date) - { - $serverTimezone = $this->serverTimezone; - $dateObj = new \DateTime($date); - try { - $dateObj->setTimezone(new \DateTimeZone($serverTimezone)); - } catch (\Exception) { - $dateObj->setTimezone(new \DateTimeZone('UTC')); - } - - return $dateObj->format('Y-m-d H:i:s T'); - } } diff --git a/bootstrap/helpers/timezone.php b/bootstrap/helpers/timezone.php new file mode 100644 index 000000000..96d9ba6cf --- /dev/null +++ b/bootstrap/helpers/timezone.php @@ -0,0 +1,42 @@ +setTimezone(new \DateTimeZone($serverTimezone)); + } catch (\Exception) { + $dateObj->setTimezone(new \DateTimeZone('UTC')); + } + + return $dateObj->format('Y-m-d H:i:s T'); +} + +function calculateDuration($startDate, $endDate = null) +{ + if (! $endDate) { + return null; + } + + $start = new \DateTime($startDate); + $end = new \DateTime($endDate); + $interval = $start->diff($end); + + if ($interval->days > 0) { + return $interval->format('%dd %Hh %Im %Ss'); + } elseif ($interval->h > 0) { + return $interval->format('%Hh %Im %Ss'); + } else { + return $interval->format('%Im %Ss'); + } +} diff --git a/resources/views/livewire/project/application/deployment/index.blade.php b/resources/views/livewire/project/application/deployment/index.blade.php index 3fa52b7f3..0555f90d7 100644 --- a/resources/views/livewire/project/application/deployment/index.blade.php +++ b/resources/views/livewire/project/application/deployment/index.blade.php @@ -32,135 +32,96 @@ @forelse ($deployments as $deployment)