Skip to content

Commit

Permalink
v1.3.6
Browse files Browse the repository at this point in the history
Update media-bulma.blade.php

…
  • Loading branch information
ctf0 committed Oct 19, 2017
1 parent c37fe9e commit 095ba7c
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 56 deletions.
67 changes: 37 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,46 @@
- disable/enable buttons depend on the usage to avoid noise & keep the user focused
- shortcuts

| navigation | button | keyboard | mouse (click) |
|---------------------|-------------------------------|-----------|---------------|
| | upload *(toolbar)* | u | * |
| | refresh *(toolbar)* | r | * |
| | move *(toolbar)* | m | * |
| | delete *(toolbar)* | d/del | * |
| | bulk select *(toolbar)* | b | * |
| | bulk select all *(toolbar)* | a | * |
| | toggle *(sidebar)* | t | * |
| | file rename *(modal)* | enter | * |
| | file delete *(modal)* | enter | * |
| | create new folder *(modal)* | enter | * |
| select next | | right | * |
| select prev | | left | * |
| select first | | home | * |
| select last | | end | * |
| open folder | | enter | double click |
| go back to prev dir | folderName *(breadcrumb)* | backspace | * |
| play/pause media | player controller *(sidebar)* | space | * |
| view image | image *(sidebar)* | space | * |
| hide image | image *(light-box)* | space/esc | * |
| navigation | button | keyboard | mouse (click) |
|---------------------|-----------------------------|-----------|-----------------|
| | upload *(toolbar)* | u | * |
| | refresh *(toolbar)* | r | * |
| | move *(toolbar)* | m | * |
| | delete *(toolbar)* | d/del | * |
| | bulk select *(toolbar)* | b | * |
| | bulk select all *(toolbar)* | a | * |
| | file rename *(modal)* | enter | * |
| | file delete *(modal)* | enter | * |
| | create new folder *(modal)* | enter | * |
| | toggle *(sidebar)* | t | * |
| | play/pause media | space | * *(sidebar)* |
| | view image | space | * *(sidebar)* |
| | hide image | space/esc | * *(light-box)* |
| select next | | right | * |
| select prev | | left | * |
| select first | | home | * |
| select last | | end | * |
| open folder | | enter | double click |
| go back to prev dir | folderName *(breadcrumb)* | backspace | * |

- events

| event-name | description |
|--------------------|------------------------------|
| modal-show | when modal is showen |
| modal-hide | when modal is hidden |
| no-files-show | when no files msg is showen |
| no-files-hide | when no files msg is hidden |
| loading-files-show | when loading files is hidden |
| loading-files-hide | when loading files is hidden |
| ajax-error-show | when ajax call fails |
| type | event-name | description |
|---------|-------------------------------------|------------------------------|
| JS | | |
| | modal-show | when modal is showen |
| | modal-show | when modal is showen |
| | modal-hide | when modal is hidden |
| | no-files-show | when no files msg is showen |
| | no-files-hide | when no files msg is hidden |
| | loading-files-show | when loading files is hidden |
| | loading-files-hide | when loading files is hidden |
| | ajax-error-show | when ajax call fails |
| Laravel | | |
| | MMFileUploaded($file_path) | get uploade file full path |
| | MMFileDeleted($file_path) | get deleted file full path |
| | MMFolderDeleted($file_path) | get deleted folder full path |
| | MMFileRenamed($old_path, $new_path) | get renamed file/folder path |

## Config
**config/mediaManager.php**
Expand Down
3 changes: 0 additions & 3 deletions logs/v1.3.4.txt

This file was deleted.

