diff --git a/laravel_app/app/Events/DownloadStatusPending.php b/laravel_app/app/Events/DownloadStatusPending.php deleted file mode 100644 index 591a00b..0000000 --- a/laravel_app/app/Events/DownloadStatusPending.php +++ /dev/null @@ -1,30 +0,0 @@ - - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } -} diff --git a/laravel_app/app/Events/ProjectDownloadStatus.php b/laravel_app/app/Events/ProjectDownloadStatus.php new file mode 100644 index 0000000..7e7f96b --- /dev/null +++ b/laravel_app/app/Events/ProjectDownloadStatus.php @@ -0,0 +1,33 @@ +projectDownload = $projectDownload; + } + + /** + * Get the channels the event should broadcast on. + * + */ + public function broadcastOn(): array + { + return [new PrivateChannel('download.'.$this->projectDownload->id)]; + } +} diff --git a/laravel_app/app/Events/ProjectMosaicStatus.php b/laravel_app/app/Events/ProjectMosaicStatus.php new file mode 100644 index 0000000..12908a1 --- /dev/null +++ b/laravel_app/app/Events/ProjectMosaicStatus.php @@ -0,0 +1,34 @@ +projectMosaic = $projectMosaic; + } + + /** + * Get the channels the event should broadcast on. + * + * @return array + */ + public function broadcastOn(): array + { + return [new PrivateChannel('mosaic.'.$this->projectMosaic->id)]; + } +} diff --git a/laravel_app/app/Events/ProjectReportStatus.php b/laravel_app/app/Events/ProjectReportStatus.php new file mode 100644 index 0000000..04f659e --- /dev/null +++ b/laravel_app/app/Events/ProjectReportStatus.php @@ -0,0 +1,35 @@ +projectReport = $projectReport; + } + + /** + * Get the channels the event should broadcast on. + * + * @return array + */ + public function broadcastOn(): array + { + return [new PrivateChannel('report.'.$this->projectReport->id)]; + } +} diff --git a/laravel_app/app/Livewire/Projects/ReportRow.php b/laravel_app/app/Livewire/Projects/ReportRow.php index d51bfca..c7ba3b0 100644 --- a/laravel_app/app/Livewire/Projects/ReportRow.php +++ b/laravel_app/app/Livewire/Projects/ReportRow.php @@ -5,10 +5,16 @@ use App\Livewire\Forms\MailingForm; use App\Models\ProjectReport; use Illuminate\Support\Facades\Storage; +use Livewire\Attributes\Reactive; use Livewire\Component; class ReportRow extends Component { + protected $listeners = [ +// 'Badge:refresh' => '$refresh', + ]; + + #[Reactive] public ProjectReport $report; public MailingForm $mailingForm; diff --git a/laravel_app/app/Livewire/Projects/Tabs/Download.php b/laravel_app/app/Livewire/Projects/Tabs/Download.php index 4819310..7212866 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Download.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Download.php @@ -21,6 +21,10 @@ class Download extends Component public $search = ''; + public $listeners = [ + 'Badge:refresh' => '$refresh', + ]; + public function mount(Project $project) diff --git a/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php b/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php index 9a3c77e..b4b56df 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php @@ -20,6 +20,9 @@ class Mosaic extends Component public $showCreateModal = false; public $search = ""; + protected $listeners = [ + 'Badge:refresh' => '$refresh', + ]; public function mount(Project $project) { diff --git a/laravel_app/app/Livewire/Projects/Tabs/Report.php b/laravel_app/app/Livewire/Projects/Tabs/Report.php index 661ac1c..a315d48 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Report.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Report.php @@ -20,7 +20,9 @@ class Report extends Component public $showReportModal = false; - public $listeners = ['refresh' => '$refresh']; + public $listeners = [ + 'Badge:refresh' => '$refresh' + ]; public function openCreateReportModal() { @@ -97,11 +99,13 @@ public function render() { $query = Project::find($this->project->id) ->reports() + ->with('project') ->orderBy('year', 'desc') ->orderBy('week', 'desc'); $query = $this->applySearch($query); $reports = $query->paginate(10, pageName: 'reportPage'); + return view('livewire.projects.tabs.report') ->with(compact('reports')); } diff --git a/laravel_app/app/Models/ProjectDownload.php b/laravel_app/app/Models/ProjectDownload.php index 87a3526..ed527aa 100644 --- a/laravel_app/app/Models/ProjectDownload.php +++ b/laravel_app/app/Models/ProjectDownload.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Events\ProjectDownloadStatus; use App\Traits\HasStatus; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -15,10 +16,19 @@ class ProjectDownload extends Model protected $fillable = [ 'name', 'path', + 'status' ]; public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Project::class); } + + protected static function booted(): void + { + parent::booted(); + static::updated(function (ProjectDownload $projectDownload) { + event(new ProjectDownloadStatus($projectDownload)); + }); + } } diff --git a/laravel_app/app/Models/ProjectMosaic.php b/laravel_app/app/Models/ProjectMosaic.php index 34b56be..4051c0f 100644 --- a/laravel_app/app/Models/ProjectMosaic.php +++ b/laravel_app/app/Models/ProjectMosaic.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Events\ProjectMosaicStatus; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -15,6 +16,7 @@ class ProjectMosaic extends Model 'path', 'week', 'year', + 'status' ]; public function project() @@ -22,4 +24,12 @@ public function project() return $this->belongsTo(Project::class); } + protected static function booted(): void + { + parent::booted(); + static::updated(function (ProjectMosaic $projectMosaic) { + event(new ProjectMosaicStatus($projectMosaic)); + }); + } + } diff --git a/laravel_app/app/Models/ProjectReport.php b/laravel_app/app/Models/ProjectReport.php index edcd81e..45f950b 100644 --- a/laravel_app/app/Models/ProjectReport.php +++ b/laravel_app/app/Models/ProjectReport.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Events\ProjectReportStatus; use App\Jobs\ProjectDownloadTiffJob; use App\Jobs\ProjectMosiacGeneratorJob; use App\Traits\HasStatus; @@ -14,7 +15,7 @@ class ProjectReport extends Model { use HasStatus; - protected $fillable = ['name', 'path', 'week', 'year']; + protected $fillable = ['name', 'path', 'week', 'year','status']; @@ -74,5 +75,13 @@ public function deleteMe() $this->delete(); } + protected static function booted(): void + { + parent::booted(); + static::updated(function (ProjectReport $projectReport) { + event(new ProjectReportStatus($projectReport)); + }); + } + } diff --git a/laravel_app/app/View/Components/Badge.php b/laravel_app/app/View/Components/Badge.php index 07e1260..b62545d 100644 --- a/laravel_app/app/View/Components/Badge.php +++ b/laravel_app/app/View/Components/Badge.php @@ -13,9 +13,11 @@ class Badge extends Component */ public array $colorClasses; public Status $status; + public int $id; - public function __construct($status = null) + public function __construct($status = null, $id = 0) { + $this->id ??= $id ; $this->status = Status::tryFrom($status) ?? Status::Success; $this->colorClasses = match($this->status) { Status::Success => ['bg' => 'bg-green-100', 'text' => 'text-green-700'], diff --git a/laravel_app/resources/js/alpine.js b/laravel_app/resources/js/alpine.js index df15b0c..66b1cc7 100644 --- a/laravel_app/resources/js/alpine.js +++ b/laravel_app/resources/js/alpine.js @@ -1,17 +1,20 @@ -import { Livewire, Alpine } from '../../vendor/livewire/livewire/dist/livewire.esm'; +import {Livewire, Alpine} from '../../vendor/livewire/livewire/dist/livewire.esm'; // import Intersect from "@alpinejs/intersect"; import focus from "@alpinejs/focus"; // import Clipboard from "@ryangjchandler/alpine-clipboard"; // import collapse from "@alpinejs/collapse"; import ui from "@alpinejs/ui"; -Alpine.plugin(ui) -Alpine.plugin(focus) + +Alpine.plugin(ui); +Alpine.plugin(focus); // Alpine.plugin(Clipboard); // Alpine.plugin(Intersect); // Alpine.plugin(collapse); import htabs from './history-tabs'; -htabs(Alpine) -window.Alpine = Alpine +htabs(Alpine); + +window.Alpine = Alpine; +Alpine.start(); Livewire.start(); diff --git a/laravel_app/resources/js/app.js b/laravel_app/resources/js/app.js index a111dc0..37c5e93 100644 --- a/laravel_app/resources/js/app.js +++ b/laravel_app/resources/js/app.js @@ -2,3 +2,4 @@ import './bootstrap'; import('./alpine'); import flatpckr from 'flatpickr'; window.flatpckr = flatpckr; + diff --git a/laravel_app/resources/views/components/badge.blade.php b/laravel_app/resources/views/components/badge.blade.php index 20285f9..62ef09c 100644 --- a/laravel_app/resources/views/components/badge.blade.php +++ b/laravel_app/resources/views/components/badge.blade.php @@ -1,3 +1,11 @@ - + {{ $status }} diff --git a/laravel_app/resources/views/livewire/projects/report-row.blade.php b/laravel_app/resources/views/livewire/projects/report-row.blade.php index 144fd1e..0c74682 100644 --- a/laravel_app/resources/views/livewire/projects/report-row.blade.php +++ b/laravel_app/resources/views/livewire/projects/report-row.blade.php @@ -5,11 +5,12 @@ {{ $report->name }} - @if($report->status == \App\Enums\Status::Pending) - - @else - - @endif +{{-- @if($report->status == \App\Enums\Status::Pending)--}} +{{-- --}} +{{-- @else--}} +{{-- --}} +{{-- @endif--}} + diff --git a/laravel_app/resources/views/livewire/projects/tabs/download.blade.php b/laravel_app/resources/views/livewire/projects/tabs/download.blade.php index 4276dc2..27deba3 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/download.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/download.blade.php @@ -1,8 +1,8 @@
hasPendingDownload())--}} -{{-- wire:poll.1s=""--}} -{{-- @endif--}} -{{-- TODO Put Back the poll but to the list of downloads only--}} + {{-- @if($project->hasPendingDownload())--}} + {{-- wire:poll.1s=""--}} + {{-- @endif--}} + {{-- TODO Put Back the poll but to the list of downloads only--}} class="m-2" >
@@ -50,8 +50,9 @@ class="px-3 py-3.5 text-right pr-4 sm:pr-8 lg:pr-8 text-sm font-semibold text-gr {{ $download->path }} - - + + @endforeach diff --git a/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php b/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php index d903bab..b25b557 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php @@ -1,8 +1,4 @@ -
hasPendingMosaic()) - wire:poll.1s="" - @endif -> +
@@ -49,7 +45,7 @@ class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900 sm:pr-8 lg:pr- {{ $mosaic->year }}-{{ $mosaic->week}} - + @endforeach diff --git a/laravel_app/routes/channels.php b/laravel_app/routes/channels.php index 5d451e1..9b68dc2 100644 --- a/laravel_app/routes/channels.php +++ b/laravel_app/routes/channels.php @@ -16,3 +16,14 @@ Broadcast::channel('App.Models.User.{id}', function ($user, $id) { return (int) $user->id === (int) $id; }); + +Broadcast::channel('download.{downloadId}', function ($user, $downloadId) { + return true; +}); +Broadcast::channel('mosaic.{mosaicId}', function ($user, $mosaicId) { + return true; +}); +Broadcast::channel('report.{reportId}', function ($user, $reportId) { + return true; +}); +