diff --git a/laravel_app/app/Events/ReportUpdated.php b/laravel_app/app/Events/ReportUpdated.php new file mode 100644 index 0000000..0ab3584 --- /dev/null +++ b/laravel_app/app/Events/ReportUpdated.php @@ -0,0 +1,35 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('reports-channel'), + ]; + } +} diff --git a/laravel_app/app/Livewire/Components/Badge.php b/laravel_app/app/Livewire/Components/Badge.php index f9ef9cd..241d0b7 100644 --- a/laravel_app/app/Livewire/Components/Badge.php +++ b/laravel_app/app/Livewire/Components/Badge.php @@ -3,16 +3,16 @@ namespace App\Livewire\Components; use App\Enums\Status; + use Livewire\Component; class Badge extends Component { + public $status; public string $type; public int $id; - public $listeners = [ -// 'Badge:refresh' => '$refresh', - ]; + public function mount(string $status = null, $id = 0, $type = null) { @@ -35,13 +35,14 @@ public function setStatus(string $status): void $this->status = Status::tryFrom($status) ?? Status::Success; } - public function refreshPage() + public function refreshPendingMessage() { - $this->dispatch('Badge:refresh'); + $this->dispatch('PendingMessage:refresh'); } public function render() { + logger(sprintf('%s %s', __CLASS__, $this->id)); return view('livewire.components.badge'); } } diff --git a/laravel_app/app/Livewire/Components/PendingMessage.php b/laravel_app/app/Livewire/Components/PendingMessage.php new file mode 100644 index 0000000..92d858c --- /dev/null +++ b/laravel_app/app/Livewire/Components/PendingMessage.php @@ -0,0 +1,52 @@ + 'updateSelf', + ]; + + public function mount(Project $project,string $type = null): void + { + logger('in PendingMessage->mount();'); + $this->project = Project::find($project->id); + $this->type = $type; + $this->count = static::getPendingCount($project,$type); + } + + public function boot() + { + logger('in PendingMessage->boot();'); + } + + public static function getPendingCount(Project $p,string $t): int + { + return (match($t){ + 'reports' => $p->reports(), + 'downloads' => $p->downloads(), + 'mosaics' => $p->mosaics(), + 'mailings' => $p->mailings(), + })->statusPending()->count(); + } + + public function updateSelf() + { + logger($this->attributes->toJson()); + $this->count = static::getPendingCount($this->project, $this->type); + } + + public function render() + { + logger(sprintf('%s', __CLASS__)); + return view('livewire.components.pending-message'); + } +} diff --git a/laravel_app/app/Livewire/Projects/ReportRow.php b/laravel_app/app/Livewire/Projects/ReportRow.php index 0e568f5..1d3f8ef 100644 --- a/laravel_app/app/Livewire/Projects/ReportRow.php +++ b/laravel_app/app/Livewire/Projects/ReportRow.php @@ -11,7 +11,7 @@ class ReportRow extends Component { protected $listeners = [ - 'Badge:refresh' => '$refresh', +// 'Badge:refresh' => '$refresh', ]; #[Reactive] @@ -42,4 +42,9 @@ public function createMailing() { $this->mailingForm->save(); $this->reset('createMailingModal'); } + + public function render(){ + logger(sprintf('%s %s', __CLASS__, $this->report->id)); + return view('livewire.projects.report-row'); + } } diff --git a/laravel_app/app/Livewire/Projects/Tabs/Report.php b/laravel_app/app/Livewire/Projects/Tabs/Report.php index bc327e2..eec0786 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Report.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Report.php @@ -6,6 +6,7 @@ use App\Models\Project; use App\Models\ProjectReport; use App\Rules\AllMosaicsPresentRule; +use Livewire\Attributes\Reactive; use Livewire\Component; use Livewire\WithPagination; @@ -18,11 +19,8 @@ class Report extends Component public $search = ""; - public $showReportModal = false; - public $listeners = [ - 'Badge:refresh' => '$refresh', - ]; + public $showReportModal = false; public function openCreateReportModal() { @@ -86,12 +84,6 @@ private function applySearch($query) ->orWhere('year', 'like', '%'.$this->search.'%') ->orWhere('week', 'like', '%'.$this->search.'%'); }); -// if ($this->search) { -// $query->where('name', 'like', '%'.$this->search.'%'); -// $query->orWhere('year', 'like', '%'.$this->search.'%'); -// $query->orWhere('week', 'like', '%'.$this->search.'%'); -// } -// return $query; } @@ -105,7 +97,7 @@ public function render() $query = $this->applySearch($query); $reports = $query->paginate(10, pageName: 'reportPage'); - + logger(sprintf('%s %s', __CLASS__, now())); return view('livewire.projects.tabs.report') ->with(compact('reports')); } diff --git a/laravel_app/resources/views/livewire/components/badge.blade.php b/laravel_app/resources/views/livewire/components/badge.blade.php index 4871644..1877bb2 100644 --- a/laravel_app/resources/views/livewire/components/badge.blade.php +++ b/laravel_app/resources/views/livewire/components/badge.blade.php @@ -4,7 +4,8 @@ console.log(e.project{{ucfirst($this->type)}}.status); if(e.project{{ucfirst($this->type)}}.status){ $wire.setStatus(e.project{{ucfirst($this->type)}}.status); - $wire.refreshPage(); + console.log('update pending message'); + $wire.refreshPendingMessage(); } });" x-destroy="Echo.leaveChannel(`{{$this->type}}.@js($this->id)`);" diff --git a/laravel_app/resources/views/livewire/components/pending-message.blade.php b/laravel_app/resources/views/livewire/components/pending-message.blade.php new file mode 100644 index 0000000..43c793d --- /dev/null +++ b/laravel_app/resources/views/livewire/components/pending-message.blade.php @@ -0,0 +1,3 @@ +@if($count > 0) +

Pending {{ $type }} for this project: {{ $this->count }}

+@endif diff --git a/laravel_app/resources/views/livewire/projects/tabs/report.blade.php b/laravel_app/resources/views/livewire/projects/tabs/report.blade.php index 473e067..da6454f 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/report.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/report.blade.php @@ -3,9 +3,10 @@

Reports

- @if($project->hasPendingReport()) -

Pending reports for this project: {{ $project->reports()->statusPending()->count() }}

- @endif +{{-- @if($project->hasPendingReport())--}} +{{--

Pending reports for this project: {{ $project->reports()->statusPending()->count() }}

--}} + +{{-- @endif--}}