Skip to content

Commit

Permalink
Move php from Blade to Page
Browse files Browse the repository at this point in the history
  • Loading branch information
RMartinOscar committed Jan 8, 2025
1 parent 7c94ad9 commit 2d002b6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
34 changes: 34 additions & 0 deletions app/Filament/Admin/Pages/Health.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Pages\Page;
use Illuminate\Support\Facades\Artisan;
use Spatie\Health\Commands\RunHealthChecksCommand;
use Spatie\Health\Enums\Status;
use Spatie\Health\ResultStores\ResultStore;

class Health extends Page
Expand Down Expand Up @@ -122,4 +123,37 @@ public static function getNavigationIcon(): string

return $results->containsFailingCheck() ? 'tabler-heart-exclamation' : 'tabler-heart-check';
}

public function backgroundColor(string $str): string
{
return match ($str) {
Status::ok()->value => 'bg-success-100 dark:bg-success-200',
Status::warning()->value => 'bg-warning-100 dark:bg-warning-200',
Status::skipped()->value => 'bg-info-100 dark:bg-info-200',
Status::failed()->value, Status::crashed()->value => 'bg-danger-100 dark:bg-danger-200',
default => 'bg-gray-100 dark:bg-gray-200'
};
}

public function iconColor(string $str): string
{
return match ($str) {
Status::ok()->value => 'text-success-500 dark:text-success-600',
Status::warning()->value => 'text-warning-500 dark:text-warning-600',
Status::skipped()->value => 'text-info-500 dark:text-info-600',
Status::failed()->value, Status::crashed()->value => 'text-danger-500 dark:text-danger-600',
default => 'text-gray-500 dark:text-gray-600'
};
}

public function icon(string $str): string
{
return match ($str) {
Status::ok()->value => 'tabler-circle-check',
Status::warning()->value => 'tabler-exclamation-circle',
Status::skipped()->value => 'tabler-circle-chevron-right',
Status::failed()->value, Status::crashed()->value => 'tabler-circle-x',
default => 'tabler-help-circle'
};
}
}
44 changes: 2 additions & 42 deletions resources/views/filament/pages/health.blade.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,10 @@
@php
if(! function_exists('backgroundColor')) {
function backgroundColor($status) {
return match ($status) {
Spatie\Health\Enums\Status::ok()->value => 'bg-success-100 dark:bg-success-200',
Spatie\Health\Enums\Status::warning()->value => 'bg-warning-100 dark:bg-warning-200',
Spatie\Health\Enums\Status::skipped()->value => 'bg-info-100 dark:bg-info-200',
Spatie\Health\Enums\Status::failed()->value, Spatie\Health\Enums\Status::crashed()->value => 'bg-danger-100 dark:bg-danger-200',
default => 'bg-gray-100 dark:bg-gray-200'
};
}
}
if(! function_exists('iconColor')) {
function iconColor($status)
{
return match ($status) {
Spatie\Health\Enums\Status::ok()->value => 'text-success-500 dark:text-success-600',
Spatie\Health\Enums\Status::warning()->value => 'text-warning-500 dark:text-warning-600',
Spatie\Health\Enums\Status::skipped()->value => 'text-info-500 dark:text-info-600',
Spatie\Health\Enums\Status::failed()->value, Spatie\Health\Enums\Status::crashed()->value => 'text-danger-500 dark:text-danger-600',
default => 'text-gray-500 dark:text-gray-600'
};
}
}
if(! function_exists('icon')) {
function icon($status)
{
return match ($status) {
Spatie\Health\Enums\Status::ok()->value => 'tabler-circle-check',
Spatie\Health\Enums\Status::warning()->value => 'tabler-exclamation-circle',
Spatie\Health\Enums\Status::skipped()->value => 'tabler-circle-chevron-right',
Spatie\Health\Enums\Status::failed()->value, Spatie\Health\Enums\Status::crashed()->value => 'tabler-circle-x',
default => 'tabler-help-circle'
};
}
}
@endphp

<x-filament-panels::page>
@if (count($checkResults?->storedCheckResults ?? []))
<x-filament::grid default="1" sm="2" class="gap-6 mb-5">
@foreach ($checkResults->storedCheckResults as $result)
<div class="flex items-start px-4 py-5 space-x-2 md:space-x-3 overflow-hidden shadow-lg rounded-xl bg-white dark:bg-gray-900 ring-1 ring-gray-950/5 dark:ring-white/10 sm:p-6">
<div class="flex justify-center items-center rounded-full p-2 mr-2 {{ backgroundColor($result->status) }}">
<x-filament::icon icon="{{ icon($result->status) }}" class="h-6 w-6 {{ iconColor($result->status) }}" />
<div class="flex justify-center items-center rounded-full p-2 mr-2 {{ $this->backgroundColor($result->status) }}">
<x-filament::icon icon="{{ $this->icon($result->status) }}" class="h-6 w-6 {{ $this->iconColor($result->status) }}" />
</div>
<div>
<dd class="-mt-1 font-bold md:mt-1 md:text-xl text-gray-900 dark:text-white">
Expand Down

0 comments on commit 2d002b6

Please sign in to comment.