174 lines
6.2 KiB
PHP
174 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\System;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Livewire\Component;
|
|
|
|
class TaskToast extends Component
|
|
{
|
|
// public string $taskKey;
|
|
// public ?string $lastStatus = null;
|
|
//
|
|
// public function mount(string $taskKey)
|
|
// {
|
|
// $this->taskKey = $taskKey;
|
|
// }
|
|
//
|
|
// public function load()
|
|
// {
|
|
// $task = Cache::store('redis')->get($this->taskKey);
|
|
// if (!$task) return;
|
|
//
|
|
// $status = $task['status'] ?? null;
|
|
//
|
|
// // nur wenn sich der Status geändert hat → neues Toast
|
|
// if ($status !== $this->lastStatus) {
|
|
// $this->lastStatus = $status;
|
|
//
|
|
// $this->dispatch('notify', [
|
|
// 'id' => $this->taskKey,
|
|
// 'title' => strtoupper($task['type']).' · '.$task['payload']['domain'],
|
|
// 'text' => $task['message'] ?? '',
|
|
// 'type' => match($status) {
|
|
// 'done' => 'success',
|
|
// 'failed' => 'error',
|
|
// 'running'=> 'info',
|
|
// default => 'info',
|
|
// },
|
|
// 'duration' => in_array($status, ['done','failed']) ? 6000 : 0,
|
|
// 'close' => true,
|
|
// ]);
|
|
// }
|
|
// }
|
|
|
|
// public function render()
|
|
// {
|
|
// return <<<'BLADE'
|
|
// <div class="absolute" wire:poll.3s="load"></div>
|
|
// BLADE;
|
|
// }
|
|
|
|
// public ?string $taskKey = null; // wird über Prop ODER Query ?task=… gesetzt
|
|
// public ?array $task = null;
|
|
// public ?string $last = null; // letzter Status, um doppelte Events zu vermeiden
|
|
// public bool $final = false; // done/failed => Poll stoppen (Frontend kann darauf reagieren)
|
|
//
|
|
// public function mount(?string $taskKey = null): void
|
|
// {
|
|
// // TaskKey aus Prop oder aus URL-Query (?task=issue-cert:domain)
|
|
// $this->taskKey = $taskKey ?: request('task');
|
|
// }
|
|
//
|
|
// public function load(): void
|
|
// {
|
|
// if (!$this->taskKey) return;
|
|
//
|
|
// $this->task = Cache::store('redis')->get($this->taskKey);
|
|
// if (!$this->task) return;
|
|
//
|
|
// $status = $this->task['status'] ?? 'queued';
|
|
// if ($status !== $this->last) {
|
|
// $this->last = $status;
|
|
//
|
|
//// $status = $this->task['status'] ?? 'queued'; // queued|running|done|failed
|
|
//
|
|
// $this->dispatch('notify', [
|
|
// 'id' => $this->taskKey, // gleiche ID => Toast wird ersetzt
|
|
// 'state' => $status, // 'queued' | 'running' | 'done' | 'failed'
|
|
// 'badge' => strtoupper($this->task['type'] ?? 'task'),// z.B. CERTBOT
|
|
// 'domain' => $this->task['payload']['domain'] ?? '', // erscheint rechts neben Badge
|
|
// 'message' => $this->task['message'] ?? '', // Text unten
|
|
// 'position' => 'bottom-center', // optional: top-right|… (Standard: bottom-right)
|
|
// 'duration' => in_array($status, ['done','failed']) ? 6000 : 0, // 0 = offen lassen
|
|
// 'close' => true, // X-Button anzeigen
|
|
// ]);
|
|
// }
|
|
//
|
|
// if (in_array($status, ['done','failed'])) {
|
|
// $this->final = true;
|
|
// }
|
|
// }
|
|
//
|
|
// public function render()
|
|
// {
|
|
// return view('livewire.system.task-toast');
|
|
// }
|
|
|
|
// public ?string $taskKey = null;
|
|
// public ?array $task = null;
|
|
// public ?string $last = null; // letzter gesehener Status
|
|
//
|
|
// public function mount(?string $taskKey = null): void
|
|
// {
|
|
// $this->taskKey = $taskKey ?: request('task');
|
|
// }
|
|
//
|
|
// public function load(): void
|
|
// {
|
|
// if (!$this->taskKey) return;
|
|
//
|
|
// $this->task = Cache::store('redis')->get($this->taskKey);
|
|
// if (!$this->task) return;
|
|
//
|
|
// $status = $this->task['status'] ?? 'queued'; // queued|running|done|failed
|
|
// if ($status !== $this->last) {
|
|
// $this->last = $status;
|
|
//
|
|
// $this->dispatch('notify', [
|
|
// 'id' => $this->taskKey, // gleiche ID => Toast wird ersetzt
|
|
// 'state' => $status, // 'queued' | 'running' | 'done' | 'failed'
|
|
// 'badge' => strtoupper($this->task['type'] ?? 'task'),// z.B. CERTBOT
|
|
// 'domain' => $this->task['payload']['domain'] ?? '', // erscheint rechts neben Badge
|
|
// 'message' => $this->task['message'] ?? '', // Text unten
|
|
// 'position' => 'bottom-center', // z.B. bottom-center
|
|
// 'duration' => in_array($status, ['done','failed']) ? 6000 : 0,
|
|
// 'close' => true,
|
|
// ]);
|
|
// }
|
|
// }
|
|
|
|
public ?string $taskKey = null;
|
|
public ?array $task = null;
|
|
public ?string $lastHash = null; // <— statt $last
|
|
|
|
public function mount(?string $taskKey = null): void
|
|
{
|
|
$this->taskKey = $taskKey ?: request('task');
|
|
}
|
|
|
|
public function load(): void
|
|
{
|
|
if (!$this->taskKey) return;
|
|
|
|
$this->task = \Cache::store('redis')->get($this->taskKey);
|
|
if (!$this->task) return;
|
|
|
|
$status = $this->task['status'] ?? 'queued';
|
|
$message = $this->task['message'] ?? '';
|
|
$hash = sha1($status.'|'.$message); // <— Fingerprint
|
|
|
|
if ($hash !== $this->lastHash) {
|
|
$this->lastHash = $hash;
|
|
|
|
$this->dispatch('notify', [
|
|
'id' => $this->taskKey,
|
|
'state' => $status, // queued|running|done|failed
|
|
'badge' => strtoupper($this->task['type'] ?? 'task'), // z.B. CERTBOT
|
|
'domain' => $this->task['payload']['domain'] ?? '',
|
|
'message' => $message,
|
|
'position' => 'bottom-center',
|
|
'duration' => in_array($status, ['done','failed']) ? 6000 : 0,
|
|
'close' => true,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
// Minimaler Marker reicht, damit wire:poll arbeitet
|
|
return view('livewire.system.task-toast');
|
|
}
|
|
|
|
}
|