From 50a3e9a4dfc5a976b6b502b24f9062b0ad1c5a9c Mon Sep 17 00:00:00 2001 From: guillaume91 Date: Fri, 24 May 2024 12:19:20 +0200 Subject: [PATCH] [Done] moved mail and edit to tabs, removed slug url for projects, new settings tab --- .../Http/Controllers/ProjectController.php | 4 +- laravel_app/app/Livewire/Projects/Menu.php | 1 + .../app/Livewire/Projects/Tabs/Settings.php | 71 ++++++------ .../views/components/action-message.blade.php | 2 +- .../views/components/button.blade.php | 2 +- .../components/project-manager-grid.blade.php | 10 +- .../livewire/projects/tabs/settings.blade.php | 107 +++++++++--------- .../resources/views/projects/show.blade.php | 2 +- .../livewire/dropzone.blade.php | 2 +- 9 files changed, 96 insertions(+), 105 deletions(-) diff --git a/laravel_app/app/Http/Controllers/ProjectController.php b/laravel_app/app/Http/Controllers/ProjectController.php index d36bfbf..33b56d8 100644 --- a/laravel_app/app/Http/Controllers/ProjectController.php +++ b/laravel_app/app/Http/Controllers/ProjectController.php @@ -14,9 +14,9 @@ public function index() public function show(string $projectName,?string $currentTab = null) { - if($project = Project::firstWhere('name',$projectName)) { + if($project = Project::firstWhere([['name',$projectName]])) { $availableTabs = ['downloads', 'mosaics', 'reports', 'mailings', 'settings']; - return in_array($currentTab, $availableTabs) ? view('projects.show', compact(['project', 'currentTab'])) : redirect(route('project.show', [$projectName, 'downloads'])); + return in_array($currentTab, $availableTabs) ? view('projects.show', compact(['project', 'currentTab'])) : redirect(route('project.show', [$projectName,'downloads'])); } return abort(404); } diff --git a/laravel_app/app/Livewire/Projects/Menu.php b/laravel_app/app/Livewire/Projects/Menu.php index 293ba21..94af96f 100644 --- a/laravel_app/app/Livewire/Projects/Menu.php +++ b/laravel_app/app/Livewire/Projects/Menu.php @@ -8,6 +8,7 @@ class Menu extends Component { public string $activeTab = "downloads"; public string $projectName = ''; + public string $projectId= ''; public function mount() { diff --git a/laravel_app/app/Livewire/Projects/Tabs/Settings.php b/laravel_app/app/Livewire/Projects/Tabs/Settings.php index fa1660e..4510d0e 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Settings.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Settings.php @@ -20,36 +20,22 @@ class Settings extends Component public $confirmingReportDeletion = false; - public $showProjectModal = false; - - public $showMailSettingsModal = false; - public $projectIdBeingDeleted; public array $pivotFiles; public array $spanFiles; - public $harvestDataFiles; + public array $harvestDataFiles; + + public $isDirty = false; + /** * Mount the component. * * @return void */ - public function mount() + public function mount(Project $project) { - $this->resetFormData(); - } - - - public function editProject(Project $project) - { - $this->showProjectModal = true; - $this->loadFormData($project); - } - - public function editMailSettings(Project $project) - { - $this->showMailSettingsModal = true; $this->loadFormData($project); } @@ -62,23 +48,19 @@ private function loadFormData(Project $project) 'email' => '', ] ]; + $this->formData['pivot_file'] = null; + $this->formData['span_file'] = null; + $this->formData['harvest_file'] = null; } - - public function openCreateProjectModal() - { - $this->resetFormData(); - $this->showProjectModal = true; - } - public function saveProject() { $this->resetErrorBag(); $this->mergeFormData(); $this->validateForm(); Project::saveWithFormData($this->formData); - $this->resetFormData(); - $this->showProjectModal = false; - $this->dispatch('saved'); + //dd(route('project.show',[$this->formData['name'],$this->formData['id'],'settings'])); + return redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']); + //$this->dispatch('saved'); } public function saveMailSettings() @@ -86,11 +68,29 @@ public function saveMailSettings() $this->resetErrorBag(); $this->validateEmailSettingsForm(); Project::saveWithFormData($this->formData); - $this->resetFormData(); - $this->showMailSettingsModal = false; $this->dispatch('saved'); } + public function saveSettings() + { + $this->resetErrorBag(); + $this->mergeFormData(); + $this->validateForm(); + $this->validateEmailSettingsForm(); + $this->shouldReload(); + Project::saveWithFormData($this->formData); + if($this->isDirty) redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']); + $this->dispatch('saved'); + } + + public function shouldReload() + { + if (Project::find($this->formData['id'])?->name == $this->formData['name']) return; + $this->isDirty = true; + } + + + public function addEmailRecipient() { $this->formData['mail_recipients'][] = @@ -147,10 +147,6 @@ public function getProjectsProperty() return Project::all(); } -// public function render() -// { -// return view('livewire.project-manager'); -// } private function resetFormData() { @@ -168,6 +164,11 @@ private function resetFormData() $this->addEmailRecipient(); } + public function todo() + { + + } + private function validateForm() { $projectIdentifier = $this->formData['id'] ?? null; diff --git a/laravel_app/resources/views/components/action-message.blade.php b/laravel_app/resources/views/components/action-message.blade.php index a8a95f9..25f1f4e 100644 --- a/laravel_app/resources/views/components/action-message.blade.php +++ b/laravel_app/resources/views/components/action-message.blade.php @@ -5,6 +5,6 @@ x-show.transition.out.opacity.duration.1500ms="shown" x-transition:leave.opacity.duration.1500ms style="display: none;" - {{ $attributes->merge(['class' => 'text-sm text-gray-600']) }}> + {{ $attributes->merge(['class' => 'text-sm text-gray-600 text-center']) }}> {{ $slot->isEmpty() ? 'Saved.' : $slot }} diff --git a/laravel_app/resources/views/components/button.blade.php b/laravel_app/resources/views/components/button.blade.php index d71f0b6..d015594 100644 --- a/laravel_app/resources/views/components/button.blade.php +++ b/laravel_app/resources/views/components/button.blade.php @@ -1,3 +1,3 @@ - diff --git a/laravel_app/resources/views/components/project-manager-grid.blade.php b/laravel_app/resources/views/components/project-manager-grid.blade.php index 49221c0..4915f7b 100644 --- a/laravel_app/resources/views/components/project-manager-grid.blade.php +++ b/laravel_app/resources/views/components/project-manager-grid.blade.php @@ -21,17 +21,9 @@ @foreach ($projectManager->projects->sortBy('name') as $project)
- -
- - -
- - {{ __('Saved.') }} - +
{{ __('Add recipient') }} - - {{ __('Cancel') }} - - - {{ __('Save') }} - -
+
+ + + {{ __('Saved.') }} + + + + {{__('Save settings')}} + +
diff --git a/laravel_app/resources/views/projects/show.blade.php b/laravel_app/resources/views/projects/show.blade.php index 9eabcfa..f69dc85 100644 --- a/laravel_app/resources/views/projects/show.blade.php +++ b/laravel_app/resources/views/projects/show.blade.php @@ -5,7 +5,7 @@
- +
@switch($currentTab) @case('downloads') diff --git a/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php b/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php index 08b8cc6..5ed5097 100644 --- a/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php +++ b/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php @@ -11,7 +11,7 @@ @drop.prevent="onDrop" class="w-full antialiased" > -
+
@if(! is_null($error))