[Done] Updated classes with a range instead of week - year
This commit is contained in:
parent
76d4babd98
commit
ecc1a9a47b
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use App\Jobs\ProjectMosiacGeneratorJob;
|
||||
use App\Models\Project;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
|
|
@ -14,8 +15,8 @@ class Mosaic extends Component
|
|||
public Project $project;
|
||||
|
||||
public $formData = [
|
||||
'week' => '',
|
||||
'year' => '',
|
||||
'end_date' => '',
|
||||
'offset' => '7',
|
||||
];
|
||||
public $showCreateModal = false;
|
||||
|
||||
|
|
@ -27,18 +28,19 @@ class Mosaic extends Component
|
|||
public function mount(Project $project)
|
||||
{
|
||||
$this->path = $project->download_path;
|
||||
$this->formData['end_date'] = Carbon::yesterday()->toDateString();
|
||||
}
|
||||
public function saveMosaic()
|
||||
{
|
||||
$this->validate([
|
||||
'formData.year' => 'required',
|
||||
'formData.week' => 'required',
|
||||
'formData.end_date' => ['required','date','before:today'],
|
||||
'formData.offset' => 'required|integer|min:1|max:1000',
|
||||
]);
|
||||
|
||||
$mosaic = $this->project->mosaics()->updateOrCreate([
|
||||
'name' => sprintf('Week %s, %s', $this->formData['week'], $this->formData['year']),
|
||||
'year' => $this->formData['year'],
|
||||
'week' => $this->formData['week'],
|
||||
'name' => sprintf('', $this->formData['end_date'], $this->formData['offset']),
|
||||
'offset' => $this->formData['offset'],
|
||||
'end_date' => $this->formData['end_date'],
|
||||
], [
|
||||
'path' => $this->project->getMosaicPath(),
|
||||
]);
|
||||
|
|
@ -55,24 +57,20 @@ public function openCreateMosiacsModal()
|
|||
|
||||
public function getDateRangeProperty()
|
||||
{
|
||||
if (empty($this->formData['week']) || strlen($this->formData['year']) !== 4) {
|
||||
return '<span class="text-red-500">Invalid week or year</span>';
|
||||
if (!$this->formData['end_date'] || !$this->formData['offset']) {
|
||||
return '<span class="text-red-500">Please give a correct date or offset</span>';
|
||||
}
|
||||
$begin = now()
|
||||
->setISODate($this->formData['year'], $this->formData['week'])
|
||||
->startOfWeek();
|
||||
$end = now()
|
||||
->setISODate($this->formData['year'], $this->formData['week'])
|
||||
->endOfWeek();
|
||||
return $begin->format('Y-m-d').' - '.$end->format('Y-m-d');
|
||||
$start = (new Carbon($this->formData['end_date']))->subDays($this->formData['offset']-1);
|
||||
$end = new Carbon($this->formData['end_date']);
|
||||
return 'from '.$start->format('Y-m-d').' to '.$end->format('Y-m-d');
|
||||
}
|
||||
|
||||
private function applySearch($query)
|
||||
{
|
||||
return $query->when($this->search !== '', function ($q){
|
||||
$q->where('name', 'like', '%'.$this->search.'%')
|
||||
->orWhere('year', 'like', '%' . $this->search . '%')
|
||||
->orWhere('week', 'like', '%' . $this->search . '%');
|
||||
->orWhere('offset', 'like', '%' . $this->search . '%')
|
||||
->orWhere('end_date', 'like', '%' . $this->search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -86,8 +84,8 @@ public function update($property)
|
|||
public function render()
|
||||
{
|
||||
$query = $this->project->mosaics()
|
||||
->orderBy('year', 'desc')
|
||||
->orderBy('week', 'desc');
|
||||
->orderBy('offset', 'desc')
|
||||
->orderBy('end_date', 'desc');
|
||||
$query = $this->applySearch($query);
|
||||
$mosaics = $query->paginate(10, pageName: 'mosaicPage');
|
||||
|
||||
|
|
|
|||
|
|
@ -22,13 +22,14 @@ class ProjectMosaic extends Model
|
|||
'week',
|
||||
'year',
|
||||
'end_date',
|
||||
'offset',
|
||||
'status'
|
||||
];
|
||||
|
||||
|
||||
public static function getFilenameByPeriod(Carbon $endDate,int $offset)
|
||||
{
|
||||
return sprintf('period_%s_%s.tif',(clone $endDate)->subdays($offset-1)->format('Y-m-d'),$endDate->format('Y-m-d'));
|
||||
return sprintf('period_%s_%s.tif',(clone $endDate)->subdays($offset)->format('Y-m-d'),$endDate->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function project()
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ public function passes($attribute, $value)
|
|||
}
|
||||
|
||||
return $project->allMosaicsPresent(
|
||||
ProjectReport::getReportDateForYearAndWeek($project, $value['year'], $value['week'])
|
||||
// TODO change with end_date.
|
||||
$value['end_date']
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->errorMessage = $e->getMessage();
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@
|
|||
|
||||
<x-slot name="form">
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<x-label for="year" value="{{ __('Year') }}"/>
|
||||
<x-input id="year" type="number" min="1900" max="{{\Carbon\Carbon::now()->year}}" class="mt-1 block w-full" wire:model.live="formData.year" autofocus/>
|
||||
<x-input-error for="formData.year" class="mt-2"/>
|
||||
<x-label for="end_date" value="{{ __('Date') }}"/>
|
||||
<x-input id="end_date" type="date" max="{{\Carbon\Carbon::yesterday()->toDateString()}}" class="mt-1 block w-full" wire:model.live="formData.end_date" autofocus/>
|
||||
<x-input-error for="formData.end_date" class="mt-2"/>
|
||||
</div><div class="col-span-6 sm:col-span-4">
|
||||
<x-label for="week" value="{{ __('Week') }}"/>
|
||||
<x-input id="week" type="number" min="1" max="53" class="mt-1 block w-full" wire:model.live="formData.week" autofocus/>
|
||||
<x-input-error for="formData.week" class="mt-2"/>
|
||||
<x-label for="offset" value="{{ __('Offset') }}"/>
|
||||
<x-input id="offset" type="number" min="1" max="1000" placeholder="{{__('Number of days used to generate the mosaic (7 by default)')}}" class="mt-1 block w-full" wire:model.live="formData.offset" autofocus/>
|
||||
<x-input-error for="formData.offset" class="mt-2"/>
|
||||
<x-input-error for="formData" class="mt-2"/>
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -22,10 +22,16 @@ class="justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold t
|
|||
<tr>
|
||||
<th scope="col"
|
||||
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6 lg:pl-8">
|
||||
Name
|
||||
{{__('Name')}}
|
||||
</th>
|
||||
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
|
||||
Year-Week
|
||||
{{__('Start')}}
|
||||
</th>
|
||||
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
|
||||
{{__('End')}}
|
||||
</th>
|
||||
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
|
||||
{{__('Range (days)')}}
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900 sm:pr-8 lg:pr-8">
|
||||
|
|
@ -38,7 +44,13 @@ class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900 sm:pr-8 lg:pr-
|
|||
<tr>
|
||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6 lg:pl-8">{{ $mosaic->name }}</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
{{ $mosaic->year }}-{{ $mosaic->week}}
|
||||
{{ $mosaic->end_date->copy()->subDays($mosaic->offset)->format('Y-m-d') }}
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
{{ $mosaic->end_date->format('Y-m-d') }}
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
{{ $mosaic->offset }}
|
||||
</td>
|
||||
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 lg:pr-8">
|
||||
<livewire:components.badge :status="$mosaic->status" :id="$mosaic->id" type="mosaic" wire:key="{{$mosaic->id}}"></livewire:components.badge>
|
||||
|
|
@ -52,7 +64,6 @@ class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900 sm:pr-8 lg:pr-
|
|||
<div class="text-gray-700 text-sm">
|
||||
Results: {{ \Illuminate\Support\Number::format($mosaics->total()) }}
|
||||
</div>
|
||||
|
||||
{{ $mosaics->links('livewire.pagination') }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue