diff --git a/app/Http/Requests/Products/StoreProductRequest.php b/app/Http/Requests/Products/StoreProductRequest.php index 73d0eb2..4a93091 100644 --- a/app/Http/Requests/Products/StoreProductRequest.php +++ b/app/Http/Requests/Products/StoreProductRequest.php @@ -11,7 +11,7 @@ use App\Enums\Products\RangeEnum; use App\Enums\Products\RayEnum; use App\Enums\Products\SourceEnum; use App\Lib\Helpers\ToolboxHelper; -use App\Traits\Requests\HasDocument; +use App\Traits\Requests\HasDocumentAndPictureList; use App\Traits\Requests\HasPicture; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rules\Enum; @@ -20,7 +20,7 @@ use Illuminate\Validation\ValidationException; class StoreProductRequest extends FormRequest { use HasPicture; - use HasDocument; + use HasDocumentAndPictureList; /** * Determine if the user is authorized to make this request. @@ -110,7 +110,7 @@ class StoreProductRequest extends FormRequest return \array_merge( $rules, $this->pictureRules('picture', false, 1200, 900, 1200, 900), - $this->documentsRules('docs', false), + $this->documentsRules('docs'), ); } diff --git a/app/Traits/Requests/HasDocument.php b/app/Traits/Requests/HasDocumentAndPictureList.php similarity index 58% rename from app/Traits/Requests/HasDocument.php rename to app/Traits/Requests/HasDocumentAndPictureList.php index 63ea180..f5864ed 100644 --- a/app/Traits/Requests/HasDocument.php +++ b/app/Traits/Requests/HasDocumentAndPictureList.php @@ -4,24 +4,43 @@ namespace App\Traits\Requests; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Str; -trait HasDocument +trait HasDocumentAndPictureList { + /** + * Autorised mimtypes + * + * @var string[] + */ + private $autorisedMimTypes = [ + 'application/msword', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'image/jpeg', + 'image/png', + 'image/gif', + 'application/pdf', + 'application/vnd.ms-powerpoint', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'application/vnd.ms-excel', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'text/csv', + 'text/plain', + ]; + /** * Images rules * - * @param string $name - * @param boolean $required + * @param string $name * @return array */ public function documentsRules( - string $name = 'documents', - ?bool $required = null + string $name = 'docs', ): array { return [ - "{$name}" => ($required ? 'required' : 'nullable') . '|array', + "{$name}" => 'present|array', "{$name}.*" => [ - $required ? 'required' : 'nullable', + 'required', function (string $attribute, $value, callable $fail) { return $this->validateDocument($attribute, $value, $fail); } @@ -40,29 +59,32 @@ trait HasDocument */ private function validateDocument(string $attribute, mixed $value, callable $fail) { + // phpcs:enable if (!($useStorage = Storage::exists($value)) and !File::exists($value)) { $fail(trans(":attribute n'existe pas dans le système de fichier")); return; } - if ( - !\in_array($this->getUploadedFileMimeType($value, $useStorage), [ - 'application/pdf' - ]) - ) { - $fail(trans(":attribute doit être une image de type 'application/pdf'")); + if (!\in_array($this->getUploadedFileMimeType($value, $useStorage), $this->autorisedMimTypes)) { + $fail(trans(':attribute doit être un document de type :mimetypes', [ + 'mimetypes' => Str::of($this->autorisedMimTypes)->implode(' ou ') + ])); + } + $maxSize = 6 * 1024 * 1024; + if (File::size($value) > $maxSize) { + $fail(trans(':attribute doit être inférieur à :size Mo', ['size' => $maxSize / (1024 * 1024)])); } } /** - * Merges documents fields with request data. + * Merges docs fields with request data. * * @param string $name * @return void */ - protected function mergeDocuments(string $name = 'documents'): void + protected function mergeDocuments(string $name = 'docs'): void { $documents = $this->{$name}; - $this->merge(['doc' => $this->docs ?? []]); + $this->merge([$name => $this->{$name} ?? []]); $this->merge(["{$name}Validate" => []]); if (is_array($documents)) { foreach ($documents as $key => $documentPath) { diff --git a/app/Traits/Requests/HasPicture.php b/app/Traits/Requests/HasPicture.php index ff664c4..d18ad34 100644 --- a/app/Traits/Requests/HasPicture.php +++ b/app/Traits/Requests/HasPicture.php @@ -138,6 +138,11 @@ trait HasPicture ) { $fail(trans(":attribute doit être une image de type 'image/jpeg,image/jpg,image/png,image/gif'")); } + $filesize = \filesize($fileFullPath); + $maxSize = 6 * 1024 * 1024; + if ($filesize === false || $filesize > $maxSize) { + $fail(trans(':attribute doit être inférieur à :size Mo', ['size' => $maxSize / (1024 * 1024)])); + } if (!($dimensions = \getimagesize($fileFullPath)) or !isset($dimensions[0]) or !isset($dimensions[1])) { $fail(trans(":attribute impossible de valider les dimensions")); } else { diff --git a/resources/sass/base/_common.scss b/resources/sass/base/_common.scss index 479a389..47ab386 100644 --- a/resources/sass/base/_common.scss +++ b/resources/sass/base/_common.scss @@ -26,3 +26,9 @@ display: block; } } + +.pagination-custom .dropdown-menu { + overflow: auto; + min-width: 5rem; + max-height: 178px; +} diff --git a/resources/ts/components/MultipleDocumentsInputComponent.vue b/resources/ts/components/MultipleDocumentsInputComponent.vue index f2e0425..ed33fa9 100644 --- a/resources/ts/components/MultipleDocumentsInputComponent.vue +++ b/resources/ts/components/MultipleDocumentsInputComponent.vue @@ -7,11 +7,11 @@
- - - - -
-
-

- {{ - parseValidationInput( - `${intName.replace(/[\[\]']+/g, "")}.${n - 1}`, - intAllErrors - ) - }} -

- - -