Skip to content

Commit 12a358f

Browse files
committed
Improve README, give more info about FileSetter
1 parent 62ad1ee commit 12a358f

File tree

4 files changed

+83
-16
lines changed

4 files changed

+83
-16
lines changed

README.md

+80-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This package is to upload different media files to Local or remote Amazon S3 sto
2929

3030
Run the composer command:
3131

32-
`composer require itstructure/laravel-media-file-uploader "~1.0.1"`
32+
`composer require itstructure/laravel-media-file-uploader "~1.0.2"`
3333

3434
#### If you are testing this package from a local server directory
3535

@@ -155,9 +155,9 @@ Run command to create symbolic links:
155155

156156
**Pay Attention! This option is needed just in the next cases:**
157157

158-
- If you use a **File setter** in your app html forms (see **5.3 Digging deeper** point).
158+
- If you use a **File setter** in your app html forms (see **5.3 Digging deeper** / **5.3.3 Use FileSetter** point).
159159

160-
- If you use an **Album editor** (see **5.3 Digging deeper** point).
160+
- If you use an **Album editor** (see in **5.1 Routes part**).
161161

162162
**Make sure** you use a **Bootstrap 4** for styling and **JQuery** in your application.
163163

@@ -177,7 +177,7 @@ Set the next js asset at the end of the `body` tag of your app layout:
177177

178178
Note: `vendor/uploader/js/jquery.min.js` is required just if **JQuery** is absent in your application.
179179

180-
#### 4.2.2 If you use [AdminLTE](https://github.com/jeroennoten/Laravel-AdminLTE) package
180+
#### 4.2.2 If you use [AdminLTE](https://github.com/jeroennoten/Laravel-AdminLTE) package in your project
181181

182182
```php
183183
'plugins' => [
@@ -208,7 +208,7 @@ Pay attention: Not recommended using of `asset()` in AdminLTE config file, becau
208208

209209
### 4.3 Change `uploader.php` config file.
210210

211-
This file is **intuitive**. Some features of its configuration are described in the **5.3 Digging deeper** point.
211+
This file is **intuitive**.
212212

213213
But at this stage, pay attention to the next important options:
214214

@@ -397,15 +397,13 @@ The next routes are available by default:
397397

398398
#### 5.2.2 Access to File upload manager
399399

400-
If to click on green **Uploader** button in a file list manager, you will go to **uploader_file_upload_manager** route.
400+
If to click on green **Uploader** button in a file list manager, you will go to **uploader_file_upload_manager** route: `http://example-domain.com/uploader/managers/file-upload`.
401401