5 changes: 5 additions & 0 deletions logs/v1.3.6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- fix refresh button when no files are avail
- fix refresh shortcut button not working when there are no files
- add events for file/folder “upload/delete/rename” which will give you the full path to the file/folder so you can hook into them easily.
- fixed error when adding new folder & not triggering refresh after
- update readme
47 changes: 32 additions & 15 deletions src/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function index()
*/
public function get_files(Request $request)
{
$folder = $request->folder !== '/'
$folder = '/' !== $request->folder
? $request->folder
: '';

Expand Down Expand Up @@ -92,34 +92,39 @@ public function get_dirs(Request $request)
public function upload(Request $request)
{
$upload_path = $request->upload_path;
$files = $request->file;
$result = [];

foreach ($request->file as $one) {
$file_name = $one->getClientOriginalName();
$destination = "$upload_path/{$this->cleanName($file_name)}";
$file_type = $one->getMimeType();

foreach ($files as $one) {
try {
// check for mime type
$file_type = $one->getMimeType();

if (str_contains($file_type, $this->unallowed_mimes)) {
throw new Exception(trans('MediaManager::messages.not_allowed_file_ext', ['attr'=>$file_type]));
}

$file_name = $one->getClientOriginalName();
$destination = "$upload_path/{$this->cleanName($file_name)}";

// check existence
if ($this->storageDisk->exists($destination)) {
throw new Exception(trans('MediaManager::messages.error_may_exist'));
}

// check name
// because dropzone automatically sanitize the file name
if ($file_name == '.' . $one->getClientOriginalExtension()) {
$file_name = $this->sanitizedText . $file_name;
}

$path = $one->storeAs($upload_path, $this->cleanName($file_name), $this->fileSystem);
// save file
$saved_name = $one->storeAs($upload_path, $this->cleanName($file_name), $this->fileSystem);

// fire event
event('MMFileUploaded', $this->getFilePath($this->fileSystem, $saved_name));

$result[] = [
'path' => preg_replace('/^public\//', '', $path),
'path' => preg_replace('/^public\//', '', $saved_name),
'success' => true,
'message' => $file_name,
];
Expand Down Expand Up @@ -187,19 +192,25 @@ public function delete_file(Request $request)

$file_name = "$folderLocation/$file_name";

if ($type == 'folder') {
if ('folder' == $type) {
if (!$this->storageDisk->deleteDirectory($file_name)) {
$result[] = [
'success' => false,
'message' => trans('MediaManager::messages.error_deleting_folder'),
];
} else {
// fire event
event('MMFolderDeleted', $this->getFilePath($this->fileSystem, $file_name));
}
} else {
if (!$this->storageDisk->delete($file_name)) {
$result[] = [
'success' => false,
'message' => trans('MediaManager::messages.error_deleting_file'),
];
} else {
// fire event
event('MMFileDeleted', $this->getFilePath($this->fileSystem, $file_name));
}
}
}
Expand Down Expand Up @@ -229,14 +240,14 @@ public function move_file(Request $request)
$file_size = $one['size'];

$destination = "{$request->destination}/$file_name";
$file_name = "$folderLocation/$file_name";
$destination = strpos($destination, '../') == true
$old_path = "$folderLocation/$file_name";
$new_path = true == strpos($destination, '../')
? '/' . dirname($folderLocation) . '/' . str_replace('../', '', $destination)
: "$folderLocation/$destination";

try {
if (!file_exists($destination)) {
if ($this->storageDisk->move($file_name, $destination)) {
if (!file_exists($new_path)) {
if ($this->storageDisk->move($old_path, $new_path)) {
$result[] = [
'success' => true,
'name' => $one['name'],
Expand All @@ -252,7 +263,7 @@ public function move_file(Request $request)
} catch (Exception $e) {
$result[] = [
'success' => false,
'message' => "\"$file_name\" " . $e->getMessage(),
'message' => "\"$old_path\" " . $e->getMessage(),
];
}
}
Expand Down Expand Up @@ -282,6 +293,12 @@ public function rename_file(Request $request)
if ($this->storageDisk->move("$folderLocation/$filename", "$folderLocation/$new_filename")) {
$message = '';
$success = true;

// fire event
event('MMFileRenamed', [
'old' => $this->getFilePath($this->fileSystem, "$folderLocation/$filename"),
'new' => $this->getFilePath($this->fileSystem, "$folderLocation/$new_filename"),
]);
} else {
$message = trans('MediaManager::messages.error_moving');
}
Expand Down
25 changes: 24 additions & 1 deletion src/Controllers/OpsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function cleanName($text, $folder = null)

$text = preg_replace($pattern, '', $text);

return $text == '' ? $this->sanitizedText : $text;
return '' == $text ? $this->sanitizedText : $text;
}

protected function filePattern($file)
Expand Down Expand Up @@ -107,4 +107,27 @@ protected function folderFiles($folder)
{
return $this->storageDisk->allFiles($folder);
}

/**
* get file path from storange.
*
* @param [type] $disk [description]
* @param [type] $name [description]
*
* @return [type] [description]
*/
protected function getFilePath($disk, $name)
{
$config = config("filesystems.disks.$disk");
$url = app('filesystem')->disk($disk)->url($name);
$dir = str_replace(array_get($config, 'url'), '', $url);
$root = array_get($config, 'root');

// for other disks without root ex."cloud"
if (!$root) {
return preg_replace('/(.*\/\/.*?)\//', '', $url);
}

return $root . $dir;
}
}
10 changes: 5 additions & 5 deletions src/resources/assets/js/components/media-bulma.vue
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ export default {
this.toggleModal('#img_modal')
}
}
// refresh
if (keycode(e) == 'r') {
$('#refresh').trigger('click')
}
}
// end of when there are files
// refresh
if (keycode(e) == 'r') {
$('#refresh').trigger('click')
}
// file upload
if (keycode(e) == 'u') {
$('#upload').trigger('click')
Expand Down
2 changes: 1 addition & 1 deletion src/resources/assets/js/components/mixins/methods/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
}, (res) => {
this.files = res
this.loadingFiles('hide')
this.noFiles('hide')
this.selectFirst()
$('#right').fadeIn()

Expand Down Expand Up @@ -57,7 +58,6 @@ export default {
this.toggleLoading()
this.resetInput('new_folder_name')
this.toggleModal()
this.scrollToFile()

if (!data.success) {
return this.showNotif(data.message, 'danger')
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/media-bulma.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class="button"
{{-- footer --}}
<script src="//cdnjs.cloudflare.com/ajax/libs/bodymovin/4.10.2/bodymovin.min.js"></script>
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="{{ mix("path/to/app.js") }}"></script>
<script src="{{ asset("path/to/app.js") }}"></script>

{{-- animations --}}
{{-- moved to events @ js/events.js --}}
Expand Down

0 comments on commit 095ba7c

Please sign in to comment.