67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Projects;
|
|
|
|
use App\Jobs\ProjectMosiacGeneratorJob;
|
|
use App\Models\Project;
|
|
use Livewire\Component;
|
|
|
|
class MosaicManager extends Component
|
|
{
|
|
public $project;
|
|
|
|
public $formData = [
|
|
'week' => '',
|
|
'year' => '',
|
|
];
|
|
public $showCreateModal = false;
|
|
|
|
public function mount(Project $project) {
|
|
$this->path = $project->download_path;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.projects.mosaic-manager', [
|
|
'downloads' => $this->project
|
|
]);
|
|
}
|
|
|
|
public function saveMosaic(){
|
|
$this->validate([
|
|
'formData.year' => 'required',
|
|
'formData.week' => 'required',
|
|
]);
|
|
|
|
$mosaic = $this->project->mosaics()->updateOrCreate([
|
|
'name' => sprintf('Week %s, %s', $this->formData['week'], $this->formData['year']),
|
|
'year' => $this->formData['year'],
|
|
'week' => $this->formData['week'],
|
|
],[
|
|
'path' => $this->project->getMosaicPath(),
|
|
]);
|
|
|
|
ProjectMosiacGeneratorJob::dispatch($mosaic);
|
|
|
|
$this->showCreateModal = false;
|
|
}
|
|
|
|
public function openCreateMosiacsModal(){
|
|
$this->showCreateModal = true;
|
|
}
|
|
|
|
public function getDateRangeProperty()
|
|
{
|
|
if (empty($this->formData['week']) || strlen($this->formData['year']) !== 4) {
|
|
return '<span class="text-red-500">Invalid week or year</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');
|
|
}
|
|
}
|