[done] Notification downloads
This commit is contained in:
parent
9d744a95a2
commit
355dbfe984
|
|
@ -2,14 +2,45 @@
|
||||||
|
|
||||||
namespace App\Livewire\Components;
|
namespace App\Livewire\Components;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class DownloadNotification extends Component
|
class DownloadNotification extends Component
|
||||||
{
|
{
|
||||||
public $show_download_notification;
|
public $show_download_notification;
|
||||||
|
public Project $project;
|
||||||
|
|
||||||
public function render()
|
public function mount(Project $project)
|
||||||
{
|
{
|
||||||
return view('livewire.components.download-notification');
|
$this->show_download_notification = session()->get('show-download.'.$project->id,false);
|
||||||
|
$this->project = $project;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSessionKey()
|
||||||
|
{
|
||||||
|
return 'show-download.'.$this->project->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[On('download_notify')]
|
||||||
|
public function open()
|
||||||
|
{
|
||||||
|
$this->show_download_notification = true;
|
||||||
|
session([$this->getSessionKey()=>true]);
|
||||||
|
}
|
||||||
|
public function close(): void
|
||||||
|
{
|
||||||
|
$this->show_download_notification = false;
|
||||||
|
session([$this->getSessionKey()=>false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startDownloads()
|
||||||
|
{
|
||||||
|
$this->project->handleMissingDownloads();
|
||||||
|
$this->close();
|
||||||
|
$this->dispatch('notify',message:'Downloads added to the queue.',type:'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,10 @@
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\ProjectEmailRecipient;
|
use App\Models\ProjectEmailRecipient;
|
||||||
use App\Rules\HarvestFile;
|
use App\Rules\HarvestFile;
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\WithFileUploads;
|
use Livewire\WithFileUploads;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
|
|
||||||
|
|
||||||
class ProjectManager extends Component
|
class ProjectManager extends Component
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,6 @@ class Settings extends Component
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function mount(Project $project)
|
public function mount(Project $project)
|
||||||
{
|
|
||||||
$this->loadFormData($project);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadFormData(Project $project)
|
|
||||||
{
|
{
|
||||||
$this->formData = $project->toArray();
|
$this->formData = $project->toArray();
|
||||||
$this->formData['mail_recipients'] = $project->emailRecipients->toArray() ?: [
|
$this->formData['mail_recipients'] = $project->emailRecipients->toArray() ?: [
|
||||||
|
|
@ -84,8 +79,10 @@ public function saveSettings()
|
||||||
$this->validateEmailSettingsForm();
|
$this->validateEmailSettingsForm();
|
||||||
$this->shouldReload();
|
$this->shouldReload();
|
||||||
Project::saveWithFormData($this->formData);
|
Project::saveWithFormData($this->formData);
|
||||||
|
$this->shouldDownload();
|
||||||
|
//check if the project name changed
|
||||||
if($this->isDirty) redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']);
|
if($this->isDirty) redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']);
|
||||||
$this->dispatch('download_notify',title:'Download',message:'hallo');
|
// $this->dispatch('download_notify',title:'Download',message:'hallo');
|
||||||
$this->dispatch('saved');
|
$this->dispatch('saved');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,8 +91,16 @@ public function shouldReload()
|
||||||
if (Project::find($this->formData['id'])?->name == $this->formData['name']) return;
|
if (Project::find($this->formData['id'])?->name == $this->formData['name']) return;
|
||||||
$this->isDirty = true;
|
$this->isDirty = true;
|
||||||
}
|
}
|
||||||
|
public function shouldDownload(){
|
||||||
|
/**
|
||||||
|
* @var Project $project
|
||||||
|
*/
|
||||||
|
$project = Project::find($this->formData['id']);
|
||||||
|
if($project->hasMissingDownloadsDateInHarvestFile()){
|
||||||
|
$this->dispatch('download_notify');
|
||||||
|
session(['show-download.'.$project->id=>true]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function addEmailRecipient()
|
public function addEmailRecipient()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,11 @@ public function downloads(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
return $this->hasMany(ProjectDownload::class);
|
return $this->hasMany(ProjectDownload::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function nonFailedDownloads(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProjectDownload::class)->where('status','<>','failed');
|
||||||
|
}
|
||||||
|
|
||||||
public function mosaics(): \Illuminate\Database\Eloquent\Relations\HasMany
|
public function mosaics(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(ProjectMosaic::class);
|
return $this->hasMany(ProjectMosaic::class);
|
||||||
|
|
@ -343,6 +348,29 @@ public function getMosaicsFor(Carbon $endDate, int $offset= 7): array
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleMissingDownloads()
|
||||||
|
{
|
||||||
|
$this->getMissingDownloadsDateInHarvestFile()
|
||||||
|
->each(function(Carbon $date){
|
||||||
|
ProjectDownloadTiffJob::handleForDate($this,$date);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasMissingDownloadsDateInHarvestFile():bool
|
||||||
|
{
|
||||||
|
return $this->getMissingDownloadsDateInHarvestFile()->count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMissingDownloadsDateInHarvestFile()
|
||||||
|
{
|
||||||
|
if(!$this->harvest_json_path || !$this->min_harvest_date){
|
||||||
|
return collect([]);
|
||||||
|
}
|
||||||
|
$harvest_dates = $this->nonFailedDownloads()->get()->map(fn($d)=>$d->date);
|
||||||
|
$all_dates = collect(CarbonPeriod::create($this->min_harvest_date,'1 day',now())->toArray());
|
||||||
|
return $all_dates->diff($harvest_dates);
|
||||||
|
}
|
||||||
|
|
||||||
public function setMinHarvestDate():bool
|
public function setMinHarvestDate():bool
|
||||||
{
|
{
|
||||||
if(!$this->harvest_json_path){
|
if(!$this->harvest_json_path){
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Query\Builder;
|
||||||
|
|
||||||
class ProjectDownload extends Model
|
class ProjectDownload extends Model
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,6 @@
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
<x-notification />
|
<x-notification />
|
||||||
<livewire:components.download-notification></livewire:components.download-notification>
|
|
||||||
|
|
||||||
@stack('modals')
|
@stack('modals')
|
||||||
@stack('map')
|
@stack('map')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
<!-- Global notification live region, render this permanently at the end of the document -->
|
|
||||||
<div aria-live="assertive" class="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6"
|
<div aria-live="assertive" class="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6"
|
||||||
x-data="{
|
x-data="{
|
||||||
open: $wire.entangle('show_download_notification').live,
|
open: $wire.entangle('show_download_notification').live,
|
||||||
message: 'If you see this, a notification has been triggered.',
|
title: '@lang("Download Missing TIF for ".$project->name)',
|
||||||
title: 'Download Notification'
|
message: '@lang("Some TIF images are missing for this dataset, would you like to download them ?")'
|
||||||
|
|
||||||
}"
|
}"
|
||||||
x-show="open"
|
x-show="open"
|
||||||
x-cloak
|
x-cloak
|
||||||
@download_notify.window="message = event.detail.message; title = event.detail.title;open = true;"
|
|
||||||
>
|
>
|
||||||
|
|
||||||
<div class="flex w-full flex-col items-center space-y-4 sm:items-end"
|
<div class="flex w-full flex-col items-center space-y-4 sm:items-end"
|
||||||
|
|
@ -31,9 +29,11 @@
|
||||||
<p class="text-sm font-medium text-gray-900" x-cloak x-text="title"></p>
|
<p class="text-sm font-medium text-gray-900" x-cloak x-text="title"></p>
|
||||||
<p class="mt-1 text-sm text-gray-500" x-cloak x-text="message"></p>
|
<p class="mt-1 text-sm text-gray-500" x-cloak x-text="message"></p>
|
||||||
<div class="mt-4 flex">
|
<div class="mt-4 flex">
|
||||||
<button type="button" class="inline-flex items-center rounded-md bg-indigo-600 px-2.5 py-1.5 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">Accept</button>
|
<button type="button" class="inline-flex items-center rounded-md bg-indigo-600 px-2.5 py-1.5 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"
|
||||||
|
@click="$wire.startDownloads();"
|
||||||
|
>Accept</button>
|
||||||
<button type="button" class="ml-3 inline-flex items-center rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
<button type="button" class="ml-3 inline-flex items-center rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||||
@click="open=false"
|
@click="$wire.close();"
|
||||||
>Decline</button>
|
>Decline</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,6 @@
|
||||||
<div class="flex w-full h-screen justify-center items-center"> Menu Component not found.</div>
|
<div class="flex w-full h-screen justify-center items-center"> Menu Component not found.</div>
|
||||||
@endswitch
|
@endswitch
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<livewire:components.download-notification :project="$project"/>
|
||||||
</x-app-layout>
|
</x-app-layout>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue