Skip to content

Commit

Permalink
v3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ctf0 committed May 2, 2018
1 parent 396f7ec commit 643f75d
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 195 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ new Vue({
- bulk selection
- change item/s visibility
- [cache requests](https://github.com/ctf0/Laravel-Media-Manager/wiki/Customization-&--Optimization#starting-from-v240-any-call-to-the-server-will-be-cached)
- dynamically hide [files](https://github.com/ctf0/Laravel-Media-Manager/wiki/Hide-Files-With-Extension)
- dynamically hide [folders](https://github.com/ctf0/Laravel-Media-Manager/wiki/Hide-Folders)
- dynamically hide [files](https://github.com/ctf0/Laravel-Media-Manager/wiki/Hide-Files-With-Extension) / [folders](https://github.com/ctf0/Laravel-Media-Manager/wiki/Hide-Folders)
- toggle between `random/original` names for uploaded files
- download selected ["including bulk selection"](https://github.com/ctf0/Laravel-Media-Manager/wiki/Download-Files-as-a-ZipFile)
- directly copy selected file link
- use the manager
+ [from modal](https://github.com/ctf0/Laravel-Media-Manager/wiki/Use-The-Manager-From-A-Modal)
+ [with any wysiwyg editor](https://github.com/ctf0/Laravel-Media-Manager/wiki/Use-The-Manager-With-Any-WYSIWYG-Editor)
- auto scroll to selected item when using (left/up, right/down, home, end)
- [lock/unlock](https://github.com/ctf0/Laravel-Media-Manager/wiki/Lock-Files-&-Folder) selected files/folders **"sqLite must be installed"**
- [lock/unlock](https://github.com/ctf0/Laravel-Media-Manager/wiki/Lock-Files-&-Folder) selected files/folders ***"sqLite must be installed"***
- search
- filter by
+ folder
Expand Down Expand Up @@ -133,7 +132,7 @@ new Vue({
| select first | | home | | |
| select last | | end | | |
| open folder | | enter | ** | |
| go to prev dir | folderName *(breadcrumb)* | backspace | * | swipe right |
| go to prev dir | folderName *(breadcrumb)* | backspace | * | swipe right *(files container)* |

- events

Expand All @@ -143,7 +142,7 @@ new Vue({
| | modal-show | when modal is showen |
| | modal-hide | when modal is hidden |
| | file_selected *(when inside modal)* | get selected file url |
| | multi_file_selected *(when inside modal)* | get bulk selected files url |
| | multi_file_selected *(when inside modal)* | get bulk selected files urls |
| | folder_selected *(when inside modal)* | get selected folder path |
| [Laravel][lara] | | |
| | MMFileUploaded($file_path) | get uploaded file full [path][path] |
Expand Down Expand Up @@ -219,13 +218,12 @@ return [
'hide_files_ext' => true,

/*
* load image preview when item is clicked
* load image preview only when item is clicked ?
*/
'lazy_load_image_on_click' => false,

/*
* automatically invalidate cache after ?
* in "Minutes"
* automatically invalidate cache after "in Minutes"
*/
'cacheExpiresAfter'=> 60,
];
Expand Down
8 changes: 0 additions & 8 deletions logs/v3.0.0.txt

This file was deleted.

12 changes: 12 additions & 0 deletions logs/v3.0.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- separate lock&link icon click events from the file box
- fix btns being disabled after cache deletion and refetching
- fix dbl selection happens when going up a dir
- select first item when lazy loading is active & first item is a folder
- fix sidebar info not having correct bg color when empty
- allow zipping files with duplicate names
- standardize animation
- preserve search across navigation “a temp solution until global search is implemented”
- re-worked how the cache gets cleared through the different operations, so you get accurate info no matter how deep the current dir is
- cache is now also checked for invalidation when going up a dir
- fix issue of missing “$randId” when using the modal view
- cleanup
5 changes: 1 addition & 4 deletions src/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public function __construct(Carbon $carbon)
*/
public function index()
{
return view('MediaManager::media')->with([
'randId' => uniqid(),
'cacheExp' => array_get($this->config, 'cacheExpiresAfter'),
]);
return view('MediaManager::media');
}

/**
Expand Down
27 changes: 21 additions & 6 deletions src/Controllers/OpsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,17 @@ protected function storeFile($item, $upload_path, $file_name)
*/
protected function download($name, $id, $list, $type)
{
$cacheName = "$name-$id";
return response()->stream(function () use ($name, $list, $type, $id) {
// track changes
$cacheName = "$name-$id";
$counter = 100 / count($list);
$store = $this->zipCacheStore;
$store->forever("$cacheName.progress", 0);

// track changes
$counter = 100 / count($list);
$store = $this->zipCacheStore;
$store->forever("$cacheName.progress", 0);
// name duplication
$names = [];
$order = 0;

return response()->stream(function () use ($name, $list, $type, $counter, $store, $cacheName) {
$zip = new ZipStream("$name.zip", [
'content_type' => 'application/octet-stream',
]);
Expand All @@ -221,6 +224,18 @@ protected function download($name, $id, $list, $type)
$streamRead = @fopen($file['path'], 'r');
}

// check if file name was used b4
$name_only = pathinfo($file, PATHINFO_FILENAME);
$ext_only = pathinfo($file, PATHINFO_EXTENSION);

if (in_array($file_name, $names)) {
++$order;
$file_name = "{$name_only}_{$order}.{$ext_only}";
} else {
$names[] = $file_name;
}

// add to zip
if ($streamRead) {
$store->increment("$cacheName.progress", round($counter, 2));
$zip->addFileFromStream($file_name, $streamRead);
Expand Down
7 changes: 7 additions & 0 deletions src/DiskStorageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Adapter;

/**
* create a dynamic filesystem disk with cache capabilities.
*
* 1- install: composer require league/flysystem-cached-adapter
* 2- register: DiskStorageServiceProvider
* 3- usage: app('filesystem')->disk('ctf0-media').
*/
class DiskStorageServiceProvider extends ServiceProvider
{
/**
Expand Down
25 changes: 10 additions & 15 deletions src/resources/assets/js/components/media.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export default {
'zipProgressRoute',
'uploadPanelImgList',
'hideExt',
'hidePath',
'cacheExp'
'hidePath'
],
data() {
return {
Expand Down Expand Up @@ -105,7 +104,6 @@ export default {
this.preSaved()
this.getFiles(this.folders, null, this.selectedFile)
})
},
mounted() {
this.fileUpload()
Expand Down Expand Up @@ -153,17 +151,13 @@ export default {
if (this.allItemsCount) {
this.navigation(e)
if (
key == 'space' &&
e.target == document.body &&
(
this.selectedFileIs('video') ||
this.selectedFileIs('audio') ||
this.selectedFileIs('image') ||
this.selectedFileIs('pdf') ||
this.selectedFileIs('text')
)
) {
if (key == 'space' && e.target == document.body && (
this.selectedFileIs('video') ||
this.selectedFileIs('audio') ||
this.selectedFileIs('image') ||
this.selectedFileIs('pdf') ||
this.selectedFileIs('text')
)) {
e.preventDefault()
// play-pause media
Expand Down Expand Up @@ -285,6 +279,7 @@ export default {
/* end of short cuts */
refresh() {
this.resetInput('searchFor')
this.getFiles(this.folders, null, this.selectedFile ? this.selectedFile.name : null)
},
moveItem() {
Expand Down Expand Up @@ -344,4 +339,4 @@ export default {
},
render() {}
}
</script>
</script>
8 changes: 5 additions & 3 deletions src/resources/assets/js/modules/bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export default {

this.resetInput(['selectedFile', 'currentFileIndex'])

if (!this.isBulkSelecting() && !this.config.lazyLoad) {
file ? this.setSelected(file, index) : this.selectFirst()
if (!this.isBulkSelecting()) {
!this.config.lazyLoad
? file ? this.setSelected(file, index) : this.selectFirst()
: this.lazySelectFirst()
}
},
blkSlctAll() {
Expand Down Expand Up @@ -108,4 +110,4 @@ export default {
}
}
}
}
}
48 changes: 30 additions & 18 deletions src/resources/assets/js/modules/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ import addMinutes from 'date-fns/add_minutes'
import getTime from 'date-fns/get_time'

import { Store, get, set, del, clear, keys } from 'idb-keyval'
const DBNAME = 'ctf0-Media_Manager'
const cacheStore = new Store(
'ctf0-Media_Manager', // db
DBNAME, // db
'laravel-media-manager' // store
)

export default {
methods: {
// local storage
getLs() {
return this.$ls.get('ctf0-Media_Manager', {})
return this.$ls.get(DBNAME, {})
},
updateLs(obj) {
let storage = Object.assign(this.getLs(), obj)
this.$ls.set('ctf0-Media_Manager', storage)
this.$ls.set(DBNAME, storage)
},
removeLs() {
this.folders = []
this.$ls.remove('ctf0-Media_Manager')
this.$ls.remove(DBNAME)
},
preSaved() {
let ls = this.getLs()
Expand All @@ -37,7 +38,7 @@ export default {
return get(key, cacheStore)
},
cacheResponse(val) {
let date = getTime(addMinutes(new Date(), this.cacheExp))
let date = getTime(addMinutes(new Date(), this.config.cacheExp))
val = Object.assign(val, {expire: date})

return set(this.cacheName, val, cacheStore).catch((err) => {
Expand All @@ -46,20 +47,31 @@ export default {
},
removeCachedResponse(destination = null) {
let cacheName = this.cacheName
let extra
let items = []

if (destination) {
extra = destination == '../'
// go up
? cacheName.split('/').length > 2 ? cacheName.replace(/\/[^/]+$/, '') : 'root_'
// go down
: cacheName == 'root_' ? `/${destination}` : `${cacheName}${destination}`
// current path only
if (!destination) {
return this.deleteCache(cacheName)
}

// avoid clearing twice
let items = destination
? extra == cacheName ? [cacheName] : [extra, cacheName]
: [cacheName]
// up & down
destination == '../'
? false
: cacheName = cacheName == 'root_'
? `/${destination}`
: `${cacheName}${destination}`

let arr = cacheName.split('/').filter((e) => e)
let i = arr.length - 1
for (i; i >= 0; i--) {
items.push(cacheName) // add current
arr.pop() // remove last
cacheName = `/${arr.join('/')}` // regroup remaining
}

if (!items.includes('root_')) {
items.push('root_')
}

items.forEach((one) => {
return this.deleteCache(one)
Expand Down Expand Up @@ -92,7 +104,7 @@ export default {
keys.map((key) => {
this.getCachedResponse(key).then((item) => {
if (item.expire < now) {
return this.deleteCache(key)
this.deleteCache(key)
}
})
})
Expand All @@ -101,4 +113,4 @@ export default {
})
}
}
}
}
2 changes: 1 addition & 1 deletion src/resources/assets/js/modules/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ export default {
return folders.length ? '/' + folders.join('/') : 'root_'
}
}
}
}
3 changes: 2 additions & 1 deletion src/resources/assets/js/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ EventHub.listen('ajax-error-show', () => {

/**
* body movin animation
* you can remove it / replace it, do what you want
*/
function bm(el, name) {
bodymovin.loadAnimation({
Expand All @@ -53,4 +54,4 @@ function bm(el, name) {
progressiveLoad: true
}
})
}
}
8 changes: 5 additions & 3 deletions src/resources/assets/js/modules/filtration.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export default {
this.resetInput(['selectedFile', 'currentFileIndex'])
}

if (!this.isBulkSelecting() && !this.config.lazyLoad) {
this.selectFirst()
if (!this.isBulkSelecting()) {
!this.config.lazyLoad
? this.selectFirst()
: this.lazySelectFirst()
}

if (this.searchFor) {
Expand Down Expand Up @@ -88,4 +90,4 @@ export default {
})
}
}
}
}
Loading

0 comments on commit 643f75d

Please sign in to comment.