From d99f1b2a81f59162adeed5955bf13631d08bb0f7 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Fri, 17 Nov 2023 16:07:28 +0100 Subject: [PATCH] WIP: Adding crud sections" " --- .eslintrc.json | 3 + app/Enums/CkEditorConfigName.php | 23 + app/Enums/Sections/PageSectionEnum.php | 92 ++- app/Enums/StaticPageType.php | 18 + app/Http/Controllers/Bo/SectionController.php | 112 +++ app/Http/Controllers/Bo/UploadController.php | 30 + app/Http/Middleware/SecureHeaders.php | 4 +- .../Bo/Sections/UpdateSectionRequest.php | 69 ++ .../Requests/Bo/UpdateMiniCrudRequest.php | 40 +- app/Http/Requests/Bo/UploadFileRequest.php | 30 + app/Models/Section.php | 69 +- app/Models/StaticPage.php | 14 + app/Policies/SectionPolicy.php | 33 + app/Traits/Models/MiniCrudModel.php | 2 +- config/purifier.php | 8 +- database/seeders/SectionSeeder.php | 15 + resources/js/ckUploadAdaptater.js | 67 ++ resources/lang/en/models.php | 1 + resources/lang/fr/crud.php | 2 +- resources/lang/fr/models.php | 3 +- resources/lang/fr/validation.php | 7 +- .../ts/bo/components/CkEditorComponent.vue | 652 ++++++++++++------ resources/ts/fo/base/oembed.ts | 26 + resources/views/bo/layouts/nav-list.blade.php | 40 +- .../modules/minicrud-form-inputs.blade.php | 59 +- .../views/bo/pages/sections/edit.blade.php | 39 ++ .../views/bo/pages/sections/form.blade.php | 149 ++++ .../bo/pages/sections/index-list.blade.php | 47 ++ .../views/bo/pages/sections/index.blade.php | 37 + .../inputs/bigint-foreign-id.blade.php | 6 +- .../bo/partials/inputs/text-html.blade.php | 30 +- resources/views/fo/layout.blade.php | 1 + resources/views/fo/modules/ckVideo.blade.php | 5 + .../views/modules/script-routes.blade.php | 11 +- routes/breadcrumbs-bo.php | 13 + routes/web-bo.php | 11 + 36 files changed, 1474 insertions(+), 294 deletions(-) create mode 100644 app/Enums/CkEditorConfigName.php create mode 100644 app/Http/Controllers/Bo/SectionController.php create mode 100644 app/Http/Controllers/Bo/UploadController.php create mode 100644 app/Http/Requests/Bo/Sections/UpdateSectionRequest.php create mode 100644 app/Http/Requests/Bo/UploadFileRequest.php create mode 100644 app/Policies/SectionPolicy.php create mode 100644 resources/js/ckUploadAdaptater.js create mode 100644 resources/ts/fo/base/oembed.ts rename resources/views/{ => bo}/modules/minicrud-form-inputs.blade.php (90%) create mode 100644 resources/views/bo/pages/sections/edit.blade.php create mode 100644 resources/views/bo/pages/sections/form.blade.php create mode 100644 resources/views/bo/pages/sections/index-list.blade.php create mode 100644 resources/views/bo/pages/sections/index.blade.php create mode 100644 resources/views/fo/modules/ckVideo.blade.php diff --git a/.eslintrc.json b/.eslintrc.json index 42a2da7..1e8c802 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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": { diff --git a/app/Enums/CkEditorConfigName.php b/app/Enums/CkEditorConfigName.php new file mode 100644 index 0000000..1acf0b5 --- /dev/null +++ b/app/Enums/CkEditorConfigName.php @@ -0,0 +1,23 @@ +name => 'minimal', + self::base->name => 'base', + self::advanced->name => 'advanced', + ]; +} diff --git a/app/Enums/Sections/PageSectionEnum.php b/app/Enums/Sections/PageSectionEnum.php index a05d00c..c5b7c5e 100644 --- a/app/Enums/Sections/PageSectionEnum.php +++ b/app/Enums/Sections/PageSectionEnum.php @@ -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 + } } diff --git a/app/Enums/StaticPageType.php b/app/Enums/StaticPageType.php index 93ad19f..519fa1d 100644 --- a/app/Enums/StaticPageType.php +++ b/app/Enums/StaticPageType.php @@ -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, + ]; + } } diff --git a/app/Http/Controllers/Bo/SectionController.php b/app/Http/Controllers/Bo/SectionController.php new file mode 100644 index 0000000..bc59619 --- /dev/null +++ b/app/Http/Controllers/Bo/SectionController.php @@ -0,0 +1,112 @@ +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')) + ])); + }); + } +} diff --git a/app/Http/Controllers/Bo/UploadController.php b/app/Http/Controllers/Bo/UploadController.php new file mode 100644 index 0000000..cf59e4b --- /dev/null +++ b/app/Http/Controllers/Bo/UploadController.php @@ -0,0 +1,30 @@ +upload; + + $path = FileStorageHelper::storeFile(new Section(), $image, true); + + return response()->json([ + 'url' => "/{$path}" + ]); + } +} diff --git a/app/Http/Middleware/SecureHeaders.php b/app/Http/Middleware/SecureHeaders.php index db85da3..8b54fef 100644 --- a/app/Http/Middleware/SecureHeaders.php +++ b/app/Http/Middleware/SecureHeaders.php @@ -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 diff --git a/app/Http/Requests/Bo/Sections/UpdateSectionRequest.php b/app/Http/Requests/Bo/Sections/UpdateSectionRequest.php new file mode 100644 index 0000000..85a2d7b --- /dev/null +++ b/app/Http/Requests/Bo/Sections/UpdateSectionRequest.php @@ -0,0 +1,69 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|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'), + ]; + } +} diff --git a/app/Http/Requests/Bo/UpdateMiniCrudRequest.php b/app/Http/Requests/Bo/UpdateMiniCrudRequest.php index f845c96..8db6ebb 100644 --- a/app/Http/Requests/Bo/UpdateMiniCrudRequest.php +++ b/app/Http/Requests/Bo/UpdateMiniCrudRequest.php @@ -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) ]); diff --git a/app/Http/Requests/Bo/UploadFileRequest.php b/app/Http/Requests/Bo/UploadFileRequest.php new file mode 100644 index 0000000..5e9e7e8 --- /dev/null +++ b/app/Http/Requests/Bo/UploadFileRequest.php @@ -0,0 +1,30 @@ +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' + ]; + } +} diff --git a/app/Models/Section.php b/app/Models/Section.php index d741105..a503f21 100644 --- a/app/Models/Section.php +++ b/app/Models/Section.php @@ -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); + } } diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php index 97aab70..400c9c2 100644 --- a/app/Models/StaticPage.php +++ b/app/Models/StaticPage.php @@ -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); + } } diff --git a/app/Policies/SectionPolicy.php b/app/Policies/SectionPolicy.php new file mode 100644 index 0000000..d1fc9e9 --- /dev/null +++ b/app/Policies/SectionPolicy.php @@ -0,0 +1,33 @@ +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( diff --git a/config/purifier.php b/config/purifier.php index 59cb78b..139bc81 100644 --- a/config/purifier.php +++ b/config/purifier.php @@ -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, diff --git a/database/seeders/SectionSeeder.php b/database/seeders/SectionSeeder.php index eb4d7c3..5965bf1 100644 --- a/database/seeders/SectionSeeder.php +++ b/database/seeders/SectionSeeder.php @@ -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. * diff --git a/resources/js/ckUploadAdaptater.js b/resources/js/ckUploadAdaptater.js new file mode 100644 index 0000000..1772f05 --- /dev/null +++ b/resources/js/ckUploadAdaptater.js @@ -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; diff --git a/resources/lang/en/models.php b/resources/lang/en/models.php index a709346..2c988ce 100644 --- a/resources/lang/en/models.php +++ b/resources/lang/en/models.php @@ -5,5 +5,6 @@ return [ 'user' => 'user', 'activity_log' => 'activity log|activity logs', 'static_page' => 'static page|static pages', + 'section' => 'section', ] ]; diff --git a/resources/lang/fr/crud.php b/resources/lang/fr/crud.php index 72c5d72..f3dc47b 100644 --- a/resources/lang/fr/crud.php +++ b/resources/lang/fr/crud.php @@ -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).', diff --git a/resources/lang/fr/models.php b/resources/lang/fr/models.php index e0bf371..cc24db9 100644 --- a/resources/lang/fr/models.php +++ b/resources/lang/fr/models.php @@ -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', ] ]; diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index f3b7d86..fd9a539 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -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' ], ]; diff --git a/resources/ts/bo/components/CkEditorComponent.vue b/resources/ts/bo/components/CkEditorComponent.vue index 2259319..c8cec3d 100644 --- a/resources/ts/bo/components/CkEditorComponent.vue +++ b/resources/ts/bo/components/CkEditorComponent.vue @@ -15,9 +15,9 @@ +@endpush diff --git a/resources/views/bo/pages/sections/index-list.blade.php b/resources/views/bo/pages/sections/index-list.blade.php new file mode 100644 index 0000000..5b1c22e --- /dev/null +++ b/resources/views/bo/pages/sections/index-list.blade.php @@ -0,0 +1,47 @@ + + @if (count($sectionModelList) > 0) + + @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')), + ], + ]) + + + @foreach ($sectionModelList as $sectionModel) + + + + + + + + @endforeach + + @else + + + + @endif +
{{ $sectionModel->page->title }}{{ $sectionModel->section->label() }}{{ $sectionModel->h2_title }} + {{ $sectionModel->updated_at->isoFormat('LLLL') }} + + @canAny(['update'], $sectionModel) +
+ @can('update', $sectionModel) + + + + @endcan +
+ @else + + + + @endcan +
{{ __('crud.other.no_model_found', ['model' => __('models.classes.section')]) }}
diff --git a/resources/views/bo/pages/sections/index.blade.php b/resources/views/bo/pages/sections/index.blade.php new file mode 100644 index 0000000..0e46016 --- /dev/null +++ b/resources/views/bo/pages/sections/index.blade.php @@ -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') +
+ @include('modules.breadcrumbs.breadcrumb-body') + +
+ @include('bo.modules.search-bar') +
+ @include('bo.pages.sections.index-list') +
+ {{ $sectionModelList->links() }} +@endsection diff --git a/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php b/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php index c0f9f1e..cf04655 100644 --- a/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php +++ b/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php @@ -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)) - + @endif