From 486476d326c0e465ab7754426fe8cde69f0fe9df Mon Sep 17 00:00:00 2001 From: Martin Folkerts Date: Wed, 22 Nov 2023 20:01:12 +0100 Subject: [PATCH] wip --- laravel_app/app/Helper.php | 27 ++ .../Http/Controllers/ProjectController.php | 6 + .../app/Livewire/Projects/DownloadManager.php | 21 ++ .../app/Livewire/Projects/MailingManager.php | 23 ++ .../app/Livewire/Projects/ProjectManager.php | 163 ++++++++---- .../app/Livewire/Projects/ReportManager.php | 13 + laravel_app/app/Models/Project.php | 74 ++++++ laravel_app/app/Models/ProjectDownload.php | 11 + .../app/Models/ProjectEmailRecipient.php | 16 ++ laravel_app/app/Models/ProjectMailing.php | 31 +++ .../app/Models/ProjectMailingAttachment.php | 16 ++ .../app/Models/ProjectMailingRecipient.php | 11 + ...023_11_07_154128_create_projects_table.php | 5 +- ..._create_project_email_recipients_table.php | 31 +++ ...1_125040_create_project_mailings_table.php | 31 +++ ...reate_project_mailing_recipients_table.php | 30 +++ ...eate_project_mailing_attachments_table.php | 30 +++ ..._142339_create_project_downloads_table.php | 30 +++ .../database/seeders/DatabaseSeeder.php | 243 +++++++++++++++++- .../views/components/form-modal.blade.php | 25 ++ .../views/components/modal.blade.php | 2 + ...anager-delete-confirmation-modal.blade.php | 19 ++ .../components/project-manager-grid.blade.php | 45 ++++ ...ject-manager-mail-settings-modal.blade.php | 104 ++++++++ ...project-manager-properties-modal.blade.php | 106 ++++++++ .../views/components/tab-section.blade.php | 23 ++ .../views/livewire/project-manager.blade.php | 166 +----------- .../projects/download-manager.blade.php | 16 ++ .../projects/mailing-manager.blade.php | 40 +++ .../projects/report-manager.blade.php | 9 + .../resources/views/projects/show.blade.php | 68 +++++ laravel_app/routes/web.php | 3 +- 32 files changed, 1219 insertions(+), 219 deletions(-) create mode 100644 laravel_app/app/Helper.php create mode 100644 laravel_app/app/Livewire/Projects/DownloadManager.php create mode 100644 laravel_app/app/Livewire/Projects/MailingManager.php create mode 100644 laravel_app/app/Livewire/Projects/ReportManager.php create mode 100644 laravel_app/app/Models/ProjectDownload.php create mode 100644 laravel_app/app/Models/ProjectEmailRecipient.php create mode 100644 laravel_app/app/Models/ProjectMailing.php create mode 100644 laravel_app/app/Models/ProjectMailingAttachment.php create mode 100644 laravel_app/app/Models/ProjectMailingRecipient.php create mode 100644 laravel_app/database/migrations/2023_11_20_103515_create_project_email_recipients_table.php create mode 100644 laravel_app/database/migrations/2023_11_21_125040_create_project_mailings_table.php create mode 100644 laravel_app/database/migrations/2023_11_21_125712_create_project_mailing_recipients_table.php create mode 100644 laravel_app/database/migrations/2023_11_21_125723_create_project_mailing_attachments_table.php create mode 100644 laravel_app/database/migrations/2023_11_21_142339_create_project_downloads_table.php create mode 100644 laravel_app/resources/views/components/form-modal.blade.php create mode 100644 laravel_app/resources/views/components/project-manager-delete-confirmation-modal.blade.php create mode 100644 laravel_app/resources/views/components/project-manager-grid.blade.php create mode 100644 laravel_app/resources/views/components/project-manager-mail-settings-modal.blade.php create mode 100644 laravel_app/resources/views/components/project-manager-properties-modal.blade.php create mode 100644 laravel_app/resources/views/components/tab-section.blade.php create mode 100644 laravel_app/resources/views/livewire/projects/download-manager.blade.php create mode 100644 laravel_app/resources/views/livewire/projects/mailing-manager.blade.php create mode 100644 laravel_app/resources/views/livewire/projects/report-manager.blade.php create mode 100644 laravel_app/resources/views/projects/show.blade.php diff --git a/laravel_app/app/Helper.php b/laravel_app/app/Helper.php new file mode 100644 index 0000000..e4e6689 --- /dev/null +++ b/laravel_app/app/Helper.php @@ -0,0 +1,27 @@ +startOfWeek(); + + $daysOfWeek = collect([]); + for ($i = 0; $i < 7; $i++) { + $daysOfWeek->add($startOfWeek->copy()->addDays($i)->format('l')); + } + + return $daysOfWeek; + } + + public static function getMailFrequencies(): \Illuminate\Support\Collection + { + return collect([ + 'Weekly', + 'Monthly', + ]); + } + +} diff --git a/laravel_app/app/Http/Controllers/ProjectController.php b/laravel_app/app/Http/Controllers/ProjectController.php index 703da34..ad96032 100644 --- a/laravel_app/app/Http/Controllers/ProjectController.php +++ b/laravel_app/app/Http/Controllers/ProjectController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Project; use Illuminate\Http\Request; class ProjectController extends Controller @@ -10,5 +11,10 @@ public function index() { return view('projects.index'); } + + public function show(Project $project) + { + return view('projects.show', compact('project')); + } // } diff --git a/laravel_app/app/Livewire/Projects/DownloadManager.php b/laravel_app/app/Livewire/Projects/DownloadManager.php new file mode 100644 index 0000000..c47bb8f --- /dev/null +++ b/laravel_app/app/Livewire/Projects/DownloadManager.php @@ -0,0 +1,21 @@ +path = $project->download_path; + } + + public function render() + { + return view('livewire.projects.download-manager', [ + 'downloads' => $this->project + ]); + } +} diff --git a/laravel_app/app/Livewire/Projects/MailingManager.php b/laravel_app/app/Livewire/Projects/MailingManager.php new file mode 100644 index 0000000..519b049 --- /dev/null +++ b/laravel_app/app/Livewire/Projects/MailingManager.php @@ -0,0 +1,23 @@ +project = $project; + } + + public function render() + { + return view('livewire.projects.mailing-manager', [ + 'mailings' => $this->project->mailings()->orderBy('created_at', 'desc')->get(), + ]); + } +} diff --git a/laravel_app/app/Livewire/Projects/ProjectManager.php b/laravel_app/app/Livewire/Projects/ProjectManager.php index e5dba03..e4e9fe4 100644 --- a/laravel_app/app/Livewire/Projects/ProjectManager.php +++ b/laravel_app/app/Livewire/Projects/ProjectManager.php @@ -4,10 +4,10 @@ use App\Models\Project; use App\Models\ProjectBoundingBox; -use App\Models\Report; +use App\Models\ProjectEmailRecipient; use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\Rule; use Livewire\Component; -use Symfony\Component\Process\Process; class ProjectManager extends Component { @@ -20,6 +20,8 @@ class ProjectManager extends Component public $showProjectModal = false; + public $showMailSettingsModal = false; + public $projectIdBeingDeleted; /** @@ -29,64 +31,59 @@ class ProjectManager extends Component */ public function mount() { - $this->addBoundingBox(); + $this->resetFormData(); } - public function editProject(Project $project) { + public function editProject(Project $project) + { $this->showProjectModal = true; + $this->loadFormData($project); + } + + public function editMailSettings(Project $project) + { + $this->showMailSettingsModal = true; + $this->loadFormData($project); + } + + private function loadFormData(Project $project) + { $this->formData = $project->toArray(); $this->formData['boundingBoxes'] = $project->boundingBoxes->toArray(); + $this->formData['mail_recipients'] = $project->emailRecipients->toArray() ?: [ + [ + 'name' => '', + 'email' => '', + ] + ]; } - /** - * Create a new API token. - * - * @return void - */ - public function createProject() + public function openCreateProjectModal() + { + $this->resetFormData(); + $this->showProjectModal = true; + } + + public function saveProject() { $this->resetErrorBag(); - Validator::make([ - 'name' => $this->formData['name'], - 'boundingBoxes' => $this->formData['boundingBoxes'], - ], [ - 'name' => ['required', 'string', 'max:255'], - '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('createProject'); - - -// Define the unique identifier for the Project (for example, 'id') - $uniqueIdentifier = ['id' =>$this->formData['id'] ?? null]; - -// Using updateOrCreate to either update an existing project or create a new one - $project = Project::updateOrCreate($uniqueIdentifier, $this->formData); - -// Preparing the bounding boxes data for upsert -// Ensure that each bounding box data array includes a 'project_id' field - $boundingBoxesData = array_map(function ($boundingBox) use ($project) { - $boundingBox['project_id'] = $project->id; - unset($boundingBox['created_at']); - unset($boundingBox['updated_at']); - if (!array_key_exists('id', $boundingBox)) { - $boundingBox['id'] = null; - } - return $boundingBox; - }, $this->formData['boundingBoxes'] ?? []); - -// Using upsert to update or create bounding boxes -// You need to specify the unique fields and the fields to be updated - ProjectBoundingBox::upsert($boundingBoxesData, ['id', 'project_id'], ['name', 'top_left_latitude', 'top_left_longitude', 'bottom_right_latitude', 'bottom_right_longitude']); - + $this->validateForm(); + Project::saveWithFormData($this->formData); $this->resetFormData(); $this->showProjectModal = false; $this->dispatch('saved'); } + public function saveMailSettings() + { + $this->resetErrorBag(); + $this->validateEmailSettingsForm(); + Project::saveWithFormData($this->formData); + $this->resetFormData(); + $this->showMailSettingsModal = false; + $this->dispatch('saved'); + } + public function addBoundingBox() { $this->formData['boundingBoxes'][] = @@ -99,9 +96,19 @@ public function addBoundingBox() ]; } + public function addEmailRecipient() + { + $this->formData['mail_recipients'][] = + [ + 'name' => '', + 'email' => '', + ]; + } + + public function deleteBoundingBox($index) { - if(array_key_exists('id', $this->formData['boundingBoxes'][$index])) { + if (array_key_exists('id', $this->formData['boundingBoxes'][$index])) { ProjectBoundingBox::whereId($this->formData['boundingBoxes'][$index]['id'])->delete(); } unset($this->formData['boundingBoxes'][$index]); @@ -109,6 +116,16 @@ public function deleteBoundingBox($index) $this->dispatch('saved'); } + public function deleteEmailRecipient($index) + { + if (array_key_exists('id', $this->formData['mail_recipients'][$index])) { + ProjectEmailRecipient::whereId($this->formData['mail_recipients'][$index]['id'])->delete(); + } + unset($this->formData['mail_recipients'][$index]); + $this->formData['mail_recipients'] = array_values($this->formData['mail_recipients']); + $this->dispatch('saved'); + } + /** * Confirm that the given Project should be deleted. @@ -154,9 +171,57 @@ public function render() private function resetFormData() { $this->formData = [ - 'name' => '', - 'boundingBoxes' => [], + 'name' => '', + 'boundingBoxes' => [], + 'mail_subject' => '', + 'mail_template' => '', + 'mail_frequency' => '', + 'mail_day' => '', + 'mail_recipients' => [], ]; $this->addBoundingBox(); + $this->addEmailRecipient(); + } + + private function validateForm() + { + $projectIdentifier = $this->formData['id'] ?? null; + + Validator::make([ + 'name' => $this->formData['name'], + 'boundingBoxes' => $this->formData['boundingBoxes'], + ], [ + 'name' => [ + 'required', + Rule::unique('projects')->ignore($projectIdentifier), + 'string', + 'max:255' + ], + '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'); + } + + private function validateEmailSettingsForm() + { + Validator::make([ + 'mail_template' => $this->formData['mail_template'], + 'mail_subject' => $this->formData['mail_subject'], + 'mail_frequency' => $this->formData['mail_frequency'], + 'mail_day' => $this->formData['mail_day'], + 'mail_recipients' => $this->formData['mail_recipients'], + ], [ + 'mail_template' => ['required', 'string',], + 'mail_subject' => ['required', 'string',], + 'mail_frequency' => ['required', 'string',], + 'mail_day' => ['required', 'string',], + 'mail_recipients' => ['required', 'array', 'min:1'], + 'mail_recipients.*.name' => ['required', 'string', 'max:255'], + 'mail_recipients.*.email' => ['required', 'email'], + ])->validateWithBag('saveEmailSettingsForm'); } } diff --git a/laravel_app/app/Livewire/Projects/ReportManager.php b/laravel_app/app/Livewire/Projects/ReportManager.php new file mode 100644 index 0000000..94c35a6 --- /dev/null +++ b/laravel_app/app/Livewire/Projects/ReportManager.php @@ -0,0 +1,13 @@ + $formData['id'] ?? null]; + $project = Project::updateOrCreate($uniqueIdentifier, $formData); + $project->upsertBoundingBox($formData); + $project->upsertMailRecipients($formData); + } + + private function upsertBoundingBox($formData) + { + $boundingBoxesData = array_map(function ($boundingBox) { + $boundingBox['project_id'] = $this->id; + unset($boundingBox['created_at']); + unset($boundingBox['updated_at']); + $boundingBox['id'] ??= null; + return $boundingBox; + }, $formData['boundingBoxes'] ?? []); + + ProjectBoundingBox::upsert( + $boundingBoxesData, + ['id', 'project_id'], + [ + 'name', + 'top_left_latitude', + 'top_left_longitude', + 'bottom_right_latitude', + 'bottom_right_longitude' + ] + ); + } + + private function upsertMailRecipients($formData) + { + $mailRecipientsData = array_map(function ($mailRecipient) { + $mailRecipient['project_id'] = $this->id; + unset($mailRecipient['created_at']); + unset($mailRecipient['updated_at']); + $mailRecipient['id'] ??= null; + return $mailRecipient; + }, $formData['mail_recipients'] ?? []); + ProjectEmailRecipient::upsert( + $mailRecipientsData, + ['id', 'project_id'], + ['name', 'email',] + ); + } + protected static function boot() { parent::boot(); // TODO: Change the autogenerated stub static::deleting(function ($project) { $project->boundingBoxes()->delete(); + $project->emailRecipients()->delete(); + $project->mailings()->each(function ($mailing) { + $mailing->attachments()->delete(); + $mailing->recipients()->delete(); + }); + $project->mailings()->delete(); }); } @@ -25,4 +84,19 @@ public function boundingBoxes() { return $this->hasMany(ProjectBoundingBox::class); } + + public function emailRecipients() + { + return $this->hasMany(ProjectEmailRecipient::class); + } + + public function mailings() + { + return $this->hasMany(ProjectMailing::class); + } + + public function downloads() + { + return $this->hasMany(ProjectDownload::class); + } } diff --git a/laravel_app/app/Models/ProjectDownload.php b/laravel_app/app/Models/ProjectDownload.php new file mode 100644 index 0000000..e7c39f4 --- /dev/null +++ b/laravel_app/app/Models/ProjectDownload.php @@ -0,0 +1,11 @@ +belongsTo(Project::class); + } + + public function recipients() + { + return $this->hasMany(ProjectMailingRecipient::class); + } + + public function attachments() + { + return $this->hasMany(ProjectMailingAttachment::class); + } +} diff --git a/laravel_app/app/Models/ProjectMailingAttachment.php b/laravel_app/app/Models/ProjectMailingAttachment.php new file mode 100644 index 0000000..1c1e4c1 --- /dev/null +++ b/laravel_app/app/Models/ProjectMailingAttachment.php @@ -0,0 +1,16 @@ +string('name')->unique(); $table->text('mail_template')->nullable(); $table->string('mail_subject')->nullable(); - $table->string('mail_frequentie')->default('weekly'); - $table->string('mail_day')->default('friday'); + $table->string('mail_frequency')->default('Weekly'); + $table->string('download_path')->unique(); + $table->string('mail_day')->default('Friday'); $table->timestamps(); }); } diff --git a/laravel_app/database/migrations/2023_11_20_103515_create_project_email_recipients_table.php b/laravel_app/database/migrations/2023_11_20_103515_create_project_email_recipients_table.php new file mode 100644 index 0000000..2f6b918 --- /dev/null +++ b/laravel_app/database/migrations/2023_11_20_103515_create_project_email_recipients_table.php @@ -0,0 +1,31 @@ +id(); + $table->foreignIdFor(Project::class); + $table->string('email'); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('project_email_recipients'); + } +}; diff --git a/laravel_app/database/migrations/2023_11_21_125040_create_project_mailings_table.php b/laravel_app/database/migrations/2023_11_21_125040_create_project_mailings_table.php new file mode 100644 index 0000000..9c7d61a --- /dev/null +++ b/laravel_app/database/migrations/2023_11_21_125040_create_project_mailings_table.php @@ -0,0 +1,31 @@ +id(); + $table->foreignId('project_id'); + $table->string('subject'); + $table->text('message'); +// $table->text('recipients'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('project_mailings'); + } +}; diff --git a/laravel_app/database/migrations/2023_11_21_125712_create_project_mailing_recipients_table.php b/laravel_app/database/migrations/2023_11_21_125712_create_project_mailing_recipients_table.php new file mode 100644 index 0000000..14ab8a9 --- /dev/null +++ b/laravel_app/database/migrations/2023_11_21_125712_create_project_mailing_recipients_table.php @@ -0,0 +1,30 @@ +id(); + $table->foreignId('project_mailing_id'); + $table->string('email'); + $table->string('name')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('project_mailing_recipients'); + } +}; diff --git a/laravel_app/database/migrations/2023_11_21_125723_create_project_mailing_attachments_table.php b/laravel_app/database/migrations/2023_11_21_125723_create_project_mailing_attachments_table.php new file mode 100644 index 0000000..fe6bd49 --- /dev/null +++ b/laravel_app/database/migrations/2023_11_21_125723_create_project_mailing_attachments_table.php @@ -0,0 +1,30 @@ +id(); + $table->foreignId('project_mailing_id'); + $table->string('name'); + $table->string('path'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('project_mailing_attachments'); + } +}; diff --git a/laravel_app/database/migrations/2023_11_21_142339_create_project_downloads_table.php b/laravel_app/database/migrations/2023_11_21_142339_create_project_downloads_table.php new file mode 100644 index 0000000..0735dd9 --- /dev/null +++ b/laravel_app/database/migrations/2023_11_21_142339_create_project_downloads_table.php @@ -0,0 +1,30 @@ +id(); + $table->foreignId('project_id'); + $table->string('name'); + $table->string('path'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('project_downloads'); + } +}; diff --git a/laravel_app/database/seeders/DatabaseSeeder.php b/laravel_app/database/seeders/DatabaseSeeder.php index 460e8c4..63dae47 100644 --- a/laravel_app/database/seeders/DatabaseSeeder.php +++ b/laravel_app/database/seeders/DatabaseSeeder.php @@ -14,11 +14,244 @@ public function run(): void { // \App\Models\User::factory(10)->create(); - \App\Models\User::factory()->create([ - 'name' => 'Martin Folkerts', - 'email' => 'martin@sobit.nl', - 'password' => '$2y$10$hZZaAaiv1KXmCqq5vZ6PEeRWzvwGbaHKcfqeEMlTn.y22EEPVtofi', + \App\Models\User::factory()->create([ + 'name' => 'Martin Folkerts', + 'email' => 'martin@sobit.nl', + 'password' => '$2y$10$hZZaAaiv1KXmCqq5vZ6PEeRWzvwGbaHKcfqeEMlTn.y22EEPVtofi', + ]); - ]); + $this->createChembaProject(); + $this->createXinavaneProject(); + $this->createKakiraProject(); + + + } + + private function createChembaProject() + { + $chembaProject = \App\Models\Project::create([ + 'name' => 'Chemba', + 'mail_template' => 'Mail template for Chemba', + 'mail_subject' => 'SmartCane update Chemba for {date}', + 'mail_frequency' => 'Weekly', + 'mail_day' => 'Friday', + 'download_path' => 'chemba', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ]); + + $chembaProject->boundingBoxes()->createMany([ + [ + 'name' => 'Chemba West', + 'top_left_latitude' => 34.9460, + 'top_left_longitude' => -17.3516, + 'bottom_right_latitude' => 34.9380, + 'bottom_right_longitude' => -17.2917, + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + [ + 'name' => 'Chemba East', + 'top_left_latitude' => 34.8830, + 'top_left_longitude' => -17.3516, + 'bottom_right_latitude' => 34.9380, + 'bottom_right_longitude' => -17.2917, + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + ]); + + $chembaProject->emailRecipients()->createMany([ + [ + 'name' => 'Martin Folkerts', + 'email' => 'martin@sobit.nl', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], [ + 'name' => 'Timon Weitkamp', + 'email' => 'timon@smartfarmingtech.com', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + ]); + + $chembaProject->mailings()->createMany([ + [ + 'subject' => 'Chemba 2021-01-01', + 'message' => 'Chemba 2021-01-01', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], [ + 'subject' => 'Chemba 2021-01-08', + 'message' => 'Chemba 2021-01-08', + 'created_at' => '2021-01-08 00:00:00', + 'updated_at' => '2021-01-08 00:00:00', + ], + ]); + + foreach ($chembaProject->mailings as $mailing) { + $mailing->recipients()->createMany([ + [ + 'name' => 'Martin Folkerts', + 'email' => 'martin@sobit.nl', + 'created_at' => $mailing->created_at, + 'updated_at' => $mailing->updated_at, + ], [ + 'name' => 'Timon Weitkamp', + 'email' => 'timon@smartfarmingtech.com', + 'created_at' => $mailing->created_at, + 'updated_at' => $mailing->updated_at, + ], + ]); + } + } + + private function createXinavaneProject() + { + $project = \App\Models\Project::create([ + 'name' => 'Xinavane', + 'mail_template' => 'Mail template for Xinavane', + 'mail_subject' => 'SmartCane update Xinavane for {date}', + 'mail_frequency' => 'Weekly', + 'mail_day' => 'Friday', + 'download_path' => 'xinavane', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ]); + + $project->boundingBoxes()->createMany([ + [ + 'name' => 'Xinavane West', + 'top_left_latitude' => 32.6213, + 'top_left_longitude' => -25.0647, + 'bottom_right_latitude' => 32.6284, + 'bottom_right_longitude' => -25.0570, + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + [ + 'name' => 'Xinavane East', + 'top_left_latitude' => 32.6790, + 'top_left_longitude' => -25.0333, + 'bottom_right_latitude' => 32.7453, + 'bottom_right_longitude' => -25.0235, + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + ]); + + $project->emailRecipients()->createMany([ + [ + 'name' => 'Martin Folkerts', + 'email' => 'martin@sobit.nl', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], [ + 'name' => 'Timon Weitkamp', + 'email' => 'timon@smartfarmingtech.com', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + ]); + + $project->mailings()->createMany([ + [ + 'subject' => 'Xinavane 2021-01-01', + 'message' => 'Xinavane 2021-01-01', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], [ + 'subject' => 'Xinavane 2021-01-08', + 'message' => 'Xinavane 2021-01-08', + 'created_at' => '2021-01-08 00:00:00', + 'updated_at' => '2021-01-08 00:00:00', + ], + ]); + + foreach ($project->mailings as $mailing) { + $mailing->recipients()->createMany([ + [ + 'name' => 'Martin Folkerts', + 'email' => 'martin@sobit.nl', + 'created_at' => $mailing->created_at, + 'updated_at' => $mailing->updated_at, + ], [ + 'name' => 'Timon Weitkamp', + 'email' => 'timon@smartfarmingtech.com', + 'created_at' => $mailing->created_at, + 'updated_at' => $mailing->updated_at, + ], + ]); + } + } + + private function createKakiraProject() + { + $project = \App\Models\Project::create([ + 'name' => 'Kakira', + 'mail_template' => 'Mail template for Kakira', + 'mail_subject' => 'SmartCane update Kakira for {date}', + 'mail_frequency' => 'Weekly', + 'mail_day' => 'Friday', + 'download_path' => 'kakira', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ]); + + $project->boundingBoxes()->createMany([ + [ + 'name' => 'kakira_demo', + 'top_left_latitude' => 33.289993827426535, + 'top_left_longitude' => 0.491981861534345, + 'bottom_right_latitude' => 33.32572075441914, + 'bottom_right_longitude' => 0.5144195937114393, + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + ]); + + $project->emailRecipients()->createMany([ + [ + 'name' => 'Martin Folkerts', + 'email' => 'martin@sobit.nl', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], [ + 'name' => 'Timon Weitkamp', + 'email' => 'timon@smartfarmingtech.com', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], + ]); + + $project->mailings()->createMany([ + [ + 'subject' => 'Kakira 2021-01-01', + 'message' => 'Kakira 2021-01-01', + 'created_at' => '2021-01-01 00:00:00', + 'updated_at' => '2021-01-01 00:00:00', + ], [ + 'subject' => 'Kakira 2021-01-08', + 'message' => 'Kakira 2021-01-08', + 'created_at' => '2021-01-08 00:00:00', + 'updated_at' => '2021-01-08 00:00:00', + ], + ]); + + foreach ($project->mailings as $mailing) { + $mailing->recipients()->createMany([ + [ + 'name' => 'Martin Folkerts', + 'email' => 'martin@sobit.nl', + 'created_at' => $mailing->created_at, + 'updated_at' => $mailing->updated_at, + ], [ + 'name' => 'Timon Weitkamp', + 'email' => 'timon@smartfarmingtech.com', + 'created_at' => $mailing->created_at, + 'updated_at' => $mailing->updated_at, + ], + ]); + } } } diff --git a/laravel_app/resources/views/components/form-modal.blade.php b/laravel_app/resources/views/components/form-modal.blade.php new file mode 100644 index 0000000..6d7a78d --- /dev/null +++ b/laravel_app/resources/views/components/form-modal.blade.php @@ -0,0 +1,25 @@ +@props(['submit']) + +
merge(['class' => 'md:grid md:grid-cols-1 md:gap-6']) }}> +
+

{{ $title }}

+ + {{ $description }} +
+ +
+
+
+
+ {{ $form }} +
+
+ + @if (isset($actions)) +
+ {{ $actions }} +
+ @endif +
+
+
diff --git a/laravel_app/resources/views/components/modal.blade.php b/laravel_app/resources/views/components/modal.blade.php index b1c1e68..9285736 100644 --- a/laravel_app/resources/views/components/modal.blade.php +++ b/laravel_app/resources/views/components/modal.blade.php @@ -9,6 +9,8 @@ 'lg' => 'sm:max-w-lg', 'xl' => 'sm:max-w-xl', '2xl' => 'sm:max-w-2xl', + '4xl' => 'sm:max-w-4xl', + '6xl' => 'sm:max-w-6xl', ][$maxWidth ?? '2xl']; @endphp diff --git a/laravel_app/resources/views/components/project-manager-delete-confirmation-modal.blade.php b/laravel_app/resources/views/components/project-manager-delete-confirmation-modal.blade.php new file mode 100644 index 0000000..d771ff7 --- /dev/null +++ b/laravel_app/resources/views/components/project-manager-delete-confirmation-modal.blade.php @@ -0,0 +1,19 @@ + + + {{ __('Delete Project') }} + + + + {{ __('Are you sure you would like to delete this Project?') }} + + + + + {{ __('Cancel') }} + + + + {{ __('Delete') }} + + + diff --git a/laravel_app/resources/views/components/project-manager-grid.blade.php b/laravel_app/resources/views/components/project-manager-grid.blade.php new file mode 100644 index 0000000..8cd867f --- /dev/null +++ b/laravel_app/resources/views/components/project-manager-grid.blade.php @@ -0,0 +1,45 @@ +@props([ + /** @var \App\Livewire\Projects\ProjectManager */ + 'projectManager' +]) + +
class(['mt-10 sm:mt-0']) }}> + + + {{ __('Manage projects') }} + + + + {{ __('You may delete any of your projects if they are no longer needed.') }} + + + +
+ + {{ __('Create Project') }} + + @foreach ($projectManager->projects->sortBy('name') as $project) +
+ +
+ + + +
+
+ @endforeach +
+
+
+
diff --git a/laravel_app/resources/views/components/project-manager-mail-settings-modal.blade.php b/laravel_app/resources/views/components/project-manager-mail-settings-modal.blade.php new file mode 100644 index 0000000..e47f275 --- /dev/null +++ b/laravel_app/resources/views/components/project-manager-mail-settings-modal.blade.php @@ -0,0 +1,104 @@ +@props([ + /** @var \App\Livewire\Projects\ProjectManager */ + 'projectManager' +]) + + + + + {{ __('Project') }} : {{ $projectManager->formData['name'] ?? '' }} + + + + {{ __('Email settings for project.') }} + + + +
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ {{ __('Recipients') }} +
+ @foreach($projectManager->formData['mail_recipients'] as $key => $email_recipient) +
+
+ + + +
+ +
+ + + +
+
+ @if( count($projectManager->formData['mail_recipients']) > 1) + + @endif +
+
+ @endforeach +
+ + + + {{ __('Saved.') }} + + + {{ __('Add recipient') }} + + + {{ __('Cancel') }} + + + {{ __('Save') }} + + + +
+
diff --git a/laravel_app/resources/views/components/project-manager-properties-modal.blade.php b/laravel_app/resources/views/components/project-manager-properties-modal.blade.php new file mode 100644 index 0000000..5a422f4 --- /dev/null +++ b/laravel_app/resources/views/components/project-manager-properties-modal.blade.php @@ -0,0 +1,106 @@ +@props([ + 'formData', + /** @var \App\Livewire\Projects\ProjectManager */ + 'projectManager' +]) + + + + + {{ __('Project') }} + + + + {{ __('Report generator for generating reports') }} + + + + +
+ + + +
+ @foreach($projectManager->formData['boundingBoxes'] as $key => $boundingBox) + {{--
--}} +
+ {{ __('Bounding box') }} + @if( count($projectManager->formData['boundingBoxes']) > 1) + + @endif +
+
+ + + +
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ {{--
--}} + @endforeach +
+ + + + {{ __('Saved.') }} + + + {{ __('Add Bounding box') }} + + + {{ __('Cancel') }} + + + {{ __('Save') }} + + + +
+
diff --git a/laravel_app/resources/views/components/tab-section.blade.php b/laravel_app/resources/views/components/tab-section.blade.php new file mode 100644 index 0000000..f94593f --- /dev/null +++ b/laravel_app/resources/views/components/tab-section.blade.php @@ -0,0 +1,23 @@ + +
merge(['class' => 'md:grid md:grid-cols-1 md:gap-6']) }}> +
+

{{ $title }}

+ + {{ $description }} +
+ +
+
+
+ {{ $form }} +
+
+ + @if (isset($actions)) +
+ {{ $actions }} +
+ @endif + +
+
diff --git a/laravel_app/resources/views/livewire/project-manager.blade.php b/laravel_app/resources/views/livewire/project-manager.blade.php index b8d77f6..a47cae6 100644 --- a/laravel_app/resources/views/livewire/project-manager.blade.php +++ b/laravel_app/resources/views/livewire/project-manager.blade.php @@ -1,165 +1,7 @@
- - - - {{ __('Project') }} - - - - {{ __('Report generator for generating reports') }} - - - - -
- - - -
- @foreach($formData['boundingBoxes'] as $key => $boundingBox) - {{--
--}} -
- {{ __('Bounding box') }} - @if( count($this->formData['boundingBoxes']) > 1) - - @endif -
-
- - - -
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- {{--
--}} - @endforeach -
- - - - {{ __('Saved.') }} - - - {{ __('Add Bounding box') }} - - - {{ __('Cancel') }} - - - {{ __('Save') }} - - - -
-
- - -
- - - {{ __('Manage projects') }} - - - - {{ __('You may delete any of your projects if they are no longer needed.') }} - - - - -
- - {{ __('Create Project') }} - - @foreach ($this->projects->sortBy('name') as $project) -
-
- {{ $project->name }} -
- -
- - -
-
- @endforeach -
-
-
-
- - - - - - {{ __('Delete Project') }} - - - - {{ __('Are you sure you would like to delete this Project?') }} - - - - - {{ __('Cancel') }} - - - - {{ __('Delete') }} - - - + + + +
diff --git a/laravel_app/resources/views/livewire/projects/download-manager.blade.php b/laravel_app/resources/views/livewire/projects/download-manager.blade.php new file mode 100644 index 0000000..d688950 --- /dev/null +++ b/laravel_app/resources/views/livewire/projects/download-manager.blade.php @@ -0,0 +1,16 @@ + + Download details + Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa, reprehenderit. + +
+
+ @livewire('download.download-grid') +
+ + +
+ @livewire('download.download-form') +
+
+
+
diff --git a/laravel_app/resources/views/livewire/projects/mailing-manager.blade.php b/laravel_app/resources/views/livewire/projects/mailing-manager.blade.php new file mode 100644 index 0000000..a56bcbd --- /dev/null +++ b/laravel_app/resources/views/livewire/projects/mailing-manager.blade.php @@ -0,0 +1,40 @@ + + Mailing Details + ... + + +
+ + + + + + + + + + + + + @foreach($project->mailings as $mail) + + + + + + + + + @endforeach + +
Id + CreatedSubject#Attachment + Edit +
{{ $mail->id }}{{ $mail->created_at }}{{ $mail->subject }}{{ $mail->recipients()->count() }}{{ $mail->attachments()->get('name')->implode(', ') }} + +
+
+ + +
+
diff --git a/laravel_app/resources/views/livewire/projects/report-manager.blade.php b/laravel_app/resources/views/livewire/projects/report-manager.blade.php new file mode 100644 index 0000000..3a164db --- /dev/null +++ b/laravel_app/resources/views/livewire/projects/report-manager.blade.php @@ -0,0 +1,9 @@ + + Report Details + .. + + + + + + diff --git a/laravel_app/resources/views/projects/show.blade.php b/laravel_app/resources/views/projects/show.blade.php new file mode 100644 index 0000000..7d606ab --- /dev/null +++ b/laravel_app/resources/views/projects/show.blade.php @@ -0,0 +1,68 @@ + + +

+ {{ __('Project') }} {{ $project->name }} +

+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ @livewire('projects.download-manager', ['project' => $project]); +
+
+ @livewire('projects.mailing-manager', ['project' => $project]); + + +
+
+ @livewire('projects.report-manager', ['project' => $project]); +
+
+
+
+
diff --git a/laravel_app/routes/web.php b/laravel_app/routes/web.php index 7d37724..6785a14 100644 --- a/laravel_app/routes/web.php +++ b/laravel_app/routes/web.php @@ -28,5 +28,6 @@ Route::get('/download', [\App\Http\Controllers\DownloadController::class, 'show'])->name('download'); Route::get('/report', [\App\Http\Controllers\ReportController::class, 'index'])->name('report'); - Route::get('/project', [\App\Http\Controllers\ProjectController::class, 'index'])->name('project'); + Route::get('/projects/{project}', [\App\Http\Controllers\ProjectController::class, 'show'])->name('project.show'); + Route::get('/projects', [\App\Http\Controllers\ProjectController::class, 'index'])->name('project'); });