[done] PendingMessage Component in report tabs
This commit is contained in:
parent
acd8d0ea32
commit
c18433a9d6
35
laravel_app/app/Events/ReportUpdated.php
Normal file
35
laravel_app/app/Events/ReportUpdated.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\ProjectReport;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ReportUpdated implements ShouldBroadcastNow
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public ProjectReport $ProjectReport
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('reports-channel'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
52
laravel_app/app/Livewire/Components/PendingMessage.php
Normal file
52
laravel_app/app/Livewire/Components/PendingMessage.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Components;
|
||||
|
||||
use App\Models\Project;
|
||||
use Livewire\Component;
|
||||
|
||||
class PendingMessage extends Component
|
||||
{
|
||||
public $type;
|
||||
public Project $project;
|
||||
public $count;
|
||||
|
||||
protected $listeners = [
|
||||
'PendingMessage:refresh' => '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');
|
||||
}
|
||||
}
|
||||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)`);"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
@if($count > 0)
|
||||
<p class="text-base text-gray-700 animate-pulse"> Pending {{ $type }} for this project: {{ $this->count }}</p>
|
||||
@endif
|
||||
|
|
@ -3,9 +3,10 @@
|
|||
<div class="sm:flex sm:flex-col sm:items-center">
|
||||
<div class="w-full flex justify-between my-4">
|
||||
<h1 class="text-base font-semibold leading-6 text-gray-900">Reports</h1>
|
||||
@if($project->hasPendingReport())
|
||||
<p class="text-base text-gray-700 animate-pulse"> Pending reports for this project: {{ $project->reports()->statusPending()->count() }}</p>
|
||||
@endif
|
||||
{{-- @if($project->hasPendingReport())--}}
|
||||
{{-- <p class="text-base text-gray-700 animate-pulse"> Pending reports for this project: {{ $project->reports()->statusPending()->count() }}</p>--}}
|
||||
<livewire:components.pending-message :project="$project" type="reports"></livewire:components.pending-message>
|
||||
{{-- @endif--}}
|
||||
</div>
|
||||
<div class="mt-4 md:mt-0 flex flex-col md:flex md:justify-between md:flex-row w-full gap-2">
|
||||
<x-search></x-search>
|
||||
|
|
|
|||
Loading…
Reference in a new issue