fix: #53 - some style fixes in the commitments page + display or hide a pic in the hire page

This commit is contained in:
Noah Lancien 2024-07-25 10:39:10 +02:00
parent 3e3161cfa6
commit 5b7c943e6c
8 changed files with 169 additions and 59 deletions

View file

@ -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(

View file

@ -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;
}

View file

@ -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

View file

@ -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
}
};

View file

@ -0,0 +1,67 @@
<?php
use App\Enums\Sections\PageSectionEnum;
use App\Models\Section;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Collection;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
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;
});
$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();
}
}
};

View file

@ -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");
});

View file

@ -306,12 +306,15 @@
</div>
</div>
</div>
<div class="row">
<div class="col-12 text-center">
<img class="img-fluid rounded-4 find-img" src="{{ asset($findSection->data['bloc_image']['value']) }}"
title="{{ $findSection->data['bloc_image']['title'] }}" alt="{{ $findSection->data['bloc_image']['alt'] }}">
@if ($findSection->data['bloc_button_display_picture']['value'])
<div class="row">
<div class="col-12 text-center">
<img class="img-fluid rounded-4 find-img" src="{{ asset($findSection->data['bloc_image']['value']) }}"
title="{{ $findSection->data['bloc_image']['title'] }}"
alt="{{ $findSection->data['bloc_image']['alt'] }}">
</div>
</div>
</div>
@endif
<div class="row text-primary row-gap-3 mt-4 text-center">
<div class="col-12 fw-bolder fs-4 mb-2">
{{ __('Nos offres: ') }}

View file

@ -164,7 +164,7 @@
'hasWordCounter' => true,
'name' => 'data[' . $k . '][alt]',
'value' => old("data.{$k}.alt", $model->data[$k]['alt'] ?? null),
'required' => true,
'required' => $model->data[$k]['required'],
'model' => $model ?? null,
'helper' =>
__('crud.minicrud.picture_alt_helper') .
@ -186,7 +186,7 @@
'hasWordCounter' => true,
'name' => 'data[' . $k . '][title]',
'value' => old("data.{$k}.title", $model->data[$k]['title'] ?? null),
'required' => true,
'required' => $model->data[$k]['required'],
'model' => $model ?? null,
'helper' =>
__('crud.minicrud.picture_title_helper') .
@ -213,7 +213,7 @@
'width' => $input['dimensions']['width'],
'height' => $input['dimensions']['height'],
]),
'required' => true,
'required' => $model->data[$k]['required'],
'preview' => true,
])
@include('modules.input-error', [