402402
![MFU file upload manager](https://github.com/itstructure/laravel-media-file-uploader/blob/main/mfu_file_upload_manager.png)
403403

404404
#### 5.2.3 Access to File edit manager
405405

406-
If to click on green edition button in a file list manager, you will go to **uploader_file_edit_manager** route.
407-
408-
Also you can use this route as in a simple example below:
406+
If to click on green edition button in a file list manager, you will go to **uploader_file_edit_manager** route: `http://example-domain.com/uploader/managers/file-edit/{id}`:
409407

410408
```php
411409
route('uploader_file_edit_manager', ['id' => 1])
@@ -426,9 +424,7 @@ If you have got a media file entry `$mediaFile` by `Itstructure\MFU\Models\Media
426424
Here you can use some of the next options:
427425

428426
`\Itstructure\MFU\Services\Previewer::LOCATION_FILE_ITEM`
429-
430427
`\Itstructure\MFU\Services\Previewer::LOCATION_FILE_INFO`
431-
432428
`\Itstructure\MFU\Services\Previewer::LOCATION_EXISTING`
433429

434430
#### 5.2.5 Download Media file
@@ -484,9 +480,69 @@ Image album edition page example looks like this:
484480

485481
See inside core.
486482

487-
#### 5.3.3 Link Media files with parent owner
483+
#### 5.3.3 Use FileSetter
484+
485+
FileSetter is needed to set **file id** in to the form field and file **preview** to special container before sending request to controller during saving some entity: Page, Catalog, Product e.t.c.
486+
487+
Example FileSetter using for **thumbnail**:
488+
489+
```blade
490+
@php
491+
$thumbModel = isset($model) ? $model->getThumbnailModel() : null;
492+
@endphp
493+
<div id="{{ isset($model) ? 'thumbnail_container_' . $model->id : 'thumbnail_container' }}">
494+
@if(!empty($thumbModel))
495+
<a href="{{ $thumbModel->getOriginalUrl() }}" target="_blank">
496+
{!! \Itstructure\MFU\Facades\Previewer::getPreviewHtml($thumbModel, \Itstructure\MFU\Services\Previewer::LOCATION_FILE_INFO) !!}
497+
</a>
498+
@endif
499+
</div>
500+
<div id="{{ isset($model) ? 'thumbnail_title_' . $model->id : 'thumbnail_title' }}">
501+
@if(!empty($thumbModel))
502+
{{ $thumbModel->title }}
503+
@endif
504+
</div>
505+
<div id="{{ isset($model) ? 'thumbnail_description_' . $model->id : 'thumbnail_description' }}">
506+
@if(!empty($thumbModel))
507+
{{ $thumbModel->description }}
508+
@endif
509+
</div>
510+
@php
511+
$fileSetterConfig = [
512+
'attribute' => Itstructure\MFU\Processors\SaveProcessor::FILE_TYPE_THUMB,
513+
'value' => !empty($thumbModel) ? $thumbModel->id : null,
514+
'openButtonName' => trans('uploader::main.set_thumbnail'),
515+
'clearButtonName' => trans('uploader::main.clear'),
516+
'mediafileContainerId' => isset($model) ? 'thumbnail_container_' . $model->id : 'thumbnail_container',
517+
'titleContainerId' => isset($model) ? 'thumbnail_title_' . $model->id : 'thumbnail_title',
518+
'descriptionContainerId' => isset($model) ? 'thumbnail_description_' . $model->id : 'thumbnail_description',
519+
//'callbackBeforeInsert' => 'function (e, v) {console.log(e, v);}',//Custom
520+
'neededFileType' => Itstructure\MFU\Processors\SaveProcessor::FILE_TYPE_THUMB,
521+
'subDir' => isset($model) ? $model->getTable() : null
522+
];
523+
524+
$ownerConfig = isset($ownerParams) && is_array($ownerParams) ? array_merge([
525+
'ownerAttribute' => Itstructure\MFU\Processors\SaveProcessor::FILE_TYPE_THUMB
526+
], $ownerParams) : [];
527+
528+
$fileSetterConfig = array_merge($fileSetterConfig, $ownerConfig);
529+
@endphp
530+
@fileSetter($fileSetterConfig)
531+
```
488532

489-
Shortly, without extra words.
533+
Visually it looks like that:
534+
535+
![MFU file setter](https://github.com/itstructure/laravel-media-file-uploader/blob/main/mfu_file_setter.png)
536+
537+
If to click on **Set thumbnail** button, then file list manager will be opened, but with additional button "V":
538+
539+
![MFU file list with file setter button](https://github.com/itstructure/laravel-media-file-uploader/blob/main/mfu_file_list_with_setter_button.png)
540+
541+
This button is to choose a concrete file and insert it's preview in to the `thumbnail_container` and it's ID in to the automatically rendered form field by `attribute` option.
542+
543+
See next point **5.3.4** to understand how this selected file can be linked with a parent owner, like for example: Page, Product e.t.c...
544+
545+
#### 5.3.4 Link media files with parent owner
490546

491547
For example you use `Product` eloquent model, which contains **albums** and **media files** both.
492548

@@ -571,15 +627,23 @@ The main rules:
571627

572628
- It is very important to add method `booted()` with behaviour instances.
573629

574-
- It is very important to set **behavior attributes**!
630+
- It is very important to set `getBehaviorAttributes()` with attributes list, which are used in a blade form for **FileSetter**!
575631

576632
See deeper in to core and imagine how it works :-)
577633

578634
Go next...
579635

580-
It is very important to use MFU partials correctly in your application blade forms!
636+
It is very important to use MFU blade partials correctly in your application blade forms!
637+
638+
Short cut example for the blade form with using
639+
640+
`uploader::partials.thumbnail`,
641+
642+
`uploader::partials.new-mediafiles`,
643+
644+
`uploader::partials.existing-mediafiles`,
581645

582-
Short cut example for the blade form:
646+
`uploader::partials.albums-form-list`:
583647

584648
```blade
585649
<form action="{{ route('admin_product_store') }}" method="post">

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
### CHANGE LOG:
22

3+
**1.0.2 July 15, 2024:**
4+
- Fill and improve README.
5+
36
**1.0.1 July 14, 2024:**
47
- Fix `laravel-grid-view` dependency to **^1.1.3**.
58

mfu_file_list_with_setter_button.png

13.7 KB
Loading

mfu_file_setter.png

147 KB
Loading

0 commit comments

Comments
 (0)