From 2067f67791c8e1bd6a982028123afee323ecb904 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Tue, 8 Aug 2023 21:10:26 +0200 Subject: [PATCH 1/4] Fixed reactivating servers --- app/Http/Livewire/Server/ServerCard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Livewire/Server/ServerCard.php b/app/Http/Livewire/Server/ServerCard.php index 582b92c30..d159e60f8 100644 --- a/app/Http/Livewire/Server/ServerCard.php +++ b/app/Http/Livewire/Server/ServerCard.php @@ -17,7 +17,7 @@ public function mount(Server $server) public function reactivate() { - Artisan::call('ping:server '.$this->server->uuid.' true'); + Artisan::call('server:ping '.$this->server->uuid.' true'); $this->server->active = true; $this->server->save(); $this->emit('serverUpdated'); From f8d598e058102bfb77c4c36a24fbad628396cfb9 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Tue, 8 Aug 2023 21:13:29 +0200 Subject: [PATCH 2/4] Refactor server list --- app/Http/Livewire/Server/ServerCardList.php | 31 ++- .../server/server-card-list.blade.php | 17 +- .../livewire/server/server-card.blade.php | 238 +++++++++--------- 3 files changed, 153 insertions(+), 133 deletions(-) diff --git a/app/Http/Livewire/Server/ServerCardList.php b/app/Http/Livewire/Server/ServerCardList.php index b2a01e934..91b15291e 100644 --- a/app/Http/Livewire/Server/ServerCardList.php +++ b/app/Http/Livewire/Server/ServerCardList.php @@ -8,6 +8,8 @@ class ServerCardList extends Component { public $servers; + public $my_servers; + public $user; protected $listeners = [ 'serverUpdated' => 'update', @@ -15,22 +17,35 @@ class ServerCardList extends Component public function mount() { - $this->servers = Server::orderBy('official', 'desc') - ->orderBy('last_online_at', 'desc') - ->orderBy('ping', 'asc') - ->get(); + $this->loadData(); } public function update() { - $this->servers = Server::orderBy('official', 'desc') - ->orderBy('last_online_at', 'desc') - ->orderBy('ping', 'asc') - ->get(); + $this->loadData(); } public function render() { return view('livewire.server.server-card-list'); } + + /** + * @return void + */ + private function loadData(): void + { + $this->user = auth()->user() ?? null; + $this->servers = isset($this->user) ? Server::where('user_id', '!=', $this->user->id) + ->where('active', true) + ->orderBy('official', 'desc') + ->orderBy('last_online_at', 'desc') + ->orderBy('ping', 'asc') + ->get() : Server::orderBy('official', 'desc') + ->where('active', true) + ->orderBy('last_online_at', 'desc') + ->orderBy('ping', 'asc') + ->get(); + $this->my_servers = $this->user->id ? Server::where('user_id', $this->user->id)->get() : []; + } } diff --git a/resources/views/livewire/server/server-card-list.blade.php b/resources/views/livewire/server/server-card-list.blade.php index abca12ac9..393998dfc 100644 --- a/resources/views/livewire/server/server-card-list.blade.php +++ b/resources/views/livewire/server/server-card-list.blade.php @@ -1,10 +1,17 @@
-
-

{{ __('All server statuses are updated every hour.') }}

-
- @foreach ($this->servers as $server) +

{{ __('All server statuses are updated every hour.') }}

+ @if($this->my_servers->count() > 0) +

{{ __('Your servers') }}:

+
+ @foreach($this->my_servers as $server) @livewire('server.server-card', ['server' => $server]) @endforeach
+
+ @endif +
+ @foreach($this->servers as $server) + @livewire('server.server-card', ['server' => $server]) + @endforeach
-
\ No newline at end of file +
diff --git a/resources/views/livewire/server/server-card.blade.php b/resources/views/livewire/server/server-card.blade.php index 3ee5a4354..c41028e25 100644 --- a/resources/views/livewire/server/server-card.blade.php +++ b/resources/views/livewire/server/server-card.blade.php @@ -1,91 +1,104 @@
- @if($this->server->active) -
-
- @auth - @if(auth()->user()->id == $this->server->user_id) -
- -
- @if(!$this->server->active) - - @endif - - - - - @lang('Edit') - - +
+ @if(!$this->server->active) + -
+ @endif + + + + + @lang('Edit') + +
- @endif - @endauth -
+
+ @endif + @endauth +
-

{{ $this->server->name }}

- @if($this->server->official) -
- Official -
-
- {{ __('This means that the server is maintained by the P3D team') }} -
- - - +

{{ $this->server->name }}

+ @if($this->server->official) +
+ {{ __('Official') }} +
+
+ {{ __('This means that the server is maintained by the P3D team') }}
+ + +
- @endif - @if($this->server->created_at > now()->subDays(7)) -
- New -
-
- {{ __('This server was added in the last seven days') }} -
- - - +
+ @endif + @if($this->server->created_at > now()->subDays(7)) +
+ {{ __('New') }} +
+
+ {{ __('This server was added in the last seven days') }}
+ + +
- @endif - @if($this->server->ping) -
- {{ $this->server->ping }} -
-
- {{ __('The ping relative to the server from this website') }} -
- - - +
+ @endif + @if($this->server->ping) +
+ {{ $this->server->ping }} +
+
+ {{ __('The ping relative to the server from this website') }}
+ + +
- @endif - @if(!$this->server->ping && $this->server->last_check_at) +
+ @endif + @if(!$this->server->ping && $this->server->last_check_at) +
+ {{ __('Offline') }} +
+
+ {{ __('Last checked: :time', ['time'=>$this->server->last_check_at->diffForHumans()]) }} +
+ + + +
+
+ @endif + @auth + @if($this->server->user_id == auth()->user()->id && !$this->server->active)
- Offline + {{ __('Deactivated') }}
- {{ __('Last checked: :time', ['time'=>$this->server->last_check_at->diffForHumans()]) }} + {{ __('Deactivated because of downtime for the past 24 hours') }}
@@ -93,61 +106,46 @@
@endif - @auth - @if(!$this->server->active && $this->server->user_id == auth()->user()->id) -
- Deactivated -
-
- {{ __('Deactivated because of downtime for the past 24 hours') }} -
- - - -
-
- @endif - @endauth -
-

{{ $this->server->description }}

-

{{ $this->server->host }}:{{ $this->server->port }}

- @auth - @if (!$this->server->active && $this->server->user_id == auth()->user()->id) - - @endif @endauth - @if($this->server->official) -
+
+

{{ $this->server->description }}

+

{{ $this->server->host }}:{{ $this->server->port }}

+ @auth + @if ($this->server->user_id == auth()->user()->id && !$this->server->active) + + @endif + @endauth + @if($this->server->official) +
+
+ profil +
+
+

+ {{ __('The P3D Team') }} +

+
+
+ @else + - @else - - @endif -
+ +
+ @endif
- @endif +
From af5dcbb43c31a3e305ae72117deb39816220ac17 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Tue, 8 Aug 2023 21:19:27 +0200 Subject: [PATCH 3/4] Pint --- app/Http/Livewire/Server/ServerCardList.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Livewire/Server/ServerCardList.php b/app/Http/Livewire/Server/ServerCardList.php index 91b15291e..631f12add 100644 --- a/app/Http/Livewire/Server/ServerCardList.php +++ b/app/Http/Livewire/Server/ServerCardList.php @@ -8,7 +8,9 @@ class ServerCardList extends Component { public $servers; + public $my_servers; + public $user; protected $listeners = [ @@ -30,9 +32,6 @@ public function render() return view('livewire.server.server-card-list'); } - /** - * @return void - */ private function loadData(): void { $this->user = auth()->user() ?? null; From 7dd25f247976aa9a9bc531d66023f111551f3aad Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Tue, 8 Aug 2023 21:22:10 +0200 Subject: [PATCH 4/4] Fixed empty server list for guest --- app/Http/Livewire/Server/ServerCardList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Livewire/Server/ServerCardList.php b/app/Http/Livewire/Server/ServerCardList.php index 631f12add..2d95feceb 100644 --- a/app/Http/Livewire/Server/ServerCardList.php +++ b/app/Http/Livewire/Server/ServerCardList.php @@ -45,6 +45,6 @@ private function loadData(): void ->orderBy('last_online_at', 'desc') ->orderBy('ping', 'asc') ->get(); - $this->my_servers = $this->user->id ? Server::where('user_id', $this->user->id)->get() : []; + $this->my_servers = isset($this->user) ? Server::where('user_id', $this->user->id)->get() : collect(); } }