WIP: Adding crud sections"
"
This commit is contained in:
parent
2c840cf218
commit
d99f1b2a81
36 changed files with 1474 additions and 294 deletions
|
|
@ -45,6 +45,9 @@
|
|||
"vue/script-indent": ["error", 2, { "baseIndent": 0, "switchCase": 1 }],
|
||||
"vue/one-component-per-file": "off"
|
||||
},
|
||||
"globals": {
|
||||
"require": true
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"node": {
|
||||
|
|
|
|||
23
app/Enums/CkEditorConfigName.php
Normal file
23
app/Enums/CkEditorConfigName.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum CkEditorConfigName: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case minimal = 1;
|
||||
case base = 2;
|
||||
case advanced = 3;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::minimal->name => 'minimal',
|
||||
self::base->name => 'base',
|
||||
self::advanced->name => 'advanced',
|
||||
];
|
||||
}
|
||||
|
|
@ -51,8 +51,8 @@ enum PageSectionEnum: int
|
|||
self::unveil_sites->name => 'Nos Sites',
|
||||
self::unveil_history->name => 'Histoire',
|
||||
self::unveil_commitments->name => 'Engagements',
|
||||
self::hire_life->name => 'Vie de l\'entreprise',
|
||||
self::hire_formation->name => 'Alternance et formation',
|
||||
self::hire_life->name => 'Vie de l\'Entreprise',
|
||||
self::hire_formation->name => 'Alternance et Formation',
|
||||
self::hire_grow->name => 'Fiers d\'évoluer ensemble',
|
||||
self::hire_parity->name => 'Parité',
|
||||
self::hire_find->name => 'On se retrouve',
|
||||
|
|
@ -62,14 +62,94 @@ enum PageSectionEnum: int
|
|||
self::commit_respect_earth->name => 'Respecter la terre',
|
||||
self::commit_feed->name => 'Bien nourrir',
|
||||
self::commit_commitments->name => 'Engagements',
|
||||
self::move_life->name => 'vie de l\'entreprise',
|
||||
self::move_commitments->name => 'engagements',
|
||||
self::produce_local->name => 'large gamme locale',
|
||||
self::move_life->name => 'Vie de l\'Entreprise',
|
||||
self::move_commitments->name => 'Engagements',
|
||||
self::produce_local->name => 'Large Gamme Locale',
|
||||
self::produce_gms->name => 'Retrouvez en GMS',
|
||||
self::produce_rhd->name => 'RHD',
|
||||
self::produce_export->name => 'Export',
|
||||
self::produce_quality->name => 'Qualité',
|
||||
self::produce_linking->name => 'Qualité',
|
||||
self::produce_linking->name => 'Liens',
|
||||
self::listening_study->name => 'On étudie',
|
||||
];
|
||||
|
||||
/**
|
||||
* Does the section have datas ?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function containsData(): bool
|
||||
{
|
||||
return match ($this) {
|
||||
self::home_missions,
|
||||
self::home_ambition,
|
||||
self::home_team,
|
||||
self::home_life,
|
||||
self::unveil_pole,
|
||||
self::hire_grow,
|
||||
self::hire_parity,
|
||||
self::commit_breeding,
|
||||
self::commit_living,
|
||||
self::commit_respect_earth,
|
||||
self::commit_feed,
|
||||
self::move_commitments,
|
||||
self::produce_linking => true,
|
||||
self::unveil_local,
|
||||
self::unveil_sites,
|
||||
self::unveil_history,
|
||||
self::unveil_commitments,
|
||||
self::hire_life,
|
||||
self::hire_formation,
|
||||
self::hire_find,
|
||||
self::commit_ambition,
|
||||
self::commit_commitments,
|
||||
self::move_life,
|
||||
self::produce_local,
|
||||
self::produce_gms,
|
||||
self::produce_rhd,
|
||||
self::produce_export,
|
||||
self::produce_quality,
|
||||
self::listening_study => false,
|
||||
}; //end match
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ckEditor type for the first WYSIWYG content of the section.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFirstWysiwygType(): string|null
|
||||
{
|
||||
return match ($this) {
|
||||
self::home_missions,
|
||||
self::home_ambition,
|
||||
self::home_team,
|
||||
self::home_life,
|
||||
self::unveil_sites,
|
||||
self::unveil_history,
|
||||
self::unveil_commitments => \App\Enums\CkEditorConfigName::base->label(),
|
||||
self::unveil_pole,
|
||||
self::unveil_local,
|
||||
self::hire_life,
|
||||
self::hire_formation,
|
||||
self::hire_parity,
|
||||
self::hire_find,
|
||||
self::commit_ambition,
|
||||
self::commit_breeding,
|
||||
self::commit_living,
|
||||
self::commit_respect_earth,
|
||||
self::commit_feed,
|
||||
self::commit_commitments,
|
||||
self::move_life,
|
||||
self::move_commitments,
|
||||
self::produce_local,
|
||||
self::produce_gms,
|
||||
self::produce_rhd,
|
||||
self::produce_export,
|
||||
self::produce_quality,
|
||||
self::listening_study => \App\Enums\CkEditorConfigName::advanced->label(),
|
||||
self::produce_linking,
|
||||
self::hire_grow, => null,
|
||||
}; //end match
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,22 @@ enum StaticPageType: int
|
|||
self::we_produce->name => 'On Produit',
|
||||
self::we_listen->name => 'On Vous Ecoute',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the enums for the page which contains sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function containsSection(): array
|
||||
{
|
||||
return [
|
||||
self::home,
|
||||
self::unveil,
|
||||
self::we_hire,
|
||||
self::we_commit,
|
||||
self::we_move,
|
||||
self::we_produce,
|
||||
self::we_listen,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
112
app/Http/Controllers/Bo/SectionController.php
Normal file
112
app/Http/Controllers/Bo/SectionController.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Sections\UpdateSectionRequest;
|
||||
use App\Models\Section;
|
||||
use App\Models\StaticPage;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SectionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Section::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = Section::query()->with('page');
|
||||
|
||||
// Filter by related page if requested.
|
||||
if (
|
||||
$request->related_page &&
|
||||
null !== StaticPage::where('type', \collect(StaticPageType::all())
|
||||
->where('name', $request->related_page)->first())->first()
|
||||
) {
|
||||
$query = $query->whereBelongsTo(
|
||||
StaticPage::where(
|
||||
'type',
|
||||
\collect(StaticPageType::all())->where('name', $request->related_page)->first()
|
||||
)->first(),
|
||||
'page'
|
||||
);
|
||||
}
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$query,
|
||||
$search,
|
||||
null,
|
||||
'h2_title',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(__('validation.custom.h2_title')),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($query);
|
||||
|
||||
/** Custom pagination */
|
||||
$sectionModelList = $this->paginate($query);
|
||||
|
||||
return view('bo.pages.sections.index', compact('sectionModelList', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param App\Models\Section $section
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Section $section): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.sections.edit', ['sectionModel' => $section]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Sections\UpdateSectionRequest $request
|
||||
* @param \App\Models\Section $section
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateSectionRequest $request, Section $section): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $section) {
|
||||
$section->fill(array_replace_recursive(
|
||||
\json_decode(\json_encode($section->toArray()), true),
|
||||
$request->validated()
|
||||
));
|
||||
|
||||
|
||||
if ($section->saveOrFail()) {
|
||||
return redirect()->route('bo.sections.edit', $section)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(__('models.classes.section'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.sections.edit', $section)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(__('models.classes.section'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
}
|
||||
30
app/Http/Controllers/Bo/UploadController.php
Normal file
30
app/Http/Controllers/Bo/UploadController.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\UploadFileRequest;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Models\Section;
|
||||
|
||||
class UploadController extends Controller
|
||||
{
|
||||
/**
|
||||
* Upload a file sent in a request.
|
||||
* Used for picture upload in CKEditor.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\UploadFileRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function uploadFile(UploadFileRequest $request)
|
||||
{
|
||||
/** @var \Illuminate\Http\UploadedFile $image */
|
||||
$image = $request->upload;
|
||||
|
||||
$path = FileStorageHelper::storeFile(new Section(), $image, true);
|
||||
|
||||
return response()->json([
|
||||
'url' => "/{$path}"
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,9 +60,11 @@ class SecureHeaders
|
|||
]) . ';',
|
||||
"img-src * data: blob:;",
|
||||
'frame-src ' . implode(' ', [
|
||||
'\'self\'',
|
||||
'https://www.google.com/recaptcha/',
|
||||
'https://recaptcha.google.com/recaptcha/',
|
||||
'https://www.google.com/maps/'
|
||||
'https://www.google.com/maps/',
|
||||
'https://www.youtube.com',
|
||||
]) . ';',
|
||||
"font-src 'self' data: " . \implode(' ', [
|
||||
// * VITE DEV
|
||||
|
|
|
|||
69
app/Http/Requests/Bo/Sections/UpdateSectionRequest.php
Normal file
69
app/Http/Requests/Bo/Sections/UpdateSectionRequest.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Sections;
|
||||
|
||||
use App\Http\Requests\Bo\UpdateMiniCrudRequest;
|
||||
|
||||
class UpdateSectionRequest extends UpdateMiniCrudRequest
|
||||
{
|
||||
/**
|
||||
* The model parameter name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $modelName = 'section';
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'h2_title' => 'required|between:3,255',
|
||||
];
|
||||
if ($this->route('section')->section !== \app\Enums\Sections\PageSectionEnum::hire_grow) {
|
||||
$rules = \array_merge($rules, [
|
||||
'text' => 'present',
|
||||
]);
|
||||
}
|
||||
if ($this->route('section')->section->containsData()) {
|
||||
$rules = \array_merge($rules, [
|
||||
'data' => 'present|array',
|
||||
'data.*' => 'required|array',
|
||||
]);
|
||||
}
|
||||
|
||||
return \array_merge(
|
||||
parent::rules(),
|
||||
$rules
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes()
|
||||
{
|
||||
return [
|
||||
'h2_title' => __('validation.custom.h2_title'),
|
||||
'text' => __('validation.attributes.content'),
|
||||
|
||||
'data' => trans('Valeurs du contenu spécifique'),
|
||||
'data.*.value' => trans('Valeur du contenu spécifique'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -26,11 +26,32 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
foreach ($this->{$this->modelName}->data as $iptName => $input) {
|
||||
$input = \json_decode(\json_encode($input), true);
|
||||
switch ($input['inputType']) {
|
||||
case InputType::text->value:
|
||||
if (is_null($this->data[$iptName]['value']) && !$input['required']) {
|
||||
$this->merge([
|
||||
$this->data[$iptName]['value'] => ''
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||
* @phpcs:disable Generic.Metrics.NestingLevel.TooHigh
|
||||
*/
|
||||
public function rules()
|
||||
|
|
@ -68,7 +89,8 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
]);
|
||||
break;
|
||||
case InputType::text->value:
|
||||
$mergeRules = $this->compileValidate('required|string|min:15', $input);
|
||||
$required = $input['required'] ? 'required' : 'nullable';
|
||||
$mergeRules = $this->compileValidate($required . '|string|min:15', $input);
|
||||
$mergeRules = collect($mergeRules)
|
||||
->map(function ($rule) {
|
||||
if (\strpos($rule, 'max:') !== false) {
|
||||
|
|
@ -106,10 +128,14 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
'minWith' => $dim['width'],
|
||||
'maxWith' => $dim['width'],
|
||||
];
|
||||
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => [
|
||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||
return ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
function (string $attribute, $value, callable $fail) use ($sizes, $input) {
|
||||
// Picture can be null.
|
||||
if ($input['required'] || $value !== null) {
|
||||
return ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
}
|
||||
}
|
||||
],
|
||||
$this->compileValidate(
|
||||
|
|
@ -127,6 +153,12 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
]),
|
||||
$input
|
||||
),
|
||||
]);
|
||||
|
||||
// Attributes are required if a picture is set.
|
||||
$required = $this->data['bloc_image']['value'] ? 'required' : 'nullable';
|
||||
|
||||
$rules = array_merge($rules, [
|
||||
"data.$iptName.alt" => $this->compileValidate("$required|string|min:5", $input),
|
||||
"data.$iptName.title" => $this->compileValidate("$required|string|min:5", $input)
|
||||
]);
|
||||
|
|
|
|||
30
app/Http/Requests/Bo/UploadFileRequest.php
Normal file
30
app/Http/Requests/Bo/UploadFileRequest.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UploadFileRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->check() and $this->ajax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'upload' => 'required|image|mimes:jpeg,png,jpg|max:2048'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,9 @@ use Illuminate\Support\Str;
|
|||
* @property string $data Minicrud content.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\StaticPage $page StaticPage Belongs to relationship.
|
||||
|
||||
*/
|
||||
class Section extends Model
|
||||
{
|
||||
|
|
@ -34,6 +37,10 @@ class Section extends Model
|
|||
'h2_title',
|
||||
'text',
|
||||
'data',
|
||||
'page_id',
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -58,15 +65,15 @@ class Section extends Model
|
|||
});
|
||||
static::updating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
ToolboxHelper::assertNoInternalBoUrls('data', $model->data);
|
||||
ToolboxHelper::assertNoInternalBoUrls('text', $model->text);
|
||||
|
||||
// * TRANSFORMATIONS
|
||||
$model->data = FileStorageHelper::storeModelFilesFromHtml($model, $model->data);
|
||||
$model->text = FileStorageHelper::storeModelFilesFromHtml($model, $model->text);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldModelFilesFromHtml(
|
||||
$model->data,
|
||||
ToolboxHelper::getOriginal($model, 'data')
|
||||
$model->text,
|
||||
ToolboxHelper::getOriginal($model, 'text')
|
||||
);
|
||||
});
|
||||
static::deleting(function () {
|
||||
|
|
@ -267,7 +274,7 @@ class Section extends Model
|
|||
public static function getCommitLivingBloc(array $data, string $content): array
|
||||
{
|
||||
$data = self::emptyButtonBooleanBloc($data, 'On Témoigne - engagements');
|
||||
$data = self::emptyWysiwygBloc($data, 'second', $content, true);
|
||||
$data = self::emptyWysiwygBloc($data, 'numéro 2', $content, \App\Enums\CkEditorConfigName::advanced);
|
||||
$data = self::emptyButtonBooleanBloc($data, 'On Bouge');
|
||||
|
||||
return $data;
|
||||
|
|
@ -283,7 +290,7 @@ class Section extends Model
|
|||
public static function getCommitRespectEarthBloc(array $data, string $content): array
|
||||
{
|
||||
$data = self::emptyButtonBooleanBloc($data, 'On Témoigne - engagements');
|
||||
$data = self::emptyWysiwygBloc($data, 'second', $content, true);
|
||||
$data = self::emptyWysiwygBloc($data, 'numéro 2', $content, \App\Enums\CkEditorConfigName::advanced);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
@ -299,9 +306,9 @@ class Section extends Model
|
|||
public static function getCommitFeedBloc(array $data, string $content, string $secondContent): array
|
||||
{
|
||||
$data = self::emptyButtonBooleanBloc($data, 'On Témoigne - engagements');
|
||||
$data = self::emptyWysiwygBloc($data, 'second', $content, true);
|
||||
$data = self::emptyWysiwygBloc($data, 'numéro 2', $content, \App\Enums\CkEditorConfigName::advanced);
|
||||
$data = self::emptyButtonBooleanBloc($data, 'On Produit');
|
||||
$data = self::emptyWysiwygBloc($data, 'third', $secondContent, true);
|
||||
$data = self::emptyWysiwygBloc($data, 'numéro 3', $secondContent, \App\Enums\CkEditorConfigName::advanced);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
@ -316,8 +323,8 @@ class Section extends Model
|
|||
*/
|
||||
public static function getCommitCommitmentsBloc(array $data, string $firstTitle, string $secondTitle): array
|
||||
{
|
||||
$data = self::emptyH3Bloc($data, 'Premier', $firstTitle);
|
||||
$data = self::emptyH3Bloc($data, 'Second', $secondTitle);
|
||||
$data = self::emptyH3Bloc($data, 'numéro 1', $firstTitle);
|
||||
$data = self::emptyH3Bloc($data, 'numéro 2', $secondTitle);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
@ -343,9 +350,9 @@ class Section extends Model
|
|||
*/
|
||||
public static function getProduceLinkingBloc(array $data, string $content, string $secondContent): array
|
||||
{
|
||||
$data = self::emptyWysiwygBloc($data, 'second', $content);
|
||||
$data = self::emptyWysiwygBloc($data, 'numéro 2', $content);
|
||||
$data = self::emptyButtonBooleanBloc($data, 'On vous écoute');
|
||||
$data = self::emptyWysiwygBloc($data, 'third', $secondContent);
|
||||
$data = self::emptyWysiwygBloc($data, 'numéro 3', $secondContent);
|
||||
$data = self::emptyButtonBooleanBloc($data, 'On se Dévoile');
|
||||
return $data;
|
||||
}
|
||||
|
|
@ -402,7 +409,7 @@ class Section extends Model
|
|||
'label' => "URL à ouvrir",
|
||||
'inputType' => InputType::url->value,
|
||||
'value' => $url,
|
||||
'validate' => $required ? 'required' : 'nullable',
|
||||
'validate' => 'url|' . ($required ? 'required' : 'nullable'),
|
||||
'required' => $required
|
||||
];
|
||||
|
||||
|
|
@ -482,9 +489,9 @@ class Section extends Model
|
|||
$snakeCaseName = Str::of($name)->snake()->ascii()->remove(['\'', '-']);
|
||||
|
||||
$data["bloc_h3_{$snakeCaseName}"] = [
|
||||
'label' => "Titre de la section {$name}",
|
||||
'label' => "Titre h3 de la section {$name}",
|
||||
'inputType' => InputType::string->value,
|
||||
'validate' => $required ? 'required' : 'nullable',
|
||||
'validate' => 'max:255|' . ($required ? 'required' : 'nullable'),
|
||||
'value' => $value,
|
||||
'required' => $required
|
||||
];
|
||||
|
|
@ -495,31 +502,43 @@ class Section extends Model
|
|||
/**
|
||||
* Empty bloc for the WYSIWYG content.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param boolean $advanced
|
||||
* @param boolean $required
|
||||
* @param array $data
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param \App\Enums\CkEditorConfigName $config
|
||||
* @param boolean $required
|
||||
* @return array
|
||||
*/
|
||||
private static function emptyWysiwygBloc(
|
||||
array $data,
|
||||
string $name,
|
||||
string $value = '',
|
||||
bool $advanced = false,
|
||||
\App\Enums\CkEditorConfigName $config = \App\Enums\CkEditorConfigName::base,
|
||||
bool $required = false
|
||||
) {
|
||||
$snakeCaseName = Str::of($name)->snake()->ascii()->remove(['\'', '-'])->remove(['\'', '-']);
|
||||
$snakeCaseName = Str::of($name)->snake()->ascii()->remove(['\'', '-']);
|
||||
|
||||
$data["bloc_{$snakeCaseName}_content"] = [
|
||||
'label' => "Titre de la section {$name}",
|
||||
'label' => "Contenu de la section {$name}",
|
||||
'inputType' => InputType::text->value,
|
||||
'validate' => $required ? 'required' : 'nullable',
|
||||
'value' => $value,
|
||||
'advanced' => $advanced,
|
||||
'required' => $required
|
||||
'required' => $required,
|
||||
'config' => $config->name
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Get the page that owns the section.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function page(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StaticPage::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ use Illuminate\Support\Str;
|
|||
* @property string $content WYSIWYG text content using ckeditor.
|
||||
* @property-read \Carbon\Carbon $created_at Created date.
|
||||
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \App\Models\Section $sections Sections Has Many relationship.
|
||||
*/
|
||||
class StaticPage extends Model
|
||||
{
|
||||
|
|
@ -83,4 +85,16 @@ class StaticPage extends Model
|
|||
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id);
|
||||
}
|
||||
|
||||
// * RELATIONS
|
||||
|
||||
/**
|
||||
* Get the sections of the page.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function sections(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Section::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
33
app/Policies/SectionPolicy.php
Normal file
33
app/Policies/SectionPolicy.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class SectionPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function update(User $authUser): bool
|
||||
{
|
||||
// phpcs:enable
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ trait MiniCrudModel
|
|||
case InputType::string->value:
|
||||
case InputType::text->value:
|
||||
case InputType::url->value:
|
||||
ToolboxHelper::assertNoInternalBoUrls('content', $input['value']);
|
||||
ToolboxHelper::assertNoInternalBoUrls('content', $input['value'] ?? '');
|
||||
break;
|
||||
default:
|
||||
throw new \ErrorException(sprintf(
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ return [
|
|||
'URI.SafeIframeRegexp' => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/|vimeo.com/|www.dailymotion.com/video/)%",
|
||||
'HTML.Doctype' => 'HTML 4.01 Transitional',
|
||||
// * Legacy filter en full avec safe legacy.
|
||||
// 'HTML.Allowed' => 'h1[style|id],h2[style|id],h3[style|id],h4[style|id],h5[style|id],h6[style|id],figure[class|style],oembed[url],div[style],b,strong,i,em,u,s,pre,code[class],a[href|title|target|rel|id],ul[style],ol[style],dl[style],li,p[style],br,span[style|class],img[width|height|alt|src|style|class|title],iframe[src|width|height|class|frameborder|style],table[style|align|border|cellspacing|cellpadding|width],thead,tbody,th[colspan|align|valign|style],tr[align|valign|style],td[style|colspan|rowspan|scope|align|valign],hr,dl,dt,mark[class]',
|
||||
'HTML.Allowed' => 'h1[style|id],h2[style|id],h3[style|id],h4[style|id],h5[style|id],h6[style|id],figure[class|style],oembed[url],div[style],b,strong,i,em,u,s,pre,code[class],a[href|title|target|rel|id],ul[style],ol[style],dl[style],li,p[style],br,span[style|class],img[width|height|alt|src|style|class|title],iframe[src|width|height|class|frameborder|style],table[style|align|border|cellspacing|cellpadding|width],thead,tbody,th[colspan|align|valign|style],tr[align|valign|style],td[style|colspan|rowspan|scope|align|valign],hr,dl,dt,mark[class]',
|
||||
// * Restricted basics.
|
||||
'HTML.Allowed' => 'br,p[style],b[style],u[style],i[style],a[href|title|target|rel],strong[style],span[class],ul[style],ol[style],li[style],h2[style],h3[style],h4[style],hr,blockquote[style]',
|
||||
// 'HTML.Allowed' => 'br,p[style],b[style],u[style],i[style],a[href|title|target|rel],strong[style],span[class],ul[style],ol[style],li[style],h2[style],h3[style],h4[style],hr,blockquote[style]',
|
||||
// * Legacy filter en full avec safe legacy.
|
||||
// 'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align,list-style-type,float,width,height,vertical-align,border,border-color,margin-left',
|
||||
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align,list-style-type,float,width,height,vertical-align,border,border-color,margin-left',
|
||||
// * Restricted basics.
|
||||
'CSS.AllowedProperties' => 'text-align,margin-left',
|
||||
// 'CSS.AllowedProperties' => 'text-align,margin-left',
|
||||
'AutoFormat.AutoParagraph' => false,
|
||||
'AutoFormat.RemoveEmpty' => false,
|
||||
'AutoFormat.RemoveEmpty.RemoveNbsp' => false,
|
||||
|
|
|
|||
|
|
@ -270,6 +270,21 @@ class SectionSeeder extends Seeder
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MiniCrud datas for Commit - Commitments section.
|
||||
*
|
||||
* @param \App\Models\Section $section
|
||||
* @return array
|
||||
*/
|
||||
private function getCommitCommitmentsData(\App\Models\Section $section)
|
||||
{
|
||||
return $section->getCommitCommitmentsBloc(
|
||||
[],
|
||||
fake()->sentence(),
|
||||
fake()->sentence()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MiniCrud datas for Move - Commitments section.
|
||||
*
|
||||
|
|
|
|||
67
resources/js/ckUploadAdaptater.js
Normal file
67
resources/js/ckUploadAdaptater.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import axios from "axios";
|
||||
import route from "./../ts/modules/route";
|
||||
|
||||
class CKUploadAdapter {
|
||||
constructor(loader) {
|
||||
// The file loader instance to use during the upload.
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
// Starts the upload process.
|
||||
upload() {
|
||||
return this.loader.file.then(
|
||||
(file) =>
|
||||
new Promise((resolve, reject) => {
|
||||
this._initRequest();
|
||||
this._sendRequest(file, resolve, reject);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// Aborts the upload process.
|
||||
abort() {
|
||||
if (this.cancel) {
|
||||
this.cancel.abort();
|
||||
}
|
||||
}
|
||||
|
||||
// Initializes the XMLHttpRequest object using the URL passed to the constructor.
|
||||
_initRequest() {
|
||||
this.cancel = axios.CancelToken.source();
|
||||
this.route = route.methods.route("bo.upload");
|
||||
}
|
||||
|
||||
// Prepares the data and sends the request.
|
||||
_sendRequest(file, resolve, reject) {
|
||||
// Prepare the form data.
|
||||
const data = new FormData();
|
||||
data.append("upload", file);
|
||||
axios
|
||||
.post(this.route, data, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
onUploadProgress: (evt) => {
|
||||
this.loader.uploadTotal = evt.total;
|
||||
this.loader.uploaded = evt.loaded;
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
resolve({
|
||||
default: response.data.url,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
reject("Le fichier à été marbré");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function CkUploadAdapterPlugin(editor) {
|
||||
editor.plugins.get("FileRepository").createUploadAdapter = (loader) => {
|
||||
return new CKUploadAdapter(loader);
|
||||
};
|
||||
}
|
||||
|
||||
export default CkUploadAdapterPlugin;
|
||||
|
|
@ -5,5 +5,6 @@ return [
|
|||
'user' => 'user',
|
||||
'activity_log' => 'activity log|activity logs',
|
||||
'static_page' => 'static page|static pages',
|
||||
'section' => 'section',
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ return [
|
|||
|
||||
'minicrud' => [
|
||||
'visibility_label' => 'Visibilité',
|
||||
'visibility_helper' => 'Vérifier qu\'il est visible.',
|
||||
'visibility_helper' => 'Cocher pour rendre visible.',
|
||||
'enum_select' => 'Sélectionnez :enum dans la liste.',
|
||||
'associated_enum' => 'Associé :enum',
|
||||
'dimensions_must_be' => 'Doit être :widthpx (largeur) par :heightpx (hauteur).',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ return [
|
|||
'classes' => [
|
||||
'user' => 'utilisateur',
|
||||
'activity_log' => 'journal d\'activité|journaux d\'activité',
|
||||
'static_page' => 'page statique|pages statiques'
|
||||
'static_page' => 'page statique|pages statiques',
|
||||
'section' => 'section',
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -227,7 +227,10 @@ return [
|
|||
'activated' => 'activé',
|
||||
'target' => 'cible',
|
||||
'static_page_type' => 'type de page',
|
||||
'seo_title' => 'titre SEO',
|
||||
'seo_description' => 'description SEO',
|
||||
'seo_title' => 'titre SEO',
|
||||
'seo_description' => 'description SEO',
|
||||
'h2_title' => 'titre h2',
|
||||
'first_content' => 'premier contenu',
|
||||
'specific_content' => 'contenu spécifique'
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import CKUploadAdapterPlugin from "./../../../js/ckUploadAdaptater";
|
||||
import "./../../../js/vendor/ckeditor";
|
||||
import trans from "./../../modules/trans";
|
||||
// import { CKUploadAdaptater } from "../../bo/CkUploadAdaptater";
|
||||
|
||||
export default defineComponent({
|
||||
name: "CkEditorComponent",
|
||||
|
|
@ -48,26 +48,460 @@ export default defineComponent({
|
|||
this.internalText = data.text ? String(data.text) : "";
|
||||
this.internalId = data.id ? data.id : "";
|
||||
this.internalRequired = Boolean(data.required);
|
||||
this.makeSuperBuild();
|
||||
this.internalAdvanced = Boolean(data.advanced);
|
||||
|
||||
// CkEditor base elements.
|
||||
this.ckeditor = this.$refs.ckeditor as HTMLElement;
|
||||
this.wordCounter = this.$refs.wordCounter as HTMLElement;
|
||||
this.verticalTopMenuOffset = document.querySelector(
|
||||
"body > #top-navbar"
|
||||
) as HTMLElement | null;
|
||||
if (!this.verticalTopMenuOffset) {
|
||||
console.warn("Could not find bo #top-navbar");
|
||||
}
|
||||
this.ui = this.verticalTopMenuOffset ? {
|
||||
viewportOffset: {
|
||||
top: this.verticalTopMenuOffset.getBoundingClientRect().height,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
},
|
||||
} : undefined;
|
||||
|
||||
// Differents CkEditor configs.
|
||||
this.minimalConfig = {
|
||||
wordCount: {
|
||||
container: this.wordCounter,
|
||||
// @ts-ignore
|
||||
onUpdate: (stats) => {
|
||||
this.chars = stats.characters;
|
||||
this.words = stats.words;
|
||||
},
|
||||
},
|
||||
ui: this.ui,
|
||||
link: {
|
||||
// Automatically add target="_blank" and rel="noopener noreferrer" to all external links.
|
||||
addTargetToExternalLinks: true,
|
||||
|
||||
// Let the users control the "download" attribute of each link.
|
||||
decorators: {
|
||||
openInNewTab: {
|
||||
mode: "manual",
|
||||
label: "Ouvrir dans un nouvel onglet",
|
||||
attributes: {
|
||||
target: "_blank",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
typing: {
|
||||
transformations: {
|
||||
extra: [
|
||||
{ from: ":)", to: "😊" },
|
||||
{ from: ":-P", to: "😛" },
|
||||
{ from: "8-)", to: "😎" },
|
||||
{ from: ";-)", to: "😉" },
|
||||
{ from: ":-D", to: "😄" },
|
||||
{ from: ":twisted:", to: "😈" },
|
||||
{ from: ":mrgreen:", to: "😁" },
|
||||
{ from: ":lol:", to: "😆" },
|
||||
{ from: ":roll:", to: "🙄" },
|
||||
{ from: ":-?", to: "😕" },
|
||||
{ from: ":cry:", to: "😢" },
|
||||
{ from: ":-o", to: "😮" },
|
||||
{ from: ":evil:", to: "😡" },
|
||||
{ from: ":-|", to: "😐" },
|
||||
{ from: ":oops:", to: "😳" },
|
||||
{ from: ":-x", to: "😠" },
|
||||
{ from: "8-O", to: "😲" },
|
||||
{ from: ":-(", to: "😧" },
|
||||
{ from: ":arrow:", to: "➡" },
|
||||
{ from: ":idea:", to: "💡" },
|
||||
],
|
||||
},
|
||||
},
|
||||
mediaEmbed: {
|
||||
previewsInData: false,
|
||||
removeProviders: [
|
||||
"dailymotion",
|
||||
"spotify",
|
||||
"vimeo",
|
||||
"youtube",
|
||||
"instagram",
|
||||
"twitter",
|
||||
"googleMaps",
|
||||
"flickr",
|
||||
"facebook",
|
||||
],
|
||||
},
|
||||
toolbar: {
|
||||
items: [
|
||||
"findAndReplace",
|
||||
"|",
|
||||
"bold",
|
||||
"italic",
|
||||
"underline",
|
||||
"strikethrough",
|
||||
"|",
|
||||
"undo",
|
||||
"redo",
|
||||
"selectAll",
|
||||
"|",
|
||||
"removeFormat",
|
||||
],
|
||||
},
|
||||
width: "auto",
|
||||
language: "fr",
|
||||
};
|
||||
this.baseConfig = {
|
||||
wordCount: {
|
||||
container: this.wordCounter,
|
||||
// @ts-ignore
|
||||
onUpdate: (stats) => {
|
||||
this.chars = stats.characters;
|
||||
this.words = stats.words;
|
||||
},
|
||||
},
|
||||
ui: this.ui,
|
||||
link: {
|
||||
// Automatically add target="_blank" and rel="noopener noreferrer" to all external links.
|
||||
addTargetToExternalLinks: true,
|
||||
|
||||
// Let the users control the "download" attribute of each link.
|
||||
decorators: {
|
||||
openInNewTab: {
|
||||
mode: "manual",
|
||||
label: "Ouvrir dans un nouvel onglet",
|
||||
attributes: {
|
||||
target: "_blank",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
typing: {
|
||||
transformations: {
|
||||
extra: [
|
||||
{ from: ":)", to: "😊" },
|
||||
{ from: ":-P", to: "😛" },
|
||||
{ from: "8-)", to: "😎" },
|
||||
{ from: ";-)", to: "😉" },
|
||||
{ from: ":-D", to: "😄" },
|
||||
{ from: ":twisted:", to: "😈" },
|
||||
{ from: ":mrgreen:", to: "😁" },
|
||||
{ from: ":lol:", to: "😆" },
|
||||
{ from: ":roll:", to: "🙄" },
|
||||
{ from: ":-?", to: "😕" },
|
||||
{ from: ":cry:", to: "😢" },
|
||||
{ from: ":-o", to: "😮" },
|
||||
{ from: ":evil:", to: "😡" },
|
||||
{ from: ":-|", to: "😐" },
|
||||
{ from: ":oops:", to: "😳" },
|
||||
{ from: ":-x", to: "😠" },
|
||||
{ from: "8-O", to: "😲" },
|
||||
{ from: ":-(", to: "😧" },
|
||||
{ from: ":arrow:", to: "➡" },
|
||||
{ from: ":idea:", to: "💡" },
|
||||
],
|
||||
},
|
||||
},
|
||||
mediaEmbed: {
|
||||
previewsInData: false,
|
||||
removeProviders: [
|
||||
"dailymotion",
|
||||
"spotify",
|
||||
"youtube",
|
||||
"vimeo",
|
||||
"instagram",
|
||||
"twitter",
|
||||
"googleMaps",
|
||||
"flickr",
|
||||
"facebook",
|
||||
],
|
||||
},
|
||||
toolbar: {
|
||||
items: [
|
||||
"heading",
|
||||
"|",
|
||||
"findAndReplace",
|
||||
"|",
|
||||
"bold",
|
||||
"italic",
|
||||
"underline",
|
||||
"strikethrough",
|
||||
"link",
|
||||
"bulletedList",
|
||||
"numberedList",
|
||||
// "code",
|
||||
// "codeBlock",
|
||||
"|",
|
||||
"outdent",
|
||||
"indent",
|
||||
"alignment",
|
||||
"|",
|
||||
"undo",
|
||||
"redo",
|
||||
"selectAll",
|
||||
"|",
|
||||
// "laravelFileManager",
|
||||
"blockQuote",
|
||||
"|",
|
||||
// "insertTable",
|
||||
// "tableColumn",
|
||||
// "tableRow",
|
||||
// "mergeTableCells",
|
||||
"|",
|
||||
// "highlight",
|
||||
// "removeHighlight",
|
||||
// "fontColor",
|
||||
// "fontBackgroundColor",
|
||||
// "fontFamily",
|
||||
"fontSize",
|
||||
"horizontalLine",
|
||||
// "specialCharacters",
|
||||
"|",
|
||||
"removeFormat",
|
||||
"|",
|
||||
"sourceEditing",
|
||||
],
|
||||
},
|
||||
width: "auto",
|
||||
language: "fr",
|
||||
image: {
|
||||
toolbar: [
|
||||
"toggleImageCaption",
|
||||
"imageTextAlternative",
|
||||
"imageStyle:inline",
|
||||
"imageStyle:alignLeft",
|
||||
"imageStyle:alignRight",
|
||||
"imageStyle:alignCenter",
|
||||
"imageStyle:side",
|
||||
"imageResize",
|
||||
"linkImage",
|
||||
],
|
||||
},
|
||||
};
|
||||
this.advancedConfig = {
|
||||
extraPlugins: [
|
||||
CKUploadAdapterPlugin,
|
||||
],
|
||||
wordCount: {
|
||||
container: this.wordCounter,
|
||||
// @ts-ignore
|
||||
onUpdate: (stats) => {
|
||||
this.chars = stats.characters;
|
||||
this.words = stats.words;
|
||||
},
|
||||
},
|
||||
ui: this.ui,
|
||||
link: {
|
||||
// Automatically add target="_blank" and rel="noopener noreferrer" to all external links.
|
||||
addTargetToExternalLinks: true,
|
||||
|
||||
// Let the users control the "download" attribute of each link.
|
||||
decorators: {
|
||||
openInNewTab: {
|
||||
mode: "manual",
|
||||
label: "Ouvrir dans un nouvel onglet",
|
||||
attributes: {
|
||||
target: "_blank",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
typing: {
|
||||
transformations: {
|
||||
extra: [
|
||||
{ from: ":)", to: "😊" },
|
||||
{ from: ":-P", to: "😛" },
|
||||
{ from: "8-)", to: "😎" },
|
||||
{ from: ";-)", to: "😉" },
|
||||
{ from: ":-D", to: "😄" },
|
||||
{ from: ":twisted:", to: "😈" },
|
||||
{ from: ":mrgreen:", to: "😁" },
|
||||
{ from: ":lol:", to: "😆" },
|
||||
{ from: ":roll:", to: "🙄" },
|
||||
{ from: ":-?", to: "😕" },
|
||||
{ from: ":cry:", to: "😢" },
|
||||
{ from: ":-o", to: "😮" },
|
||||
{ from: ":evil:", to: "😡" },
|
||||
{ from: ":-|", to: "😐" },
|
||||
{ from: ":oops:", to: "😳" },
|
||||
{ from: ":-x", to: "😠" },
|
||||
{ from: "8-O", to: "😲" },
|
||||
{ from: ":-(", to: "😧" },
|
||||
{ from: ":arrow:", to: "➡" },
|
||||
{ from: ":idea:", to: "💡" },
|
||||
],
|
||||
},
|
||||
},
|
||||
mediaEmbed: {
|
||||
previewsInData: false,
|
||||
removeProviders: [
|
||||
"dailymotion",
|
||||
"spotify",
|
||||
"vimeo",
|
||||
"instagram",
|
||||
"twitter",
|
||||
"googleMaps",
|
||||
"flickr",
|
||||
"facebook",
|
||||
],
|
||||
},
|
||||
toolbar: {
|
||||
items: [
|
||||
"style",
|
||||
"heading",
|
||||
"|",
|
||||
"findAndReplace",
|
||||
"|",
|
||||
"bold",
|
||||
"italic",
|
||||
"underline",
|
||||
"strikethrough",
|
||||
"link",
|
||||
"bulletedList",
|
||||
"numberedList",
|
||||
// "code",
|
||||
// "codeBlock",
|
||||
"|",
|
||||
"outdent",
|
||||
"indent",
|
||||
"alignment",
|
||||
"|",
|
||||
"undo",
|
||||
"redo",
|
||||
"selectAll",
|
||||
"|",
|
||||
"mediaEmbed",
|
||||
"imageUpload",
|
||||
// "laravelFileManager",
|
||||
"blockQuote",
|
||||
"|",
|
||||
"insertTable",
|
||||
// "tableColumn",
|
||||
// "tableRow",
|
||||
// "mergeTableCells",
|
||||
"|",
|
||||
// "highlight",
|
||||
// "removeHighlight",
|
||||
// "fontColor",
|
||||
// "fontBackgroundColor",
|
||||
// "fontFamily",
|
||||
"fontSize",
|
||||
"horizontalLine",
|
||||
// "specialCharacters",
|
||||
"|",
|
||||
"removeFormat",
|
||||
"|",
|
||||
"sourceEditing",
|
||||
],
|
||||
},
|
||||
table: {
|
||||
contentToolbar: [
|
||||
"tableColumn",
|
||||
"tableRow",
|
||||
"mergeTableCells",
|
||||
"tableProperties",
|
||||
"tableCellProperties",
|
||||
"toggleTableCaption",
|
||||
],
|
||||
|
||||
// Configuration of the TableProperties plugin.
|
||||
// tableProperties: {
|
||||
// ...
|
||||
// },
|
||||
|
||||
// Configuration of the TableCellProperties plugin.
|
||||
// tableCellProperties: {
|
||||
// ...
|
||||
// },
|
||||
},
|
||||
image: {
|
||||
toolbar: [
|
||||
"toggleImageCaption",
|
||||
"imageTextAlternative",
|
||||
"imageStyle:inline",
|
||||
"imageStyle:alignLeft",
|
||||
"imageStyle:alignRight",
|
||||
"imageStyle:alignCenter",
|
||||
"imageStyle:side",
|
||||
"imageResize",
|
||||
"linkImage",
|
||||
],
|
||||
},
|
||||
style: {
|
||||
definitions: [
|
||||
{
|
||||
name: "Button",
|
||||
element: "a",
|
||||
classes: [ "btn btn-primary" ]
|
||||
},
|
||||
{
|
||||
name: "Chiffre clé",
|
||||
element: "p",
|
||||
classes: [ "key-number" ]
|
||||
},
|
||||
]
|
||||
},
|
||||
width: "auto",
|
||||
language: "fr",
|
||||
};
|
||||
|
||||
let config = this.baseConfig;
|
||||
switch (data.editorConfig) {
|
||||
case "minimal":
|
||||
config = this.minimalConfig;
|
||||
break;
|
||||
case "base":
|
||||
config = this.baseConfig;
|
||||
break;
|
||||
case "advanced":
|
||||
config = this.advancedConfig;
|
||||
break;
|
||||
default:
|
||||
console.warn(data.editorConfig + " is not a correct configuration. The base config is loaded.");
|
||||
}
|
||||
|
||||
// Generate Editor.
|
||||
this.makeEditorBuild(config);
|
||||
},
|
||||
data(): {
|
||||
intName: string;
|
||||
internalText: string;
|
||||
internalId: string;
|
||||
internalRequired: boolean;
|
||||
// @ts-ignore
|
||||
editor: ClassicEditor | null;
|
||||
internalAdvanced: boolean;
|
||||
words: number;
|
||||
chars: number;
|
||||
ckeditor: HTMLElement;
|
||||
wordCounter: HTMLElement;
|
||||
verticalTopMenuOffset: HTMLElement | null;
|
||||
ui: {} | undefined;
|
||||
// @ts-ignore
|
||||
editor: ClassicEditor | null;
|
||||
// @ts-ignore
|
||||
minimalConfig: Config<EditorConfig>;
|
||||
// @ts-ignore
|
||||
baseConfig: Config<EditorConfig>;
|
||||
// @ts-ignore
|
||||
advancedConfig: Config<EditorConfig>;
|
||||
} {
|
||||
return {
|
||||
intName: "",
|
||||
internalText: "",
|
||||
internalId: "",
|
||||
internalRequired: false,
|
||||
editor: null,
|
||||
internalAdvanced: false,
|
||||
words: 0,
|
||||
chars: 0,
|
||||
ckeditor: document.createElement("ckeditor"),
|
||||
wordCounter: document.createElement("wordCounter"),
|
||||
verticalTopMenuOffset: null,
|
||||
ui: {},
|
||||
editor: null,
|
||||
minimalConfig: {},
|
||||
baseConfig: {},
|
||||
advancedConfig: {},
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
|
|
@ -92,219 +526,21 @@ export default defineComponent({
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
makeSuperBuild() {
|
||||
const self = this,
|
||||
ckeditor = this.$refs.ckeditor as HTMLElement,
|
||||
wordCounter = this.$refs.wordCounter as HTMLElement,
|
||||
// * Top Menu
|
||||
verticalTopMenuOffset = document.querySelector(
|
||||
"body > #top-navbar"
|
||||
) as HTMLElement | null;
|
||||
|
||||
if (!verticalTopMenuOffset) {
|
||||
console.warn("Could not find bo #top-navbar");
|
||||
}
|
||||
|
||||
const ui = verticalTopMenuOffset ? {
|
||||
viewportOffset: {
|
||||
top: verticalTopMenuOffset.getBoundingClientRect().height,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
},
|
||||
} : undefined;
|
||||
|
||||
makeEditorBuild(config: Config<EditorConfig>) {
|
||||
// @ts-ignore
|
||||
ClassicEditor.create(ckeditor, {
|
||||
// https://github.com/ckeditor/ckeditor5-react/issues/267
|
||||
extraPlugins: [
|
||||
// // @ts-ignore
|
||||
// (editor) => {
|
||||
// editor.plugins.get("FileRepository").createUploadAdapter = (
|
||||
// // @ts-ignore
|
||||
// loader
|
||||
// ) => {
|
||||
// // Configure the URL to the upload script in your back-end here!
|
||||
// return new CKUploadAdaptater(loader);
|
||||
// };
|
||||
// },
|
||||
],
|
||||
wordCount: {
|
||||
container: wordCounter,
|
||||
// @ts-ignore
|
||||
onUpdate: (stats) => {
|
||||
this.chars = stats.characters;
|
||||
this.words = stats.words;
|
||||
},
|
||||
},
|
||||
ui: ui,
|
||||
link: {
|
||||
// Automatically add target="_blank" and rel="noopener noreferrer" to all external links.
|
||||
addTargetToExternalLinks: true,
|
||||
|
||||
// Let the users control the "download" attribute of each link.
|
||||
decorators: {
|
||||
openInNewTab: {
|
||||
mode: "manual",
|
||||
label: "Ouvrir dans un nouvel onglet",
|
||||
attributes: {
|
||||
target: "_blank",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
typing: {
|
||||
transformations: {
|
||||
extra: [
|
||||
{ from: ":)", to: "😊" },
|
||||
{ from: ":-P", to: "😛" },
|
||||
{ from: "8-)", to: "😎" },
|
||||
{ from: ";-)", to: "😉" },
|
||||
{ from: ":-D", to: "😄" },
|
||||
{ from: ":twisted:", to: "😈" },
|
||||
{ from: ":mrgreen:", to: "😁" },
|
||||
{ from: ":lol:", to: "😆" },
|
||||
{ from: ":roll:", to: "🙄" },
|
||||
{ from: ":-?", to: "😕" },
|
||||
{ from: ":cry:", to: "😢" },
|
||||
{ from: ":-o", to: "😮" },
|
||||
{ from: ":evil:", to: "😡" },
|
||||
{ from: ":-|", to: "😐" },
|
||||
{ from: ":oops:", to: "😳" },
|
||||
{ from: ":-x", to: "😠" },
|
||||
{ from: "8-O", to: "😲" },
|
||||
{ from: ":-(", to: "😧" },
|
||||
{ from: ":arrow:", to: "➡" },
|
||||
{ from: ":idea:", to: "💡" },
|
||||
],
|
||||
},
|
||||
},
|
||||
mediaEmbed: {
|
||||
previewsInData: false,
|
||||
removeProviders: [
|
||||
"dailymotion",
|
||||
"spotify",
|
||||
"youtube",
|
||||
"vimeo",
|
||||
"instagram",
|
||||
"twitter",
|
||||
"googleMaps",
|
||||
"flickr",
|
||||
"facebook",
|
||||
],
|
||||
// // see https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-media-embed/src/mediaembedediting.js
|
||||
// providers: [
|
||||
// {
|
||||
// // display local videos in oembed tags
|
||||
// name: "localVideo",
|
||||
// url: /^(\/(?:content|storage|uploads)\/.*)/,
|
||||
// html: (match: string[]) => {
|
||||
// const path = match[1];
|
||||
|
||||
// return (
|
||||
// "<video controls allowfullscreen style=\"max-width: 90%; margin: 0 auto; display: block;\">" +
|
||||
// `<source src="${path}" type="video/mp4">` +
|
||||
// `<p>Votre navigateur ne prend pas en charge les vidéos HTML5. Voici <a href="${path}">un lien pour télécharger la vidéo</a>.</p>` +
|
||||
// "</video>"
|
||||
// );
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
},
|
||||
toolbar: {
|
||||
items: [
|
||||
"heading",
|
||||
"|",
|
||||
"findAndReplace",
|
||||
"|",
|
||||
"bold",
|
||||
"italic",
|
||||
"underline",
|
||||
"strikethrough",
|
||||
"link",
|
||||
"bulletedList",
|
||||
"numberedList",
|
||||
// "code",
|
||||
// "codeBlock",
|
||||
"|",
|
||||
"outdent",
|
||||
"indent",
|
||||
"alignment",
|
||||
"|",
|
||||
"undo",
|
||||
"redo",
|
||||
"selectAll",
|
||||
"|",
|
||||
// "laravelFileManager",
|
||||
"blockQuote",
|
||||
"|",
|
||||
// "insertTable",
|
||||
// "tableColumn",
|
||||
// "tableRow",
|
||||
// "mergeTableCells",
|
||||
"|",
|
||||
// "highlight",
|
||||
// "removeHighlight",
|
||||
// "fontColor",
|
||||
// "fontBackgroundColor",
|
||||
// "fontFamily",
|
||||
"fontSize",
|
||||
"horizontalLine",
|
||||
// "specialCharacters",
|
||||
"|",
|
||||
"removeFormat",
|
||||
"|",
|
||||
"sourceEditing",
|
||||
],
|
||||
},
|
||||
// table: {
|
||||
// contentToolbar: [
|
||||
// "tableColumn",
|
||||
// "tableRow",
|
||||
// "mergeTableCells",
|
||||
// "tableProperties",
|
||||
// "tableCellProperties",
|
||||
// "toggleTableCaption",
|
||||
// ],
|
||||
|
||||
// Configuration of the TableProperties plugin.
|
||||
// tableProperties: {
|
||||
// ...
|
||||
// },
|
||||
|
||||
// Configuration of the TableCellProperties plugin.
|
||||
// tableCellProperties: {
|
||||
// ...
|
||||
// },
|
||||
// },
|
||||
width: "auto",
|
||||
language: "fr",
|
||||
image: {
|
||||
toolbar: [
|
||||
"toggleImageCaption",
|
||||
"imageTextAlternative",
|
||||
"imageStyle:inline",
|
||||
"imageStyle:alignLeft",
|
||||
"imageStyle:alignRight",
|
||||
"imageStyle:alignCenter",
|
||||
"imageStyle:side",
|
||||
"imageResize",
|
||||
"linkImage",
|
||||
],
|
||||
},
|
||||
})
|
||||
ClassicEditor.create(this.ckeditor, config)
|
||||
// @ts-ignore
|
||||
.then((editor: ClassicEditor) => {
|
||||
let timer = null as number|null;
|
||||
const updateContent = () => {
|
||||
const data = editor.getData();
|
||||
self.internalText = data;
|
||||
self.$emit("input", data);
|
||||
this.internalText = data;
|
||||
this.$emit("input", data);
|
||||
timer = null;
|
||||
};
|
||||
// Display all toolbar elements
|
||||
// console.log(Array.from(editor.ui.componentFactory.names()));
|
||||
self.editor = Object.freeze(editor);
|
||||
this.editor = Object.freeze(editor);
|
||||
editor.setData(this.internalText);
|
||||
editor.model.document.on("change:data", () => {
|
||||
if(timer) {
|
||||
|
|
|
|||
26
resources/ts/fo/base/oembed.ts
Normal file
26
resources/ts/fo/base/oembed.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// ckeditor embeds
|
||||
const embeds = document.querySelectorAll(
|
||||
"figure.media > oembed"
|
||||
) as NodeListOf<HTMLElement>,
|
||||
template = document.getElementById("ckMedia") as HTMLDivElement | null;
|
||||
if (template) {
|
||||
for (const embed of embeds) {
|
||||
const newIframe = template.cloneNode(true) as HTMLDivElement;
|
||||
|
||||
if (embed.getAttribute("url")) {
|
||||
const embedUrl = embed.getAttribute("url") as string;
|
||||
let url;
|
||||
if(embedUrl.startsWith("www.youtube.com")) {
|
||||
url = new URL("https://" + embed.getAttribute("url") as string);
|
||||
url = new URL("https://www.youtube.com/embed/" + url.searchParams.get("v") as string);
|
||||
}
|
||||
newIframe.removeAttribute("id");
|
||||
(newIframe.querySelector("iframe") as HTMLElement).setAttribute("src", (url as URL).href);
|
||||
newIframe.classList.remove("display-none-weak");
|
||||
newIframe.classList.add("d-flex", "justify-content-center");
|
||||
embed.parentNode?.insertBefore(newIframe, embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -15,6 +15,44 @@
|
|||
</a>
|
||||
</li>
|
||||
@endcan
|
||||
@can('viewAny', \App\Models\Section::class)
|
||||
<li class="nav-item">
|
||||
<div class="dropdown">
|
||||
<a class="nav-link @if (request()->routeIs('bo.sections.*')) active @endif dropdown-toggle" data-bs-toggle="dropdown" type="button"
|
||||
aria-expanded="false">
|
||||
{{ Str::of(__('models.classes.section'))->plural()->ucfirst() }}
|
||||
</a>
|
||||
<ol class="dropdown-menu">
|
||||
@can('viewAny', \App\Models\Section::class)
|
||||
<li>
|
||||
<a class="dropdown-item @if (request()->routeIs('bo.sections.*') && !request()->related_page) active @endif" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.sections.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => Str::plural(__('models.classes.section'))]) }}">
|
||||
{{ sprintf('Toutes les %s',Str::of(__('models.classes.section'))->title()->plural()) }}
|
||||
</a>
|
||||
</li>
|
||||
@foreach (\App\Enums\StaticPageType::containsSection() as $page)
|
||||
<li>
|
||||
<a class="dropdown-item @if (request()->routeIs('bo.sections.*') && request()->related_page === $page->name) active @endif" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.sections.index', ['related_page' => $page->name]) }}"
|
||||
title="{{ __('crud.helpers.list_all', [
|
||||
'model' => sprintf(
|
||||
'%s %s %s %s',
|
||||
Str::plural(__('models.classes.section')),
|
||||
__('validation.custom.of_the.female'),
|
||||
trans_choice('models.classes.static_page', 1),
|
||||
$page->label(),
|
||||
),
|
||||
]) }}">
|
||||
{{ sprintf('%s - %s', Str::of(__('models.classes.section'))->title(), $page->label()) }}
|
||||
</a>
|
||||
</li>
|
||||
@endforeach
|
||||
@endcan
|
||||
</ol>
|
||||
</div>
|
||||
</li>
|
||||
@endcan
|
||||
@canAny(['isConceptor', 'viewAny'], \App\Models\User::class)
|
||||
<li class="nav-item">
|
||||
<div class="dropdown">
|
||||
|
|
@ -42,7 +80,7 @@
|
|||
</li>
|
||||
@endcan
|
||||
</ol>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
@endcan
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{{-- MINI CRUD EDIT WHEN JSON IS TRANSLATABLE --}}
|
||||
@php
|
||||
$data = isset($model->data) ? $model->getEmptyData() : $conceptData;
|
||||
// $data = isset($data) ? $model->getEmptyData() : $conceptData;
|
||||
// $data =
|
||||
@endphp
|
||||
@foreach ($data as $k => $input)
|
||||
@php
|
||||
|
|
@ -21,7 +22,7 @@
|
|||
'label' => $input['label'],
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'data[' . $k . '][value]',
|
||||
'value' => old("data.{$k}.value", $model->data[$k]['value'] ?? null),
|
||||
'value' => old("data.{$k}.value", $data[$k]['value'] ?? null),
|
||||
'required' => isset($input['required']) ? !empty($input['required']) : true,
|
||||
'model' => $model ?? null,
|
||||
'helper' => match (intval($input['inputType'])) {
|
||||
|
|
@ -51,7 +52,7 @@
|
|||
'label' => $input['label'],
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'data[' . $k . '][value]',
|
||||
'value' => old("data.{$k}.value", $model->data[$k]['value'] ?? null),
|
||||
'value' => old("data.{$k}.value", $data[$k]['value'] ?? null),
|
||||
'required' => isset($input['required']) ? !empty($input['required']) : true,
|
||||
'model' => $model ?? null,
|
||||
'helper' => __('validation.between.string', [
|
||||
|
|
@ -90,7 +91,7 @@
|
|||
<input class="form-control" id="number{{ $k }}" name="data[{{ $k }}][value]" type="number"
|
||||
value="{{ old("data.{$k}.value") ?? ($input['value'] ?? '') }}" aria-describedby="NumberHelp{{ $k }}"
|
||||
step="0.01" placeholder="{{ $input['label'] }}" @if (!isset($input['required']) or $input['required']) required @endif>
|
||||
@include('back::modules.input-error', [
|
||||
@include('modules.input-error', [
|
||||
'inputName' => "data.{$k}.value",
|
||||
'helperId' => "NumberHelp{$k}",
|
||||
'helper' => $input['helper'] ?? '',
|
||||
|
|
@ -105,21 +106,27 @@
|
|||
@case(intval(App\Enums\InputType::text->value))
|
||||
<div class="col-12 mb-3">
|
||||
<fieldset class="border p-3">
|
||||
<legend>{{ $input['label'] }} *</legend>
|
||||
<legend>{{ $input['label'] }} @if (!empty($input['required']))
|
||||
*
|
||||
@endif
|
||||
</legend>
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
@php
|
||||
$helper = !empty($input['required'])
|
||||
? __('validation.min.string', [
|
||||
'attribute' => $input['label'],
|
||||
'min' => 3,
|
||||
])
|
||||
: '';
|
||||
@endphp
|
||||
@include('bo.partials.inputs.text-html', [
|
||||
'id' => Str::slug($input['label']),
|
||||
'name' => "data[{$k}][value]",
|
||||
'value' => old("data.{$k}.value", $model->data[$k]['value'] ?? null),
|
||||
'value' => old("data.{$k}.value", $data[$k]['value'] ?? null),
|
||||
'model' => $model ?? null,
|
||||
'helper' =>
|
||||
__('crud.minicrud.text_warning') .
|
||||
'. ' .
|
||||
__('validation.min.string', [
|
||||
'attribute' => $input['label'],
|
||||
'min' => 3,
|
||||
]),
|
||||
'editorConfig' => $input['config'] ?? null,
|
||||
'helper' => __('crud.minicrud.text_warning') . '. ' . $helper,
|
||||
])
|
||||
@include('modules.input-error', [
|
||||
'inputName' => "data.{$k}.value",
|
||||
|
|
@ -133,7 +140,10 @@
|
|||
@case(intval(App\Enums\InputType::boolean->value))
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="border p-3">
|
||||
<legend>{{ $input['label'] }} *</legend>
|
||||
<legend>{{ $input['label'] }} @if (!empty($input['required']))
|
||||
*
|
||||
@endif
|
||||
</legend>
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
<label class="col-form-label"
|
||||
|
|
@ -141,7 +151,7 @@
|
|||
<div class="form-check form-switch ms-2">
|
||||
<input class="form-check-input ml-2" id="{{ Str::slug($input['label']) }}" name="data[{{ $k }}][value]"
|
||||
type="checkbox" value="1" aria-describedby="{{ Str::slug($input['label']) }}Help"
|
||||
@if (old("data.{$k}.value", old('_token') ? false : $model->data[$k]['value'] ?? (null ?? false))) checked @endif>
|
||||
@if (old("data.{$k}.value", old('_token') ? false : $data[$k]['value'] ?? (null ?? false))) checked @endif>
|
||||
</div>
|
||||
@include('modules.input-error', [
|
||||
'inputName' => "data.{$k}.value",
|
||||
|
|
@ -157,7 +167,10 @@
|
|||
@case(intval(App\Enums\InputType::image->value))
|
||||
<div class="col-12 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ $input['label'] }} *</legend>
|
||||
<legend>{{ $input['label'] }} @if (!empty($input['required']))
|
||||
*
|
||||
@endif
|
||||
</legend>
|
||||
<div class="row">
|
||||
{{-- PICTURE_ALT --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
|
|
@ -166,8 +179,8 @@
|
|||
'label' => __('crud.minicrud.picture_alt_label'),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'data[' . $k . '][alt]',
|
||||
'value' => old("data.{$k}.alt", $model->data[$k]['alt'] ?? null),
|
||||
'required' => true,
|
||||
'value' => old("data.{$k}.alt", $data[$k]['alt'] ?? null),
|
||||
'required' => $input['required'],
|
||||
'model' => $model ?? null,
|
||||
'helper' =>
|
||||
__('crud.minicrud.picture_alt_helper') .
|
||||
|
|
@ -188,8 +201,8 @@
|
|||
'label' => __('crud.minicrud.picture_title_label'),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'data[' . $k . '][title]',
|
||||
'value' => old("data.{$k}.title", $model->data[$k]['title'] ?? null),
|
||||
'required' => true,
|
||||
'value' => old("data.{$k}.title", $data[$k]['title'] ?? null),
|
||||
'required' => $input['required'],
|
||||
'model' => $model ?? null,
|
||||
'helper' =>
|
||||
__('crud.minicrud.picture_title_helper') .
|
||||
|
|
@ -211,12 +224,12 @@
|
|||
'width' => $input['dimensions']['width'],
|
||||
'height' => $input['dimensions']['height'],
|
||||
'model' => $model ?? null,
|
||||
'value' => old("data.{$k}.value", $model->data[$k]['value'] ?? null),
|
||||
'value' => old("data.{$k}.value", $data[$k]['value'] ?? null),
|
||||
'helper' => __('crud.minicrud.dimensions_must_be', [
|
||||
'width' => $input['dimensions']['width'],
|
||||
'height' => $input['dimensions']['height'],
|
||||
]),
|
||||
'required' => true,
|
||||
'required' => $input['required'],
|
||||
'preview' => true,
|
||||
])
|
||||
@include('modules.input-error', [
|
||||
|
|
@ -275,7 +288,7 @@
|
|||
'label' => __('crud.minicrud.associated_enum', ['enum' => $input['label']]),
|
||||
'name' => "data[{$k}][value]",
|
||||
'model' => $model ?? null,
|
||||
'value' => old("data.{$k}.value", $model->data[$k]['value'] ?? null),
|
||||
'value' => old("data.{$k}.value", $data[$k]['value'] ?? null),
|
||||
'required' => true,
|
||||
'associatedModels' => $selectedEnum ?? [],
|
||||
'helper' => __('crud.minicrud.enum_select', ['enum' => $input['label']]),
|
||||
39
resources/views/bo/pages/sections/edit.blade.php
Normal file
39
resources/views/bo/pages/sections/edit.blade.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
@extends('bo.layout', ['brParam' => $sectionModel])
|
||||
|
||||
@section('title', __('Édition d\'une :model', ['model' => __('models.classes.section')]))
|
||||
@section('description', __('Édition d\'une :model déjà existante', ['model' => __('models.classes.section')]))
|
||||
@section('breadcrumb',
|
||||
request()->route()->getName())
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap pb-3">
|
||||
<div class="d-flex align-items-start flex-row">
|
||||
<a class="btn btn-primary text-decoration-none m-0" data-bs-toggle="tooltip" href="{{ route('bo.sections.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => Str::plural(__('models.classes.section'))]) }}">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</a>
|
||||
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $sectionModel])
|
||||
</div>
|
||||
<div class="mb-md-0 mb-2">
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.section')]) }}">
|
||||
{{ Str::ucfirst(__('crud.actions.save')) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{ route('bo.sections.update', $sectionModel) }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
@include('bo.pages.sections.form')
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-primary" id="formSubmit" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.section')]) }}">
|
||||
{{ Str::ucfirst(__('crud.actions.save')) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
149
resources/views/bo/pages/sections/form.blade.php
Normal file
149
resources/views/bo/pages/sections/form.blade.php
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<div class="row">
|
||||
{{-- PAGE_ID --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(trans_choice('models.classes.static_page', '1')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.bigint-foreign-id', [
|
||||
'id' => 'sectionPage',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(trans_choice('models.classes.static_page', '1')),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.section'),
|
||||
]),
|
||||
'name' => 'page_id',
|
||||
'disabled' => true,
|
||||
'required' => false,
|
||||
'model' => $sectionModel ?? null,
|
||||
'associatedModels' => [$sectionModel->page] ?? null,
|
||||
'foreignLabel' => 'title',
|
||||
'helper' => '',
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- SECTION --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('models.classes.section')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.tinyint-enum', [
|
||||
'id' => 'sectionSection',
|
||||
'label' => __('Section associée'),
|
||||
'name' => 'section',
|
||||
'model' => $sectionModel ?? null,
|
||||
'required' => false,
|
||||
'disabled' => true,
|
||||
'associatedModels' => \App\Enums\Sections\PageSectionEnum::toArray(),
|
||||
'helper' => '',
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
{{-- H2_TITLE --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.custom.h2_title')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'sectionH2Title',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.h2_title')),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.section'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'h2_title',
|
||||
'required' => true,
|
||||
'model' => $sectionModel ?? null,
|
||||
'helper' => __('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.h2_title')),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.section'),
|
||||
]),
|
||||
'min' => 3,
|
||||
'max' => 255,
|
||||
]),
|
||||
'placeholder' => __('Un titre clair et concis'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ($sectionModel->section !== \App\Enums\Sections\PageSectionenum::hire_grow)
|
||||
<div class="row">
|
||||
{{-- CONTENT --}}
|
||||
<div class="col-12 mb-3">
|
||||
<fieldset class="border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.attributes.content')) }}</legend>
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.text-html', [
|
||||
'id' => 'sectionText',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.first_content')),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.section'),
|
||||
]),
|
||||
'name' => 'text',
|
||||
'model' => $sectionModel ?? null,
|
||||
'required' => true,
|
||||
'editorConfig' => $sectionModel->section->getFirstWysiwygType(),
|
||||
'helper' => __('crud.minicrud.text_warning'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($sectionModel->data)
|
||||
<div class="row">
|
||||
{{-- MINICRUD --}}
|
||||
<div class="col-12 mb-3">
|
||||
<button class="btn btn-primary col-form-label rounded-0 dropdown-toggle w-100" data-bs-toggle="collapse"
|
||||
data-bs-target="#minicrud" type="button" aria-expanded="false" aria-controls="minicrud">
|
||||
<b>{{ Str::ucfirst(__('validation.custom.specific_content')) }}</b>
|
||||
</button>
|
||||
<div class="collapse" id="minicrud">
|
||||
<div class="card card-body bg-light rounded-0">
|
||||
<div class="row">
|
||||
@include('bo.modules.minicrud-form-inputs', [
|
||||
'data' => $sectionModel->data,
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<p><b>{{ __('* Champs obligatoires') }}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script nonce="{{ $nonce }}">
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Submit button clone.
|
||||
const submit = document.getElementById('formSubmit')
|
||||
submitClone = document.getElementById('formSubmitClone');
|
||||
submitClone.addEventListener('click', (event) => {
|
||||
event.preventDefault();
|
||||
submit.click('');
|
||||
})
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
47
resources/views/bo/pages/sections/index-list.blade.php
Normal file
47
resources/views/bo/pages/sections/index-list.blade.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<table class="table-hover table-fix-action m-0 table">
|
||||
@if (count($sectionModelList) > 0)
|
||||
<thead>
|
||||
@include('bo.modules.table-col-sorter', [
|
||||
'cols' => [
|
||||
'page_id' => Str::ucfirst(trans_choice('models.classes.static_page', 1)),
|
||||
'section' => Str::ucfirst(__('models.classes.section')),
|
||||
'h2_title' => Str::ucfirst(__('validation.custom.h2_title')),
|
||||
'updated_at' => Str::ucfirst(__('validation.attributes.updated_at')),
|
||||
],
|
||||
])
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($sectionModelList as $sectionModel)
|
||||
<tr class="border-bottom list-item">
|
||||
<td class="text-center align-middle">{{ $sectionModel->page->title }}</td>
|
||||
<td class="text-center align-middle">{{ $sectionModel->section->label() }}</td>
|
||||
<td class="text-center align-middle">{{ $sectionModel->h2_title }}</td>
|
||||
<td class="text-center align-middle">
|
||||
<span class="badge bg-secondary">{{ $sectionModel->updated_at->isoFormat('LLLL') }}</span>
|
||||
</td>
|
||||
<td class="text-end align-middle">
|
||||
@canAny(['update'], $sectionModel)
|
||||
<div class="btn-group">
|
||||
@can('update', $sectionModel)
|
||||
<a class="btn btn-sm btn-primary" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.sections.edit', ['section' => $sectionModel]) }}"
|
||||
title="{{ Str::ucfirst(__('crud.actions.update')) }}">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</a>
|
||||
@endcan
|
||||
</div>
|
||||
@else
|
||||
<span class="text-danger" data-bs-toggle="tooltip" title="{{ __('list.right') }}">
|
||||
<i class="fa-solid fa-ban"></i>
|
||||
</span>
|
||||
@endcan
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@else
|
||||
<tr>
|
||||
<td class="border-0">{{ __('crud.other.no_model_found', ['model' => __('models.classes.section')]) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
</table>
|
||||
37
resources/views/bo/pages/sections/index.blade.php
Normal file
37
resources/views/bo/pages/sections/index.blade.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
@extends('bo.layout')
|
||||
|
||||
@section('title', Str::ucfirst(__('models.classes.section')))
|
||||
@section('description', __('Liste de toutes les :model', ['model' => Str::plural(__('models.classes.section'))]))
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap">
|
||||
@include('modules.breadcrumbs.breadcrumb-body')
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-light dropdown-toggle border" data-bs-toggle="dropdown" type="button" aria-expanded="false">
|
||||
{{ __('Sélectionnez une page') }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item @if (request()->routeIs('bo.sections.*') && !request()->related_page) active @endif" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.sections.index') }}" title="{{ __('Toutes les sections') }}">
|
||||
{{ __('Toutes') }}
|
||||
</a>
|
||||
</li>
|
||||
@foreach (\App\Enums\StaticPageType::containsSection() as $page)
|
||||
<li>
|
||||
<a class="dropdown-item @if (request()->routeIs('bo.sections.*') && request()->related_page === $page->name) active @endif" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.sections.index', ['related_page' => $page->name]) }}"
|
||||
title="{{ __('Sections de la page ') . $page->label() }}">
|
||||
{{ $page->label() }}
|
||||
</a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@include('bo.modules.search-bar')
|
||||
<div class="table-responsive mb-3">
|
||||
@include('bo.pages.sections.index-list')
|
||||
</div>
|
||||
{{ $sectionModelList->links() }}
|
||||
@endsection
|
||||
|
|
@ -9,11 +9,12 @@
|
|||
$label || The text displayed as a label. || string || OPTIONNAL || null
|
||||
$size || The number of lines to display. || integer || OPTIONNAL || null
|
||||
$required || Is the field required ? || boolean || OPTIONNAL || false
|
||||
$disabled || Is the field disabled ? || boolean || OPTIONNAL || false
|
||||
$model || The model we're creating/editing || Model class || OPTIONNAL || null
|
||||
--}}
|
||||
|
||||
@if(!empty($label))
|
||||
<label for="{{ $id }}" class="col-form-label"><b>{{ $label }} *</b></label>
|
||||
<label for="{{ $id }}" class="col-form-label"><b>{{ $label }} @if(!empty($required))*@endif</b></label>
|
||||
@endif
|
||||
<select
|
||||
id="{{ $id }}"
|
||||
|
|
@ -25,6 +26,9 @@
|
|||
aria-describedby="{{ $id }}Help"
|
||||
@if(!empty($required))
|
||||
required
|
||||
@endif
|
||||
@if(!empty($disabled))
|
||||
disabled
|
||||
@endif>
|
||||
@foreach ($associatedModels as $associatedModel)
|
||||
<option
|
||||
|
|
|
|||
|
|
@ -6,27 +6,33 @@
|
|||
$helper || The helper of the input. || string || OPTIONNAL || __('crud.minicrud.text_warning')
|
||||
$label || The text displayed as a label. || string || OPTIONNAL || null
|
||||
$required || Is the field required ? || boolean || OPTIONNAL || false
|
||||
$editorConfig || The config name. || string || OPTIONNAL || '' (base config will be loaded)
|
||||
$value || The default value of the input. || string || OPTIONNAL || ''
|
||||
$model || The model we're creating/editing || Model class || OPTIONNAL || null
|
||||
--}}
|
||||
|
||||
@if(!empty($label))
|
||||
<label for="{{ $id }}" class="col-form-label">
|
||||
<b>{{ $label }} {{ $required ?? false ? '*' : '' }}</b>
|
||||
</label>
|
||||
@if (!empty($label))
|
||||
<label class="col-form-label" for="{{ $id }}">
|
||||
<b>{{ $label }} @if (!empty($required)) *@endif</b>
|
||||
</label>
|
||||
@endif
|
||||
@php
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'text' => old($name, $model->{$name} ?? $value ?? '')
|
||||
];
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'text' => old($name, $model->{$name} ?? ($value ?? '')),
|
||||
'editorConfig' => $editorConfig ?? '',
|
||||
];
|
||||
@endphp
|
||||
<div class="ck-editor" data-json='@json($data)'></div>
|
||||
@include('modules.input-error', [
|
||||
'inputName' => $name,
|
||||
'helperId' => "{$id}Help",
|
||||
'helper' => $helper ?? __('crud.minicrud.text_warning') . '. ' . __('validation.min.string', [
|
||||
'attribute' => $input['label'],
|
||||
'min' => 15
|
||||
]),
|
||||
'helper' =>
|
||||
$helper ??
|
||||
__('crud.minicrud.text_warning') .
|
||||
'. ' .
|
||||
__('validation.min.string', [
|
||||
'attribute' => $input['label'],
|
||||
'min' => 15,
|
||||
]),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</main>
|
||||
@include('fo.modules.ckVideo')
|
||||
@stack('scripts-constants')
|
||||
@include('modules.script-constants')
|
||||
@vite(['resources/ts/fo/fo.ts'])
|
||||
|
|
|
|||
5
resources/views/fo/modules/ckVideo.blade.php
Normal file
5
resources/views/fo/modules/ckVideo.blade.php
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<div class="display-none-weak" id="ckMedia">
|
||||
<iframe src="" title="" style="display: block; margin-left: auto; margin-right:auto;" width="710" height="400"
|
||||
frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
allowfullscreen></iframe>
|
||||
</div>
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
@include('modules.script-constants')
|
||||
<script @if(isset($nonce)) nonce="{{ $nonce }}" @endif>
|
||||
if (!window.__SYSTEM._routes) {
|
||||
window.__SYSTEM._routes = {};
|
||||
}
|
||||
<script @if (isset($nonce)) nonce="{{ $nonce }}" @endif>
|
||||
if (!window.__SYSTEM._routes) {
|
||||
window.__SYSTEM._routes = {};
|
||||
}
|
||||
window.__SYSTEM._routes.bo = {
|
||||
upload: "{{ route('bo.upload') }}",
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Section;
|
||||
use App\Models\StaticPage;
|
||||
use App\Models\User;
|
||||
use Diglactic\Breadcrumbs\Breadcrumbs;
|
||||
|
|
@ -50,3 +51,15 @@ Breadcrumbs::for('bo.static_pages.edit', function (Generator $trail, StaticPage
|
|||
$trail->parent('bo.static_pages.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.static_pages.edit', $static_page));
|
||||
});
|
||||
|
||||
// * SECTIONS
|
||||
Breadcrumbs::for('bo.sections.index', function (Generator $trail) {
|
||||
$trail->push(
|
||||
Str::of(__('models.classes.section'))->plural()->ucfirst(),
|
||||
route('bo.sections.index', ['sort_col' => 'updated_at', 'sort_way' => 'desc'])
|
||||
);
|
||||
});
|
||||
Breadcrumbs::for('bo.sections.edit', function (Generator $trail, Section $section) {
|
||||
$trail->parent('bo.sections.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.sections.edit', $section));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
use App\Http\Controllers\Bo\ActivityLogController;
|
||||
use App\Http\Controllers\Bo\DashboardController;
|
||||
use App\Http\Controllers\Bo\SectionController;
|
||||
use App\Http\Controllers\Bo\StaticPageController;
|
||||
use App\Http\Controllers\Bo\UploadController;
|
||||
use App\Http\Controllers\Bo\UserController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
|
@ -46,10 +48,19 @@ Route::prefix('bo')
|
|||
])->parameters(['pages' => 'static_page'])
|
||||
->only(['index', 'edit', 'update']);
|
||||
|
||||
// * SECTIONS.
|
||||
Route::resource('sections', SectionController::class)
|
||||
->only(['index', 'edit', 'update'])
|
||||
->withoutMiddleware('htmlsanitize')
|
||||
->middleware(['htmlsanitize:text,data']);
|
||||
|
||||
Route::middleware('can:isConceptor')->group(function () {
|
||||
// * ACTIVITY LOGS.
|
||||
Route::resource('activity_logs', ActivityLogController::class)->only(['index', 'show']);
|
||||
});
|
||||
|
||||
// * UPLOAD (USED FOR CKEDITOR)
|
||||
Route::post('/upload', [UploadController::class, 'uploadFile'])->name('upload');
|
||||
});
|
||||
// * Others routes
|
||||
Route::post('theme/set', [Controller::class, 'setTheme'])->name('theme.set');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue