diff --git a/laravel_app/app/Events/ProjectMailingStatus.php b/laravel_app/app/Events/ProjectMailingStatus.php new file mode 100644 index 0000000..949e084 --- /dev/null +++ b/laravel_app/app/Events/ProjectMailingStatus.php @@ -0,0 +1,40 @@ +projectMailing = $projectMailing; + } + + /** + * Get the channels the event should broadcast on. + * + * @return array + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('mailing.'.$this->projectMailing->id), + ]; + } +} diff --git a/laravel_app/app/Livewire/Components/Badge.php b/laravel_app/app/Livewire/Components/Badge.php index 89e9401..f9ef9cd 100644 --- a/laravel_app/app/Livewire/Components/Badge.php +++ b/laravel_app/app/Livewire/Components/Badge.php @@ -7,25 +7,39 @@ class Badge extends Component { - public array $colorClasses; public $status; - public $type; + public string $type; public int $id; public $listeners = [ - 'Badge:refresh' => '$refresh', +// 'Badge:refresh' => '$refresh', ]; - public function mount(string $status = null, $id = 0,$type = null) + public function mount(string $status = null, $id = 0, $type = null) { $this->type = $type; - $this->id ??= $id ; + $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'], - Status::Failed => ['bg' => 'bg-red-100', 'text' => 'text-red-700'], - Status::Pending => ['bg' => 'bg-gray-100', 'text' => 'text-gray-600'], + } + + public function getColorClasses(): string + { + return match ($this->status) { + Status::Success => 'bg-green-100 text-green-700', + Status::Failed => 'bg-red-100 text-red-700', + Status::Pending => 'bg-gray-100 text-gray-600', }; } + + public function setStatus(string $status): void + { + $this->status = Status::tryFrom($status) ?? Status::Success; + } + + public function refreshPage() + { + $this->dispatch('Badge:refresh'); + } + public function render() { return view('livewire.components.badge'); diff --git a/laravel_app/app/Livewire/Projects/ReportRow.php b/laravel_app/app/Livewire/Projects/ReportRow.php index c7ba3b0..0e568f5 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] diff --git a/laravel_app/app/Livewire/Projects/Tabs/Mailings.php b/laravel_app/app/Livewire/Projects/Tabs/Mailings.php index 76dabe0..6002703 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Mailings.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Mailings.php @@ -21,6 +21,10 @@ class Mailings extends Component public $search = ''; public $active_mailing = null; + + protected $listeners = [ + 'Badge:refresh' => '$refresh', + ]; public function mount(Project $project) { $this->project = $project; diff --git a/laravel_app/app/Livewire/Projects/Tabs/Report.php b/laravel_app/app/Livewire/Projects/Tabs/Report.php index a315d48..bc327e2 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Report.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Report.php @@ -21,7 +21,7 @@ class Report extends Component public $showReportModal = false; public $listeners = [ - 'Badge:refresh' => '$refresh' + 'Badge:refresh' => '$refresh', ]; public function openCreateReportModal() diff --git a/laravel_app/app/Models/Project.php b/laravel_app/app/Models/Project.php index e0cf06f..64abace 100644 --- a/laravel_app/app/Models/Project.php +++ b/laravel_app/app/Models/Project.php @@ -140,6 +140,7 @@ public function allMosaicsPresent(Carbon $endDate): bool $mosaicsNotPresentInFilesystem = $this->getMosaicFilenameListByEndDate($endDate) ->filter(function ($filename) { return !$this->getMosaicList()->contains(function ($mosaicFilename) use ($filename) { +// TODO check the value of the week leading 0 return Str::endsWith($mosaicFilename, substr($filename, -16)); }); }); diff --git a/laravel_app/app/Models/ProjectMailing.php b/laravel_app/app/Models/ProjectMailing.php index 3126b65..149f58a 100644 --- a/laravel_app/app/Models/ProjectMailing.php +++ b/laravel_app/app/Models/ProjectMailing.php @@ -2,14 +2,14 @@ namespace App\Models; +use App\Events\ProjectMailingStatus; use App\Traits\HasStatus; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; -use Str; +use Illuminate\Support\Str; class ProjectMailing extends Model { @@ -19,6 +19,7 @@ class ProjectMailing extends Model protected $fillable = [ 'subject', 'message', + 'status' ]; @@ -63,4 +64,12 @@ protected function subject(): Attribute } ); } + + protected static function booted(): void + { + parent::booted(); + static::updated(function (ProjectMailing $projectMailing) { + event(new ProjectMailingStatus($projectMailing)); + }); + } } diff --git a/laravel_app/app/Rules/AllMosaicsPresentRule.php b/laravel_app/app/Rules/AllMosaicsPresentRule.php index 187b5bc..f70c6cf 100644 --- a/laravel_app/app/Rules/AllMosaicsPresentRule.php +++ b/laravel_app/app/Rules/AllMosaicsPresentRule.php @@ -19,6 +19,7 @@ public function __construct($projectId) public function passes($attribute, $value) { try { + /** @var Project $project */ $project = Project::find($this->projectId); if (!$project) { diff --git a/laravel_app/app/View/Components/Badge.php b/laravel_app/app/View/Components/Badge.php index b62545d..3cf8839 100644 --- a/laravel_app/app/View/Components/Badge.php +++ b/laravel_app/app/View/Components/Badge.php @@ -15,6 +15,7 @@ class Badge extends Component public Status $status; public int $id; + public function __construct($status = null, $id = 0) { $this->id ??= $id ; diff --git a/laravel_app/public/build/manifest.json b/laravel_app/public/build/manifest.json index 76a0677..7fb2cc0 100644 --- a/laravel_app/public/build/manifest.json +++ b/laravel_app/public/build/manifest.json @@ -32,12 +32,12 @@ "src": "node_modules/@fortawesome/fontawesome-free/webfonts/fa-v4compatibility.woff2" }, "resources/css/app.css": { - "file": "assets/app-4a859431.css", + "file": "assets/app-93dd061f.css", "isEntry": true, "src": "resources/css/app.css" }, "resources/js/alpine.js": { - "file": "assets/alpine-d6afa966.js", + "file": "assets/alpine-e0ba2549.js", "isDynamicEntry": true, "src": "resources/js/alpine.js" }, @@ -45,7 +45,7 @@ "dynamicImports": [ "resources/js/alpine.js" ], - "file": "assets/app-f5ffacbb.js", + "file": "assets/app-eb81fffd.js", "isEntry": true, "src": "resources/js/app.js" } diff --git a/laravel_app/resources/js/alpine.js b/laravel_app/resources/js/alpine.js index 66b1cc7..27f42ac 100644 --- a/laravel_app/resources/js/alpine.js +++ b/laravel_app/resources/js/alpine.js @@ -16,5 +16,4 @@ htabs(Alpine); window.Alpine = Alpine; -Alpine.start(); Livewire.start(); diff --git a/laravel_app/resources/views/components/badge.blade.php b/laravel_app/resources/views/components/badge.blade.php index 62ef09c..cc28467 100644 --- a/laravel_app/resources/views/components/badge.blade.php +++ b/laravel_app/resources/views/components/badge.blade.php @@ -1,4 +1,4 @@ -type) - x-init="Echo.private(`{{$this->type}}.@js($id)`).listen('Project{{ucfirst($this->type)}}Status', (e) => { + x-init="Echo.private(`{{$this->type}}.@js($this->id)`).listen('Project{{ucfirst($this->type)}}Status', (e) => { console.log(e.project{{ucfirst($this->type)}}.status); - $wire.dispatch('Badge:refresh'); + if(e.project{{ucfirst($this->type)}}.status){ + $wire.setStatus(e.project{{ucfirst($this->type)}}.status); + $wire.refreshPage(); + } });" - x-destroy="Echo.leaveChannel(`{{$this->type}}.@js($id)`);" + x-destroy="Echo.leaveChannel(`{{$this->type}}.@js($this->id)`);" @endif > {{ $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 0c74682..0999088 100644 --- a/laravel_app/resources/views/livewire/projects/report-row.blade.php +++ b/laravel_app/resources/views/livewire/projects/report-row.blade.php @@ -10,7 +10,7 @@ {{-- @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 27deba3..3448b9a 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/download.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/download.blade.php @@ -1,10 +1,4 @@ -
hasPendingDownload())--}} - {{-- wire:poll.1s=""--}} - {{-- @endif--}} - {{-- TODO Put Back the poll but to the list of downloads only--}} - class="m-2" -> +

Downloads

@@ -52,7 +46,7 @@ class="px-3 py-3.5 text-right pr-4 sm:pr-8 lg:pr-8 text-sm font-semibold text-gr - + @endforeach diff --git a/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php b/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php index 2df5ac9..43113c7 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php @@ -39,7 +39,7 @@ class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">@lang('Attachm {{ $mail->id }} {{ $mail->subject }} - + {{ $mail->recipients()->count() }} {{ $mail->attachments()->pluck('name')->join( ', ') }} 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 b25b557..563c14e 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php @@ -45,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/resources/views/projects/show.blade.php b/laravel_app/resources/views/projects/show.blade.php index aa1c110..5715238 100644 --- a/laravel_app/resources/views/projects/show.blade.php +++ b/laravel_app/resources/views/projects/show.blade.php @@ -10,7 +10,7 @@
@switch($currentTab) @case('downloads') - + @break @case('mosaics') diff --git a/laravel_app/routes/channels.php b/laravel_app/routes/channels.php index 9b68dc2..6016318 100644 --- a/laravel_app/routes/channels.php +++ b/laravel_app/routes/channels.php @@ -26,4 +26,7 @@ Broadcast::channel('report.{reportId}', function ($user, $reportId) { return true; }); +Broadcast::channel('mailing.{mailingId}', function ($user, $mailingId) { + return true; +});