diff --git a/laravel_app/app/Livewire/Projects/ProjectManager.php b/laravel_app/app/Livewire/Projects/ProjectManager.php index 21b5726..cc5d322 100644 --- a/laravel_app/app/Livewire/Projects/ProjectManager.php +++ b/laravel_app/app/Livewire/Projects/ProjectManager.php @@ -5,7 +5,7 @@ use App\Models\Project; use App\Models\ProjectBoundingBox; use App\Models\ProjectEmailRecipient; -use Illuminate\Support\Arr; +use App\Rules\HarvestFile; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Livewire\Component; @@ -28,6 +28,11 @@ class ProjectManager extends Component public $projectIdBeingDeleted; public $span_json_path; public $pivot_json_path; + public $harvest_json_path; + + public array $pivotFiles; + public array $spanFiles; + public array $harvestDataFiles; /** * Mount the component. @@ -52,12 +57,13 @@ public function editMailSettings(Project $project) $this->loadFormData($project); } - private function loadFormData(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->harvest_json_path = $this->formData['harvest_json_path']; $this->formData['span_json_path'] = null; $this->formData['boundingBoxes'] = $project->boundingBoxes->toArray(); $this->formData['mail_recipients'] = $project->emailRecipients->toArray() ?: [ @@ -77,7 +83,7 @@ public function openCreateProjectModal() public function saveProject() { $this->resetErrorBag(); - $this->validateForm(); + dd($this->validateForm()); Project::saveWithFormData($this->formData); $this->resetFormData(); $this->showProjectModal = false; @@ -184,6 +190,7 @@ private function resetFormData() 'name' => '', 'pivot_json_path' => '', 'span_json_path' => '', + 'harvest_json_path' => '', 'boundingBoxes' => [], 'mail_subject' => '', 'mail_template' => '', @@ -191,6 +198,9 @@ private function resetFormData() 'mail_day' => '', 'mail_recipients' => [], ]; + $this->pivotFiles = []; + $this->spanFiles = []; + $this->harvestDataFiles = []; $this->addBoundingBox(); $this->addEmailRecipient(); } @@ -199,10 +209,11 @@ private function validateForm() { $projectIdentifier = $this->formData['id'] ?? null; - Validator::make([ + return Validator::make([ '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'], + 'pivot_file' => $this->pivotFiles[0] ?? null, + 'span_file' => $this->spanFiles[0] ?? null, + 'harvest_data_file' => $this->harvestDataFiles[0] ?? null, 'boundingBoxes' => $this->formData['boundingBoxes'], ], [ 'name' => [ @@ -211,31 +222,16 @@ 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.'); - } - }, - ], + 'pivot_file' => ['sometimes'], + 'span_file' => ['sometimes'], + 'harvestDataFile' => ['sometimes',new HarvestFile], 'boundingBoxes' => ['required', 'array', 'min:1'], 'boundingBoxes.*.name' => ['required', 'string', 'max:255'], 'boundingBoxes.*.top_left_latitude' => ['required', 'string'], 'boundingBoxes.*.top_left_longitude' => ['required', 'string'], 'boundingBoxes.*.bottom_right_latitude' => ['required', 'string'], 'boundingBoxes.*.bottom_right_longitude' => ['required', 'string'], - ])->validateWithBag('saveProject'); + ])->validate(); } private function validateEmailSettingsForm() diff --git a/laravel_app/app/Models/Project.php b/laravel_app/app/Models/Project.php index 544de01..d544e86 100644 --- a/laravel_app/app/Models/Project.php +++ b/laravel_app/app/Models/Project.php @@ -26,6 +26,9 @@ class Project extends Model 'mail_frequency', 'mail_day', 'download_path', + 'pivot_json_path', + 'span_json_path', + 'harvest_json_data' ]; public static function saveWithFormData(mixed $formData) @@ -34,13 +37,15 @@ public static function saveWithFormData(mixed $formData) $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(); + $project->update(['pivot_json_path' => $path]); } 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->update(['span_json_path' => $path]); + } + if ($formData['harvest_json_data']) { + $path = $formData['harvest_json_path']->storeAs($project->download_path .'/Data', 'harvest.xlsx'); + $project->update(['harvest_json_path' => $path]); } $project->upsertBoundingBox($formData); $project->upsertMailRecipients($formData); diff --git a/laravel_app/composer.json b/laravel_app/composer.json index 8de0bf8..2d78ee1 100644 --- a/laravel_app/composer.json +++ b/laravel_app/composer.json @@ -6,6 +6,7 @@ "license": "MIT", "require": { "php": "^8.2", + "dasundev/livewire-dropzone": "^1.0", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^v11.0.7", "laravel/jetstream": "^5.0", diff --git a/laravel_app/composer.lock b/laravel_app/composer.lock index db97e96..a769d7b 100644 --- a/laravel_app/composer.lock +++ b/laravel_app/composer.lock @@ -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": "6c255cb424db38d53bf1b26ce0e9ec53", + "content-hash": "fb3d9bb02b87b8873aec06181a9061d5", "packages": [ { "name": "bacon/bacon-qr-code", @@ -239,6 +239,75 @@ }, "time": "2023-08-25T16:18:39+00:00" }, + { + "name": "dasundev/livewire-dropzone", + "version": "v1.0.10", + "source": { + "type": "git", + "url": "https://github.com/dasundev/livewire-dropzone.git", + "reference": "fddfc9acbd43b6b29be1692b605d911d4e6d5359" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dasundev/livewire-dropzone/zipball/fddfc9acbd43b6b29be1692b605d911d4e6d5359", + "reference": "fddfc9acbd43b6b29be1692b605d911d4e6d5359", + "shasum": "" + }, + "require": { + "livewire/livewire": "^3.0", + "php": "^8.1", + "spatie/laravel-package-tools": "^1.16" + }, + "require-dev": { + "larastan/larastan": "^2.0", + "laravel/pint": "^1.13", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^1.23" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Dasundev\\LivewireDropzone\\LivewireDropzoneServiceProvider" + ], + "aliases": { + "LivewireDropzone": "Dasundev\\LivewireDropzone\\LivewireDropzoneFacade" + } + } + }, + "autoload": { + "psr-4": { + "Dasundev\\LivewireDropzone\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dasun Tharanga", + "email": "hello@dasun.dev", + "role": "Developer" + } + ], + "description": "A Livewire Dropzone component for simple drag-and-drop file uploads.", + "keywords": [ + "dropzone", + "livewire" + ], + "support": { + "issues": "https://github.com/dasundev/livewire-dropzone/issues", + "source": "https://github.com/dasundev/livewire-dropzone/tree/v1.0.10" + }, + "funding": [ + { + "url": "https://github.com/dasundev", + "type": "github" + } + ], + "time": "2024-04-30T01:58:11+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", @@ -3799,6 +3868,66 @@ ], "time": "2024-04-27T21:32:50+00:00" }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.4", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53", + "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0|^11.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.4" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-03-20T07:29:11+00:00" + }, { "name": "symfony/clock", "version": "v7.0.7", @@ -8816,5 +8945,5 @@ "php": "^8.2" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/laravel_app/package-lock.json b/laravel_app/package-lock.json index 11d7f17..1d81b47 100644 --- a/laravel_app/package-lock.json +++ b/laravel_app/package-lock.json @@ -9,6 +9,7 @@ "@alpinejs/focus": "^3.13.3", "@alpinejs/intersect": "^3.13.3", "@alpinejs/ui": "^3.13.3-beta.4", + "@dasundev/livewire-dropzone-styles": "^1.0.7", "@fortawesome/fontawesome-free": "^6.5.2", "@ryangjchandler/alpine-clipboard": "^2.3.0", "@tailwindcss/aspect-ratio": "^0.4.2", @@ -62,6 +63,11 @@ "resolved": "https://registry.npmjs.org/@alpinejs/ui/-/ui-3.13.3-beta.4.tgz", "integrity": "sha512-Dc6j40tELUqSAIg93Dgi+Carkw8MB+YXm0sILD41vkxw0ByHf5pICCBvhxkcVRg2I/2/6YM/W7i1ZUORNEqrgw==" }, + "node_modules/@dasundev/livewire-dropzone-styles": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@dasundev/livewire-dropzone-styles/-/livewire-dropzone-styles-1.0.7.tgz", + "integrity": "sha512-Kd9lGe7qAAm2vc0DsiuzELBnqyNnlNlf9I8Zrdqm0HeD6cvJW1F16Mpl6EEJtR2ZgshTfX/mMvTjgJ5g48jMpg==" + }, "node_modules/@esbuild/android-arm": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", diff --git a/laravel_app/package.json b/laravel_app/package.json index 677a298..b990149 100644 --- a/laravel_app/package.json +++ b/laravel_app/package.json @@ -20,6 +20,7 @@ "@alpinejs/focus": "^3.13.3", "@alpinejs/intersect": "^3.13.3", "@alpinejs/ui": "^3.13.3-beta.4", + "@dasundev/livewire-dropzone-styles": "^1.0.7", "@fortawesome/fontawesome-free": "^6.5.2", "@ryangjchandler/alpine-clipboard": "^2.3.0", "@tailwindcss/aspect-ratio": "^0.4.2", diff --git a/laravel_app/resources/css/app.css b/laravel_app/resources/css/app.css index 7c44ad2..bb05c97 100644 --- a/laravel_app/resources/css/app.css +++ b/laravel_app/resources/css/app.css @@ -1,6 +1,7 @@ @import 'flatpickr/dist/flatpickr.css'; @import url('https://rsms.me/inter/inter.css'); @import '@fortawesome/fontawesome-free/css/all.css'; +@import "@dasundev/livewire-dropzone-styles"; @tailwind base; @tailwind components; @tailwind utilities; diff --git a/laravel_app/resources/views/components/form-modal.blade.php b/laravel_app/resources/views/components/form-modal.blade.php index 3acda87..94c7bd4 100644 --- a/laravel_app/resources/views/components/form-modal.blade.php +++ b/laravel_app/resources/views/components/form-modal.blade.php @@ -8,7 +8,7 @@