added homepage

This commit is contained in:
Nicolas Demangeat 2023-10-23 10:42:57 +02:00
parent 34235baa16
commit e1994588e1
19 changed files with 620 additions and 7 deletions

View file

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Http\Requests\Bo\Homepage\UpdateHomepageRequest;
use App\Models\Homepage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class HomepageController extends Controller
{
/**
* Create the controller instance.
*/
public function __construct()
{
$this->authorizeResource(Homepage::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 $homepageModels */
$homepageModels = Homepage::query();
/** @var string $search Search field */
$search = $request->search;
if ($search) {
$this->searchQuery(
$homepageModels,
$search,
null,
'title_part1',
'title_part2',
'title_part3'
);
}
$searchFields = \implode(', ', [
Str::ucfirst(trans('validation.attributes.title'))
]);
/** Sort columns with a query */
$this->sortQuery($homepageModels);
/** Custom pagination */
$homepageModels = $this->paginate($homepageModels);
return view('bo.pages.homepages.index', compact('homepageModels', 'search', 'searchFields'));
}
/**
* Show the form for editing the specified resource.
*
* @param App\Models\Homepage $homepage
* @return \Illuminate\Contracts\View\View
*/
public function edit(Homepage $homepage): \Illuminate\Contracts\View\View
{
return view('bo.pages.homepages.edit', ['homepageModel' => $homepage]);
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\Bo\Homepages\UpdateHomepageRequest $request
* @param \App\Models\Homepage $homepage
* @return \Illuminate\Http\RedirectResponse
*/
public function update(UpdateHomepageRequest $request, Homepage $homepage): \Illuminate\Http\RedirectResponse
{
return DB::transaction(function () use ($request, $homepage) {
$homepage->fill($request->validated());
if ($homepage->saveOrFail()) {
return redirect()->route('bo.homepages.edit', $homepage)
->with('success', __('crud.messages.has_been_updated', [
'model' => Str::ucfirst(__('models.classes.homepage'))
]));
}
return redirect()->route('bo.homepages.edit', $homepage)
->with('error', __('crud.messages.cannot_be_updated', [
'model' => Str::ucfirst(__('models.classes.homepage'))
]));
});
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace App\Http\Requests\Bo\Homepage;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
class StoreHomepageRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'title_part1' => 'required|string|between:3,255',
'title_part2' => 'required|string|between:3,255',
'title_part3' => 'required|string|between:3,255',
'picture_alt' => 'required|string|between:3,255',
'picture_title' => 'required|string|between:3,255',
'presentation_title' => 'required|string|between:3,255',
'presentation_content' => 'required|string',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 640, 390, 640, 390, false),
);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Bo\Homepage;
class UpdateHomepageRequest extends StoreHomepageRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return \array_merge(
parent::rules()
);
}
}

View file

