added fileuploads for pivot and span geojson to project-manager changes to make directory structure project independent

This commit is contained in:
Martin Folkerts 2024-03-04 21:54:10 +01:00
parent a976350ce5
commit 0095b5de7a
15 changed files with 229 additions and 126 deletions

View file

@ -36,11 +36,14 @@ public function __construct(ProjectDownload $download, Carbon $date,)
*/
public function handle(): void
{
logger(json_encode($this->download->project->getBoundingBoxesAsArray()));
$command = [
sprintf('%srunpython.sh', base_path('../')),
sprintf('--date=%s', $this->date->format('Y-m-d')),
sprintf('--days=%d', $this->days),
sprintf('--project_dir=%s', $this->download->project->download_path),
sprintf('--bbox=%s', json_encode($this->download->project->getBoundingBoxesAsArray())),
];
$process = new Process($command);

View file

@ -44,9 +44,9 @@ public function handle(): void
$command = [
sprintf('%sbuild_mosaic.sh', $projectFolder),
sprintf('--weeks_ago=%s', $weeksAgo),
sprintf('--data_dir=%s', $this->mosaic->project->download_path),
];
$process = new Process($command);
$process->setTimeout(220);
$currentPath = '/usr/bin:/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin/Users/mfolkerts/anaconda3/bin:/Library/Apple/usr/bin';

View file

@ -5,12 +5,15 @@
use App\Models\Project;
use App\Models\ProjectBoundingBox;
use App\Models\ProjectEmailRecipient;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Livewire\Component;
use Livewire\WithFileUploads;
class ProjectManager extends Component
{
use WithFileUploads;
public $formData = [];
@ -23,6 +26,8 @@ class ProjectManager extends Component
public $showMailSettingsModal = false;
public $projectIdBeingDeleted;
public $span_json_path;
public $pivot_json_path;
/**
* Mount the component.
@ -34,6 +39,7 @@ public function mount()
$this->resetFormData();
}
public function editProject(Project $project)
{
$this->showProjectModal = true;
@ -49,6 +55,10 @@ public function editMailSettings(Project $project)
private function loadFormData(Project $project)
{
$this->formData = $project->toArray();
$this->pivot_json_path = $this->formData['pivot_json_path'];
$this->formData['pivot_json_path'] = null;
$this->span_json_path = $this->formData['span_json_path'];
$this->formData['span_json_path'] = null;
$this->formData['boundingBoxes'] = $project->boundingBoxes->toArray();
$this->formData['mail_recipients'] = $project->emailRecipients->toArray() ?: [
[
@ -172,6 +182,8 @@ private function resetFormData()
{
$this->formData = [
'name' => '',
'pivot_json_path' => '',
'span_json_path' => '',
'boundingBoxes' => [],
'mail_subject' => '',
'mail_template' => '',
@ -188,8 +200,10 @@ private function validateForm()
$projectIdentifier = $this->formData['id'] ?? null;
Validator::make([
'name' => $this->formData['name'],
'boundingBoxes' => $this->formData['boundingBoxes'],
'name' => $this->formData['name'],
'pivot_json_path' => $this->formData['pivot_json_path'], // TODO: 'required|file|mimes:csv,txt|max:2048
'span_json_path' => $this->formData['span_json_path'],
'boundingBoxes' => $this->formData['boundingBoxes'],
], [
'name' => [
'required',
@ -197,6 +211,24 @@ private function validateForm()
'string',
'max:255'
],
'pivot_json_path' => [
function ($attribute, $value, $fail) {
if ($value && !is_file($value->getRealPath())) {
$fail($attribute.' is geen geldig bestand.');
} elseif ($value && !in_array(mime_content_type($value->getRealPath()), ['application/json'])) {
$fail($attribute.' moet een JSON-bestand zijn.');
}
},
],
'span_json_path' => [
function ($attribute, $value, $fail) {
if ($value && !is_file($value->getRealPath())) {
$fail($attribute.' is geen geldig bestand.');
} elseif ($value && !in_array(mime_content_type($value->getRealPath()), ['application/json'])) {
$fail($attribute.' moet een JSON-bestand zijn.');
}
},
],
'boundingBoxes' => ['required', 'array', 'min:1'],
'boundingBoxes.*.name' => ['required', 'string', 'max:255'],
'boundingBoxes.*.top_left_latitude' => ['required', 'string'],

View file

@ -32,6 +32,16 @@ public static function saveWithFormData(mixed $formData)
{
$uniqueIdentifier = ['id' => $formData['id'] ?? null];
$project = Project::updateOrCreate($uniqueIdentifier, $formData);
if ($formData['pivot_json_path']) {
$path = $formData['pivot_json_path']->storeAs($project->download_path .'/Data', 'pivot.geojson');
$project->pivot_json_path = $path;
$project->save();
}
if ($formData['span_json_path']) {
$path = $formData['span_json_path']->storeAs($project->download_path .'/Data', 'span.geojson');
$project->pivot_json_path = $path;
$project->save();
}
$project->upsertBoundingBox($formData);
$project->upsertMailRecipients($formData);
}
@ -271,6 +281,7 @@ public function schedule()
if ($this->shouldSchedule()) {
$this->scheduleReport();
}
}
public function shouldSchedule(): bool
@ -354,4 +365,10 @@ public function getMosaicsFor($year, $startWeekNumber)
return $return;
}
public function getBoundingBoxesAsArray() {
return $this->boundingBoxes->map(function ($boundingBox) {
return $boundingBox->toArrayCustom();
})->toArray();
}
}

View file

@ -21,4 +21,14 @@ public function project()
{
return $this->belongsTo(Project::class);
}
public function toArrayCustom()
{
return [
(float) $this->top_left_latitude,
(float) $this->top_left_longitude,
(float) $this->bottom_right_latitude,
(float) $this->bottom_right_longitude
];
}
}

View file

@ -6,15 +6,15 @@
"license": "MIT",
"require": {
"php": "^8.1",
"fakerphp/faker": "^1.9.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/jetstream": "^4.0",
"laravel/sanctum": "^3.2",
"laravel/telescope": "^4.17",
"laravel/tinker": "^2.8",
"queueworker/sansdaemon": "^1.2",
"fakerphp/faker": "^1.9.1",
"livewire/livewire": "^3.0"
"livewire/livewire": "^3.0",
"queueworker/sansdaemon": "^1.2"
},
"require-dev": {
"laravel/pint": "^1.0",

View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a5ff3fc4e2c8e72915f0398a574a4266",
"content-hash": "5c4b061866dd522ed729de3174d05b6b",
"packages": [
{
"name": "bacon/bacon-qr-code",

View file

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->string('pivot_json_path')->nullable();
$table->string('span_json_path')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->dropColumn('pivot_json_path');
});
}
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,11 +1,11 @@
{
"resources/css/app.css": {
"file": "assets/app-3d9a9513.css",
"file": "assets/app-2148f347.css",
"isEntry": true,
"src": "resources/css/app.css"
},
"resources/js/alpine.js": {
"file": "assets/alpine-25cbe97a.js",
"file": "assets/alpine-b920cb4b.js",
"isDynamicEntry": true,
"src": "resources/js/alpine.js"
},
@ -13,7 +13,7 @@
"dynamicImports": [
"resources/js/alpine.js"
],
"file": "assets/app-e02e5043.js",
"file": "assets/app-fef3848d.js",
"isEntry": true,
"src": "resources/js/app.js"
}

View file

@ -21,6 +21,18 @@
<x-input id="name" type="text" class="mt-1 block w-full" wire:model="formData.name" autofocus/>
<x-input-error for="name" class="mt-2"/>
</div>
<div class="col-span-6 sm:col-span-4">
<label for="pivot_json_path">Pivot geojson File</label>
<input type="file" id="pivot_json_path" wire:model="formData.pivot_json_path">
<x-input-error for="pivot_json_path" class="mt-2"/>
<label>{{ $projectManager->pivot_json_path }}</label>
</div>
<div class="col-span-6 sm:col-span-4">
<label for="span_json_path">Span geojson File</label>
<input type="file" id="span_json_path" wire:model="formData.span_json_path">
<x-input-error for="span_json_path" class="mt-2"/>
<label>{{ $projectManager->span_json_path }}</label>
</div>
@foreach($projectManager->formData['boundingBoxes'] as $key => $boundingBox)
{{-- <div wire:key="bounding_box_{{ $key }}">--}}
<div class="col-span-6 sm:col-span-4">