From 69233b58fe1bbbef3aed99d9f8b3f8d02e658f7e Mon Sep 17 00:00:00 2001 From: guillaume91 Date: Thu, 20 Jun 2024 14:59:59 +0200 Subject: [PATCH] [done] Download button when the mosaics are missing in reports tab. --- .../app/Livewire/Projects/Tabs/Report.php | 10 ++++++++++ laravel_app/app/Models/Project.php | 19 +++++++++++-------- .../app/Rules/AllMosaicsPresentRule.php | 1 - .../report-manager-properties-modal.blade.php | 12 ++++++------ .../livewire/projects/report-row.blade.php | 5 ----- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/laravel_app/app/Livewire/Projects/Tabs/Report.php b/laravel_app/app/Livewire/Projects/Tabs/Report.php index 907563f..3d20812 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Report.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Report.php @@ -2,11 +2,14 @@ namespace App\Livewire\Projects\Tabs; +use App\Jobs\ProjectMosiacGeneratorJob; use App\Jobs\ProjectReportGeneratorJob; use App\Models\Project; +use App\Models\ProjectMosaic; use App\Models\ProjectReport; use App\Rules\AllMosaicsPresentRule; use Carbon\Carbon; +use Illuminate\Support\Str; use Livewire\Attributes\Reactive; use Livewire\Component; use Livewire\WithPagination; @@ -105,4 +108,11 @@ public function render() return view('livewire.projects.tabs.report') ->with(compact('reports')); } + + public function getMissingMosaicsInFileSystem(Carbon $endDate,int $offset = 7) + { + $this->project->getMosaicsFor($endDate,$offset); + return redirect()->route('project.show',[$this->project->name,'mosaics']); + + } } diff --git a/laravel_app/app/Models/Project.php b/laravel_app/app/Models/Project.php index 24ea500..8e3eb53 100644 --- a/laravel_app/app/Models/Project.php +++ b/laravel_app/app/Models/Project.php @@ -132,14 +132,7 @@ public function allMosaicsPresent(Carbon $endDate): bool if ($endDate->isFuture()) { throw new \Exception('Mosaic can\'t be generated for the future. Change the end date.'); } - - $mosaicsNotPresentInFilesystem = collect($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)); - }); - }); + $mosaicsNotPresentInFilesystem = $this->getMissingMosaicsInFileSystem($endDate); if ($mosaicsNotPresentInFilesystem->count() === 0) { return true; } @@ -150,6 +143,16 @@ public function allMosaicsPresent(Carbon $endDate): bool throw new \Exception($message); } + public function getMissingMosaicsInFileSystem(Carbon $endDate) + { + return collect($this->getMosaicFilenameListByEndDate($endDate)) + ->filter(function ($filename) { + return !$this->getMosaicList()->contains(function ($mosaicFilename) use ($filename) { + return Str::endsWith($mosaicFilename, substr($filename, -16)); + }); + }); + } + public static function getMosaicFilenameListByEndDate(Carbon $endDate, int $offset=7): \Generator { for ($i = 0; $i < 4; $i++) { diff --git a/laravel_app/app/Rules/AllMosaicsPresentRule.php b/laravel_app/app/Rules/AllMosaicsPresentRule.php index efbfa3f..be0e779 100644 --- a/laravel_app/app/Rules/AllMosaicsPresentRule.php +++ b/laravel_app/app/Rules/AllMosaicsPresentRule.php @@ -4,7 +4,6 @@ use Illuminate\Contracts\Validation\Rule; use App\Models\Project; -use App\Models\ProjectReport; use Carbon\Carbon; class AllMosaicsPresentRule implements Rule diff --git a/laravel_app/resources/views/components/report-manager-properties-modal.blade.php b/laravel_app/resources/views/components/report-manager-properties-modal.blade.php index 0dc619b..3fb323d 100644 --- a/laravel_app/resources/views/components/report-manager-properties-modal.blade.php +++ b/laravel_app/resources/views/components/report-manager-properties-modal.blade.php @@ -1,9 +1,3 @@ -@props([ - 'formData', - /** @var \App\Livewire\Projects\ProjectManager */ - 'reportManager' -]) - @@ -34,7 +28,13 @@ {{ __('Saved.') }} + @error('formData') + Download missing Mosaics + @enderror {{ $report->name }} -{{-- @if($report->status == \App\Enums\Status::Pending)--}} -{{-- --}} -{{-- @else--}} -{{-- --}} -{{-- @endif--}}