@ -8,9 +8,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property string $title_part_1 Première partie du titre h1 de l'accueil.
* @property string $title_part_2 Deuxième partie du titre h1 de l'accueil.
* @property string $title_part_3 Dernière partie du titre h1 de l'accueil.
* @property string $title_part1 Première partie du titre h1 de l'accueil.
* @property string $title_part2 Deuxième partie du titre h1 de l'accueil.
* @property string $title_part3 Dernière partie du titre h1 de l'accueil.
* @property string $picture Path de l'image de la page d'accueil (640px * 390px).
* @property string $picture_alt Attribut alt de l'image de la page d'accueil.
* @property string $picture_title Attribut title de l'image de la page d'accueil.
@ -30,9 +30,9 @@ class Homepage extends Model
* @var array<int, string>
*/
protected $fillable = [
'title_part_1',
'title_part_2',
'title_part_3',
'title_part1',
'title_part2',
'title_part3',
'picture',
'picture_alt',
'picture_title',

View file

@ -0,0 +1,43 @@
<?php
namespace App\Policies;
use App\Enums\Users\RoleEnum;
use App\Models\User;
use App\Policies\Rules\UserStaticRules;
class HomepagePolicy
{
/**
* 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 view the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function view(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
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
}

View file

@ -3,6 +3,7 @@
namespace App\Providers;
use App\Models\Commitment;
use App\Models\Homepage;
use App\Models\Range;
use App\Models\SeasonalSection;
use App\Models\User;
@ -48,6 +49,7 @@ class RouteServiceProvider extends ServiceProvider
Route::model('commitment', Commitment::class);
Route::model('range', Range::class);
Route::model('seasonal_section', SeasonalSection::class);
Route::model('homepage', Homepage::class);
}
/**

View file

@ -28,6 +28,7 @@ return [
'seo_title' => 'Must give a precise description of the page, which is recommended for optimum
positioning in search engines (<title> tag).',
'seo_description' => 'Must give a precise description of the page content (<meta> description tag).',
'required_fields' => 'Required fields',
],
'libs' => [

View file

@ -6,6 +6,7 @@ return [
'activity_log' => 'activity log|activity logs',
'static_page' => 'static page|static pages',
'commitment' => 'commitment',
'range' => 'range'
'range' => 'range',
'homepage' => 'homepage'
]
];

View file

@ -238,6 +238,11 @@ return [
'picture_productsheet' => 'productsheet picture',
'picture_thumbnail' => 'thumbnail',
'background' => 'background',
'picture' => 'picture',
'presentation_title' => 'presentation title',
'title_part1' => 'title part one',
'title_part2' => 'title part two',
'title_part3' => 'title part three',
],
];

View file

@ -28,6 +28,7 @@ return [
'seo_title' => 'Doit décrire précisément la page, recommandation pour un positionnement
optimal dans les moteurs de recherche (balise <title>).',
'seo_description' => 'Doit décrire précisément le contenu de la page (balise <meta> description).',
'required_fields' => 'Champs obligatoires',
],

View file

@ -8,5 +8,6 @@ return [
'commitment' => 'engagement',
'range' => 'gamme',
'seasonal_section' => 'section saisonnière|sections saisonnières',
'homepage' => 'page d\'accueil'
]
];

View file

@ -240,5 +240,10 @@ return [
'picture_productsheet' => 'image de la fiche produit',
'picture_thumbnail' => 'vignette',
'background' => 'fond',
'picture' => 'image',
'presentation_title' => 'titre de présentation',
'title_part1' => 'première partie du titre',
'title_part2' => 'seconde partie du titre',
'title_part3' => 'dernière partie du titre',
],
];

View file

@ -41,6 +41,15 @@
</a>
</li>
@endcan
@can('viewAny', \App\Models\Homepage::class)
<li>
<a class="nav-link @if (request()->routeIs('bo.homepages.*')) active @endif" data-bs-toggle="tooltip"
href="{{ route('bo.homepages.index') }}"
title="{{ __('crud.helpers.list_all', ['model' => Str::of(__('models.classes.commitment'))->plural()]) }}">
{{ Str::of(__('models.classes.homepage'))->plural()->ucfirst() }}
</a>
</li>
@endcan
@canAny(['isConceptor', 'viewAny'], \App\Models\User::class)
<li class="nav-item">
<div class="dropdown">

View file

@ -0,0 +1,39 @@
@extends('bo.layout', ['brParam' => $homepageModel])
@section('title', trans_choice('crud.meta.title.edit', 0, ['model' => __('models.classes.homepage')]))
@section('description', trans_choice('crud.meta.description.edit', 0, ['model' => __('models.classes.homepage')]))
@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.homepages.index') }}"
title="{{ __('crud.helpers.list_all', ['model' => Str::plural(__('models.classes.homepage'))]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $homepageModel])
</div>
<div class="mb-md-0 mb-2">
<form class="btn-group confirmDeleteTS" action="{{ route('bo.homepages.edit', $homepageModel) }}" method="POST" novalidate>
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.homepage')]) }}">
{{ Str::ucfirst(__('crud.actions.save')) }}
</button>
</form>
</div>
</div>
<form action="{{ route('bo.homepages.update', $homepageModel) }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('bo.pages.homepages.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.homepage')]) }}">
{{ Str::ucfirst(__('crud.actions.save')) }}
</button>
</div>
</div>
</form>
@endsection

View file

@ -0,0 +1,245 @@
<div class="row">
{{-- TITLE PART 1 --}}
<div class="col-12 col-md-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ Str::ucfirst(__('validation.custom.title_part1')) }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'homepageTitlePart1',
'label' => __(':field :inter:model', [
'field' => Str::ucfirst(__('validation.custom.title_part1')),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'hasWordCounter' => true,
'name' => 'title_part1',
'required' => true,
'model' => $homepageModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.title_part1'),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __('crud.placeholders.beautiful', ['field' => __('validation.attributes.title')]),
])
</div>
</div>
</fieldset>
</div>
{{-- TITLE PART 2 --}}
<div class="col-12 col-md-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ Str::ucfirst(__('validation.custom.title_part2')) }}2</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'homepageTitlePart2',
'label' => __(':field :inter:model', [
'field' => Str::ucfirst(__('validation.custom.title_part2')),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'hasWordCounter' => true,
'name' => 'title_part2',
'required' => true,
'model' => $homepageModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.title_part2'),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __('crud.placeholders.beautiful', ['field' => __('validation.attributes.title')]),
])
</div>
</div>
</fieldset>
</div>
{{-- TITLE PART 3 --}}
<div class="col-12 col-md-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ Str::ucfirst(__('validation.custom.title_part3')) }}3</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'homepageTitlePart3',
'label' => __(':field :inter:model', [
'field' => Str::ucfirst(__('validation.custom.title_part3')),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'hasWordCounter' => true,
'name' => 'title_part3',
'required' => true,
'model' => $homepageModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.title_part3'),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __('crud.placeholders.beautiful', ['field' => __('validation.attributes.title')]),
])
</div>
</div>
</fieldset>
</div>
{{-- PICTURE --}}
<div class="col-12 pb-3">
<fieldset class="h-100 border p-3">
<legend>{{ Str::ucfirst(__('validation.custom.picture')) }}</legend>
<div class="row mb-3">
{{-- PICTURE_ALT --}}
<div class="col-12 col-md-6 m-md-0 mb-3">
@include('bo.partials.inputs.varchar', [
'id' => 'homepagePictureAlt',
'label' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => Str::ucfirst(__('validation.custom.attribute_alt')),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.custom.picture'),
'inter2' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'hasWordCounter' => true,
'name' => 'picture_alt',
'required' => true,
'model' => $homepageModel ?? null,
'helper' => __('crud.minicrud.picture_alt_helper'),
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => Str::ucfirst(__('validation.custom.attribute_alt')),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.custom.picture'),
'inter2' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
])
</div>
{{-- PICTURE_TITLE --}}
<div class="col-12 col-md-6 mb-3">
@include('bo.partials.inputs.varchar', [
'id' => 'homepagePictureTitle',
'label' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => Str::ucfirst(__('validation.custom.attribute_title')),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.custom.picture'),
'inter2' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'hasWordCounter' => true,
'name' => 'picture_title',
'required' => true,
'model' => $homepageModel ?? null,
'helper' => __('crud.minicrud.picture_title_helper'),
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => Str::ucfirst(__('validation.custom.attribute_title')),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.custom.picture'),
'inter2' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
])
</div>
{{-- PICTURE --}}
<div class="col-12">
@include('bo.partials.inputs.varchar-picture', [
'id' => 'homepagePicture',
'name' => 'picture',
'width' => 640,
'height' => 390,
'model' => $homepageModel ?? null,
'helper' => __('crud.minicrud.dimensions_must_be', [
'widthpx' => '640px',
'heightpx' => '390px',
]),
'required' => true,
'preview' => true,
])
</div>
</div>
</fieldset>
</div>
{{-- PRESENTATION TITLE --}}
<div class="col-12 col-md-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ Str::ucfirst(__('validation.custom.presentation_title')) }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'homepagePresentationTitle',
'label' => __(':field :inter:model', [
'field' => Str::ucfirst(__('validation.custom.presentation_title')),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'hasWordCounter' => true,
'name' => 'presentation_title',
'required' => true,
'model' => $homepageModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.presentation_title'),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __('crud.placeholders.beautiful', ['field' => __('validation.attributes.title')]),
])
</div>
</div>
</fieldset>
</div>
{{-- 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' => 'homepagePresentationContent',
'label' => __(':field :inter:model', [
'field' => Str::ucfirst(__('validation.attributes.content')),
'inter' => __('validation.custom.of_the.female'),
'model' => __('models.classes.homepage'),
]),
'name' => 'presentation_content',
'model' => $homepageModel ?? null,
'required' => true,
'helper' => __('crud.minicrud.text_warning'),
])
</div>
</div>
</fieldset>
</div>
<div class="row">
<div class="col text-center">
<p><b>* {{ __('crud.helpers.required_fields') }}</b></p>
</div>
</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

View file

@ -0,0 +1,62 @@
<table class="table-hover table-fix-action m-0 table">
@if (count($homepageModels) > 0)
<thead>
@include('bo.modules.table-col-sorter', [
'cols' => [
'title_part1' => Str::ucfirst(__('validation.custom.title_part1')),
'title_part2' => Str::ucfirst(__('validation.custom.title_part2')),
'title_part3' => Str::ucfirst(__('validation.custom.title_part3')),
'picture' => Str::ucfirst(__('validation.custom.picture')),
'presentation_title' => Str::ucfirst(__('validation.custom.presentation_title')),
'presentation_content' => Str::ucfirst(__('validation.attributes.content')),
'updated_at' => Str::ucfirst(__('validation.attributes.updated_at')),
],
])
</thead>
<tbody>
@foreach ($homepageModels as $homepageModel)
<tr class="border-bottom list-item">
<td class="text-center align-middle">{{ $homepageModel->title_part1 }}</td>
<td class="text-center align-middle">{{ $homepageModel->title_part2 }}</td>
<td class="text-center align-middle">{{ $homepageModel->title_part3 }}</td>
<td class="text-center align-middle">
<img src="{{ asset($homepageModel->picture) }}" title="{{ $homepageModel->picture_title }}"
alt="{{ $homepageModel->picture_alt }}" height="50px">
</td>
<td class="text-center align-middle">{{ $homepageModel->presentation_title }}</td>
<td class="text-center align-middle">{!! Str::limit($homepageModel->presentation_content, 100) !!}</td>
<td class="text-center align-middle">
<span class="badge bg-secondary">{{ $homepageModel->updated_at->isoFormat('LLLL') }}</span>
</td>
@php
$routeName = request()
->route()
->getName();
@endphp
<td class="text-end align-middle">
@canAny(['update'], $homepageModel)
<form class="btn-group confirmDeleteTS" action="{{ route('bo.homepages.edit', $homepageModel) }}" method="POST"
novalidate>
@can('update', $homepageModel)
<a class="btn btn-sm btn-primary" data-bs-toggle="tooltip"
href="{{ route('bo.homepages.edit', ['homepage' => $homepageModel]) }}"
title="{{ Str::ucfirst(__('crud.actions.update')) }}">
<i class="fa-solid fa-pencil"></i>
</a>
@endcan
</form>
@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.homepage')]) }}</td>
</tr>
@endif
</table>

View file

@ -0,0 +1,16 @@
@extends('bo.layout')
@section('title',
Str::of(__('models.classes.homepage'))->plural()->ucfirst())
@section('description', trans_choice('crud.meta.description.index', 0, ['model' => Str::plural(__('models.classes.homepage'))]))
@section('content')
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap">
@include('modules.breadcrumbs.breadcrumb-body')
</div>
@include('bo.modules.search-bar')
<div class="table-responsive mb-3">
@include('bo.pages.homepages.index-list')
</div>
{{ $homepageModels->links() }}
@endsection

View file

@ -2,6 +2,7 @@
use App\Models\ActivityLog;
use App\Models\Commitment;
use App\Models\Homepage;
use App\Models\Range;
use App\Models\SeasonalSection;
use App\Models\StaticPage;
@ -113,3 +114,15 @@ Breadcrumbs::for('bo.seasonalsections.duplicate', function (Generator $trail) {
$trail->parent('bo.seasonalsections.index');
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
});
// * HOMEPAGES
Breadcrumbs::for('bo.homepages.index', function (Generator $trail) {
$trail->push(
Str::of(trans('models.classes.homepage'))->plural()->ucfirst(),
route('bo.homepages.index', ['sort_col' => 'updated_at', 'sort_way' => 'desc'])
);
});
Breadcrumbs::for('bo.homepages.edit', function (Generator $trail, Homepage $homepage) {
$trail->parent('bo.homepages.index');
$trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.homepages.edit', $homepage));
});

View file

@ -3,6 +3,7 @@
use App\Http\Controllers\Bo\ActivityLogsController;
use App\Http\Controllers\Bo\CommitmentController;
use App\Http\Controllers\Bo\DashboardController;
use App\Http\Controllers\Bo\HomepageController;
use App\Http\Controllers\Bo\StaticPageController;
use App\Http\Controllers\Bo\RangeController;
use App\Http\Controllers\Bo\SeasonalSectionController;
@ -88,6 +89,11 @@ Route::prefix('bo')
SeasonalSectionController::class, 'duplicate'
])->name('seasonalsections.duplicate');
// * HOMEPAGE
Route::resource('homepages', HomepageController::class)->only(['index', 'edit', 'update'])
->withoutMiddleware('htmlsanitize')
->middleware('htmlsanitize:presentation_content');
Route::middleware('can:isConceptor')->group(function () {
// * ACTIVITY LOGS.
Route::resource('activity_logs', ActivityLogsController::class)->only(['index', 'show']);