diff --git a/app/Http/Requests/Bo/UpdateMiniCrudRequest.php b/app/Http/Requests/Bo/UpdateMiniCrudRequest.php index 025a1b9..0be6769 100644 --- a/app/Http/Requests/Bo/UpdateMiniCrudRequest.php +++ b/app/Http/Requests/Bo/UpdateMiniCrudRequest.php @@ -86,7 +86,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest ]); break; case InputType::image->value: - $required = $this->isUpdate() ? 'sometimes' : 'required'; + $required = $this->isUpdate() ? 'sometimes' : ($input['required'] ? 'required' : 'nullable'); $ipt = $this->data[$iptName]; $max = isset($ipt['dimensionsMax']); $dim = \is_string($input['dimensions']) ? collect(explode( diff --git a/app/Models/Section.php b/app/Models/Section.php index 4541cac..608df75 100644 --- a/app/Models/Section.php +++ b/app/Models/Section.php @@ -74,6 +74,7 @@ class Section extends Model $model->text = FileStorageHelper::storeModelFilesFromHtml($model, $model->text); }); static::updated(function (self $model) { + $model->minicrudUpdated(); FileStorageHelper::removeOldModelFilesFromHtml( $model->text, ToolboxHelper::getOriginal($model, 'text') @@ -196,18 +197,41 @@ class Section extends Model /** * Empty bloc for the button boolean. * - * @param array $data - * @param string $name + * @param array $data + * @param string $name + * @param boolean $value * @return array */ public static function emptyButtonBooleanBloc( array $data, - string $name + string $name, + bool $value = false ): array { $data['bloc_button_' . Str::of($name)->snake()->ascii()->remove(['\'', '-'])] = [ 'label' => "Afficher le bouton '{$name}' ?", 'inputType' => InputType::boolean->value, - 'value' => false + 'value' => $value + ]; + return $data; + } + + /** + * Empty bloc for a boolean. + * + * @param array $data + * @param string $name + * @param boolean $value + * @return array + */ + public static function emptyBooleanBloc( + array $data, + string $name, + bool $value = false + ): array { + $data['bloc_boolean_' . Str::of($name)->snake()->ascii()->remove(['\'', '-'])] = [ + 'label' => "{$name} ?", + 'inputType' => InputType::boolean->value, + 'value' => $value ]; return $data; } diff --git a/app/Traits/Models/MiniCrudModel.php b/app/Traits/Models/MiniCrudModel.php index 60a3b7c..3e72544 100644 --- a/app/Traits/Models/MiniCrudModel.php +++ b/app/Traits/Models/MiniCrudModel.php @@ -39,8 +39,8 @@ trait MiniCrudModel foreach ($data as &$input) { switch ($input['inputType']) { case InputType::text->value: - $input['text'] = clean($input['text']); - $input['text'] = FileStorageHelper::storeModelFilesFromHtml($this, $input['text']); + $input['value'] = clean($input['value']); + $input['value'] = FileStorageHelper::storeModelFilesFromHtml($this, $input['value']); break; } //end switch } //end foreach @@ -70,8 +70,15 @@ trait MiniCrudModel case InputType::text->value: $original = ToolboxHelper::getOriginal($this, 'data'); FileStorageHelper::removeOldModelFilesFromHtml( - $input['text'], - $original[$index]['text'] ?? '' + $input['value'], + $original[$index]['value'] ?? '' + ); + break; + case InputType::image->value: + $original = ToolboxHelper::getOriginal($this, 'data'); + FileStorageHelper::removeOldFiles( + [$original[$index]['value']], + [$input['value']] ); break; } //end switch @@ -85,11 +92,18 @@ trait MiniCrudModel */ public function minicrudDeleted(): void { - /** @var array */ - foreach ($this->data as $input) { + /** @var array $input */ + foreach ($this->data as $index => $input) { switch ($input['inputType']) { case InputType::text->value: - FileStorageHelper::removeModelFilesOfHtml($input['text']); + FileStorageHelper::removeModelFilesOfHtml($input['value']); + break; + case InputType::image->value: + $original = ToolboxHelper::getOriginal($this, 'data'); + FileStorageHelper::removeOldFiles( + [$original[$index]['value']], + [] + ); break; } //end switch } //end foreach diff --git a/database/migrations/2024_07_24_145556_alter_sections_hire_page.php b/database/migrations/2024_07_24_145556_alter_sections_hire_page.php index 6a359d7..7058639 100644 --- a/database/migrations/2024_07_24_145556_alter_sections_hire_page.php +++ b/database/migrations/2024_07_24_145556_alter_sections_hire_page.php @@ -3,6 +3,7 @@ use App\Enums\Sections\PageSectionEnum; use App\Models\Section; use Illuminate\Database\Migrations\Migration; +use Illuminate\Support\Collection; return new class extends Migration { @@ -13,27 +14,40 @@ return new class extends Migration */ public function up(): void { + Collection::macro('insertAfter', function ($target, $value, $new_key = null) { + if (is_int($target)) { + $this->items = array_merge(array_slice($this->items, 0, $target + 1), [$value], array_slice($this->items, $target + 1)); + return; + } + + foreach ($this->items as $key => $old) { + $new[$key] = $old; + if ($key === $target && is_null($new_key)) { + $new[] = $value; + } elseif ($key === $target) { + $new[$new_key] = $value; + } + } + + $this->items = $new; + }); + $hireSection = Section::query()->where('section', PageSectionEnum::hire_find)->first(); if ($hireSection) { - /** @var \App\Models\Section $hireSection */ - - $oldPictureField = $hireSection->data['bloc_image']; - - $hireSection->data = array_merge( - $hireSection->data, - $hireSection->emptyPictureBloc( - [], - $oldPictureField['value'], - $oldPictureField['alt'], - $oldPictureField['title'], - $oldPictureField['dimensions']['width'], - $oldPictureField['dimensions']['height'], - false, - 'Image' - ) + $data = collect($hireSection->data); + $bloc = collect(Section::emptyBooleanBloc( + [], + "Afficher l'image", + true + ))->first(); + $data->insertAfter( + "bloc_contenu_n1_content", + $bloc, + "bloc_button_display_picture" ); - $hireSection->save(); - } + $hireSection->data = $data->all(); + $hireSection->saveQuietly(); + } //end if } /** @@ -45,24 +59,10 @@ return new class extends Migration { $hireSection = Section::query()->where('section', PageSectionEnum::hire_find)->first(); if ($hireSection) { - /** @var \App\Models\Section $hireSection */ - - $oldPictureField = $hireSection->data['bloc_image']; - - $hireSection->data = array_merge( - $hireSection->data, - $hireSection->emptyPictureBloc( - [], - $oldPictureField['value'], - $oldPictureField['alt'], - $oldPictureField['title'], - $oldPictureField['dimensions']['width'], - $oldPictureField['dimensions']['height'], - true, - 'Image' - ) - ); - $hireSection->save(); - } + $data = collect($hireSection->data); + $data->forget("bloc_button_display_picture"); + $hireSection->data = $data->all(); + $hireSection->saveQuietly(); + } //end if } }; diff --git a/database/migrations/2024_07_24_161616_alter_sections_commitments_page.php b/database/migrations/2024_07_24_161616_alter_sections_commitments_page.php new file mode 100644 index 0000000..640b66e --- /dev/null +++ b/database/migrations/2024_07_24_161616_alter_sections_commitments_page.php @@ -0,0 +1,67 @@ +items = array_merge(array_slice($this->items, 0, $target + 1), [$value], array_slice($this->items, $target + 1)); + return; + } + + foreach ($this->items as $key => $old) { + $new[$key] = $old; + if ($key === $target && is_null($new_key)) { + $new[] = $value; + } elseif ($key === $target) { + $new[$new_key] = $value; + } + } + + $this->items = $new; + }); + + $commitSection = Section::query()->where('section', PageSectionEnum::commit_commitments)->first(); + if ($commitSection) { + $data = collect($commitSection->data); + $bloc = collect(Section::emptyLinkNewTabBloc( + [], + "le rapport" + ))->first(); + $data->insertAfter( + "bloc_link", + $bloc, + "bloc_link_new_tab" + ); + $commitSection->data = $data->all(); + $commitSection->saveQuietly(); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + $commitSection = Section::query()->where('section', PageSectionEnum::commit_commitments)->first(); + if ($commitSection) { + $data = collect($commitSection->data); + $data->forget("bloc_link_new_tab"); + $commitSection->data = $data->all(); + $commitSection->saveQuietly(); + } + } +}; diff --git a/resources/ts/fo/pages/commitments.ts b/resources/ts/fo/pages/commitments.ts index f9faf2d..d75a127 100644 --- a/resources/ts/fo/pages/commitments.ts +++ b/resources/ts/fo/pages/commitments.ts @@ -5,9 +5,11 @@ document.addEventListener("DOMContentLoaded", function () { } const button = document.querySelector(".commit-navigation .btn") as HTMLButtonElement; - const navWrapper = document.querySelector(".commit-navigation-wrapper") as HTMLDivElement; + const navWrapper = document.querySelectorAll(".commit-navigation-wrapper "); button.addEventListener("click", () => { - navWrapper.classList.toggle("show"); + navWrapper.forEach((element: Element) => { + element.classList.toggle("show"); + }); document.querySelectorAll(".commit-navigation .btn svg").forEach(icon => { icon.classList.toggle("d-none"); }); diff --git a/resources/views/fo/pages/hire.blade.php b/resources/views/fo/pages/hire.blade.php index cb24dba..7ce4226 100644 --- a/resources/views/fo/pages/hire.blade.php +++ b/resources/views/fo/pages/hire.blade.php @@ -306,12 +306,15 @@ -