generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64eb791
commit 413ab28
Showing
8 changed files
with
240 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
@php | ||
use Illuminate\Support\Str; | ||
@endphp | ||
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class"> | ||
<x-pulse::card-header | ||
name="Cron" | ||
> | ||
<x-slot:icon> | ||
<x-pulse::icons.rocket-launch/> | ||
</x-slot:icon> | ||
</x-pulse::card-header> | ||
|
||
<div> | ||
<div class="flex flex-col gap-6"> | ||
<div> | ||
<x-pulse::table> | ||
<colgroup> | ||
<col width="100%"/> | ||
<col width="0%"/> | ||
<col width="0%"/> | ||
<col width="0%"/> | ||
</colgroup> | ||
<x-pulse::thead> | ||
<tr> | ||
<x-pulse::th>Task</x-pulse::th> | ||
<x-pulse::th class="text-right">Last executed at</x-pulse::th> | ||
<x-pulse::th class="text-right">Cron expression</x-pulse::th> | ||
<x-pulse::th class="text-right whitespace-nowrap">Result</x-pulse::th> | ||
</tr> | ||
</x-pulse::thead> | ||
<tbody> | ||
@foreach ($cronChecks as $cronCheck) | ||
<tr class="h-2 first:h-0"></tr> | ||
<tr wire:key="cronCheck.{{ $cronCheck->id }}"> | ||
<x-pulse::td class="max-w-[1px]"> | ||
<code class="block text-xs text-gray-900 dark:text-gray-100 truncate" | ||
title="{{ $cronCheck->name }}"> | ||
{{ $cronCheck->name }} | ||
</code> | ||
</x-pulse::td> | ||
<x-pulse::td class="text-gray-700 dark:text-gray-300 font-bold"> | ||
<div> | ||
{{ $cronCheck->humanReadableLatestPingAt }} | ||
</div> | ||
<div> | ||
{{ $cronCheck->latestPingAt }} | ||
</div> | ||
|
||
</x-pulse::td> | ||
<x-pulse::td class="text-gray-700 dark:text-gray-300 font-bold"> | ||
{{ $cronCheck->humanReadableCronExpression }} | ||
{{ $cronCheck->cronExpression }} | ||
</x-pulse::td> | ||
<x-pulse::td class="text-gray-700 dark:text-gray-300 font-bold"> | ||
<div> | ||
{{ $cronCheck->latestResultLabel }} | ||
</div> | ||
<div> | ||
Result color: {{ $cronCheck->latestResultLabelColor }} | ||
</div> | ||
</x-pulse::td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</x-pulse::table> | ||
</div> | ||
</div> | ||
</div> | ||
</x-pulse::card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace OhDear\OhDearPulse\Livewire\Concerns; | ||
|
||
use Carbon\CarbonInterval; | ||
use Illuminate\Support\Facades\App; | ||
use Laravel\Pulse\Support\CacheStoreResolver; | ||
|
||
trait RemembersApiCalls | ||
{ | ||
public function remember(callable $apiCall, string $key, CarbonInterval $interval = null): mixed | ||
{ | ||
$interval ??= CarbonInterval::minute(); | ||
|
||
return App::make(CacheStoreResolver::class)->store()->remember( | ||
'laravel:pulse:' . static::class . ':' . $key, | ||
$interval, | ||
fn() => $apiCall(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace OhDear\OhDearPulse\Livewire\Concerns; | ||
|
||
use OhDear\PhpSdk\OhDear; | ||
|
||
trait UsesOhDearApi | ||
{ | ||
public function ohDear(): ?OhDear | ||
{ | ||
return app('ohdear-pulse'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace OhDear\OhDearPulse\Livewire; | ||
|
||
use Illuminate\Contracts\Support\Renderable; | ||
use Laravel\Pulse\Livewire\Card; | ||
use Livewire\Attributes\Lazy; | ||
use OhDear\OhDearPulse\Livewire\Concerns\RemembersApiCalls; | ||
use OhDear\OhDearPulse\Livewire\Concerns\UsesOhDearApi; | ||
use OhDear\OhDearPulse\OhDearPulse; | ||
use OhDear\PhpSdk\Resources\Check; | ||
use OhDear\PhpSdk\Resources\Site; | ||
|
||
#[Lazy] | ||
class OhDearCronPulseCardComponent extends Card | ||
{ | ||
use UsesOhDearApi; | ||
use RemembersApiCalls; | ||
|
||
public int $siteId; | ||
|
||
public function mount(int $siteId = null) | ||
{ | ||
$this->siteId = $siteId ?? config('services.oh_dear.pulse.site_id'); | ||
} | ||
|
||
public function render(): Renderable | ||
{ | ||
$cronChecks = $this->getCronChecks(); | ||
|
||
return view('ohdear-pulse::cron', [ | ||
'cronChecks' => $cronChecks, | ||
]); | ||
} | ||
|
||
/** | ||
* @return array<\OhDear\PhpSdk\Resources\CronCheck>|null | ||
*/ | ||
public function getCronChecks(): ?array | ||
{ | ||
if (! OhDearPulse::isConfigured()) { | ||
return null; | ||
} | ||
|
||
return $this->remember( | ||
fn() => $this->ohDear()?->cronChecks($this->siteId), | ||
'site:' . $this->siteId, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters