[done] Download button when the mosaics are missing in reports tab.

This commit is contained in:
guillaume91 2024-06-20 14:59:59 +02:00
parent c8f79846b4
commit 69233b58fe
5 changed files with 27 additions and 20 deletions

View file

@ -2,11 +2,14 @@
namespace App\Livewire\Projects\Tabs; namespace App\Livewire\Projects\Tabs;
use App\Jobs\ProjectMosiacGeneratorJob;
use App\Jobs\ProjectReportGeneratorJob; use App\Jobs\ProjectReportGeneratorJob;
use App\Models\Project; use App\Models\Project;
use App\Models\ProjectMosaic;
use App\Models\ProjectReport; use App\Models\ProjectReport;
use App\Rules\AllMosaicsPresentRule; use App\Rules\AllMosaicsPresentRule;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Str;
use Livewire\Attributes\Reactive; use Livewire\Attributes\Reactive;
use Livewire\Component; use Livewire\Component;
use Livewire\WithPagination; use Livewire\WithPagination;
@ -105,4 +108,11 @@ public function render()
return view('livewire.projects.tabs.report') return view('livewire.projects.tabs.report')
->with(compact('reports')); ->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']);
}
} }

View file

@ -132,14 +132,7 @@ public function allMosaicsPresent(Carbon $endDate): bool
if ($endDate->isFuture()) { if ($endDate->isFuture()) {
throw new \Exception('Mosaic can\'t be generated for the future. Change the end date.'); throw new \Exception('Mosaic can\'t be generated for the future. Change the end date.');
} }
$mosaicsNotPresentInFilesystem = $this->getMissingMosaicsInFileSystem($endDate);
$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));
});
});
if ($mosaicsNotPresentInFilesystem->count() === 0) { if ($mosaicsNotPresentInFilesystem->count() === 0) {
return true; return true;
} }
@ -150,6 +143,16 @@ public function allMosaicsPresent(Carbon $endDate): bool
throw new \Exception($message); 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 public static function getMosaicFilenameListByEndDate(Carbon $endDate, int $offset=7): \Generator
{ {
for ($i = 0; $i < 4; $i++) { for ($i = 0; $i < 4; $i++) {

View file

@ -4,7 +4,6 @@
use Illuminate\Contracts\Validation\Rule; use Illuminate\Contracts\Validation\Rule;
use App\Models\Project; use App\Models\Project;
use App\Models\ProjectReport;
use Carbon\Carbon; use Carbon\Carbon;
class AllMosaicsPresentRule implements Rule class AllMosaicsPresentRule implements Rule

View file

@ -1,9 +1,3 @@
@props([
'formData',
/** @var \App\Livewire\Projects\ProjectManager */
'reportManager'
])
<x-modal wire:model.live="showReportModal" {{ $attributes }} > <x-modal wire:model.live="showReportModal" {{ $attributes }} >
<x-form-modal submit="saveProjectReport" wire:loading.class="opacity-50"> <x-form-modal submit="saveProjectReport" wire:loading.class="opacity-50">
<x-slot name="title"> <x-slot name="title">
@ -34,7 +28,13 @@
<x-action-message class="mr-3" on="saved"> <x-action-message class="mr-3" on="saved">
{{ __('Saved.') }} {{ __('Saved.') }}
</x-action-message> </x-action-message>
@error('formData')
<x-button
class="mr-3 flex justify-center rounded-md bg-indigo-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
x-on:click="$wire.call('getMissingMosaicsInFileSystem',parseInt($wire.formData.offset))"
>Download missing Mosaics</x-button>
@enderror
<x-secondary-button class="mr-3" <x-secondary-button class="mr-3"
type="button" type="button"
x-on:click="$wire.showReportModal = false" x-on:click="$wire.showReportModal = false"

View file

@ -5,11 +5,6 @@
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6 lg:pl-8">{{ $report->name }}</td> <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6 lg:pl-8">{{ $report->name }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"> <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
{{-- @if($report->status == \App\Enums\Status::Pending)--}}
{{-- <x-badge status="pending" wire:poll.1s=""></x-badge>--}}
{{-- @else--}}
{{-- <x-badge :status="$report->status"></x-badge>--}}
{{-- @endif--}}
<livewire:components.badge :status="$report->status" :id="$report->id" :type="'report'" wire:key="{{$report->id}}"></livewire:components.badge> <livewire:components.badge :status="$report->status" :id="$report->id" :type="'report'" wire:key="{{$report->id}}"></livewire:components.badge>
</td> </td>
<td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 lg:pr-8 flex justify-end"> <td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 lg:pr-8 flex justify-end">