[done] Download button when the mosaics are missing in reports tab.
This commit is contained in:
parent
c8f79846b4
commit
69233b58fe
|
|
@ -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']);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectReport;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class AllMosaicsPresentRule implements Rule
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
@props([
|
||||
'formData',
|
||||
/** @var \App\Livewire\Projects\ProjectManager */
|
||||
'reportManager'
|
||||
])
|
||||
|
||||
<x-modal wire:model.live="showReportModal" {{ $attributes }} >
|
||||
<x-form-modal submit="saveProjectReport" wire:loading.class="opacity-50">
|
||||
<x-slot name="title">
|
||||
|
|
@ -34,7 +28,13 @@
|
|||
<x-action-message class="mr-3" on="saved">
|
||||
{{ __('Saved.') }}
|
||||
</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"
|
||||
type="button"
|
||||
x-on:click="$wire.showReportModal = false"
|
||||
|
|
|
|||
|
|
@ -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 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>
|
||||
</td>
|
||||
<td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 lg:pr-8 flex justify-end">
|
||||
|
|
|
|||
Loading…
Reference in a new issue