mailwolt/app/Livewire/PingButton.php

86 lines
2.6 KiB
PHP

<?php
namespace App\Livewire;
use App\Events\CertPing;
use App\Jobs\SimulateCertIssue;
use App\Support\ToastBus; // <- neu
use Illuminate\Support\Facades\Auth; // für auth()->id()
use Livewire\Component;
class PingButton extends Component
{
public function ping()
{
event(new CertPing('Ping von Livewire-Button 🚀'));
// kleines Feedback
$this->dispatch('toast', [
'state' => 'done',
'badge' => 'Broadcast',
'domain' => 'Event gesendet',
'message' => 'Sieh in der Browser-Konsole nach.',
'duration' => 3000,
]);
}
public function simulateSelfSigned(string $domain = '10.10.70.58')
{
$taskKey = 'task:issue-cert:'.$domain;
// Optionaler „Start“-Toast vor Redirect
$this->dispatch('toast', state: 'queued', badge: 'ZERTIFIKAT',
domain: $domain, message: 'Erstellung gestartet…', pos: 'bottom-right', duration: -1
);
\App\Jobs\SimulateCertIssue::dispatch($domain, $taskKey);
// return redirect()->route('dashboard');
}
// public function simulateSelfSigned(string $domain = '10.10.70.58')
// {
// $taskKey = 'issue-cert:' . $domain;
// $userId = Auth::id() ?? 0;
//
// // (optional aber nice): Sofort in Redis persistieren + WS feuern,
// // damit der Toast schon vor dem ersten Job-Schritt sichtbar ist.
// ToastBus::put($userId, $taskKey, [
// 'title' => 'Zertifikat',
// 'badge' => 'Self-signed',
// 'message' => 'Erstellung gestartet…',
// 'state' => 'queued',
// 'progress' => 5,
// ]);
//
// // zusätzlich lokales UI-Feedback (falls du es magst)
// $this->dispatch('toast', [
// 'state' => 'queued',
// 'badge' => 'Zertifikat',
// 'domain' => $domain,
// 'message' => 'Erstellung gestartet…',
// 'pos' => 'bottom-right',
// 'duration' => -1, // offen lassen, bis "done/failed" kommt
// ]);
//
// // JOB mit neuer Signatur starten
// SimulateCertIssue::dispatch(
// userId: $userId,
// domain: $domain,
// taskKey: $taskKey
// );
//
// // Dashboard kann per "Initial-Fetch" sofort den Task laden
// session()->flash('task_key', $taskKey);
//
// // weiterleiten; die Echtzeit-Updates laufen unabhängig per WS
// return redirect()->route('dashboard');
// }
public function render()
{
return view('livewire.ping-button');
}
}