Skip to content

Commit

Permalink
Merge pull request #6898 from lenvanessen/feature/filemanager-improve…
Browse files Browse the repository at this point in the history
…ments

[3.4] File manager improvements
  • Loading branch information
GwendolenLynch committed Aug 20, 2017
2 parents d26a516 + f7ceb86 commit 634399c
Show file tree
Hide file tree
Showing 24 changed files with 487 additions and 66 deletions.
2 changes: 2 additions & 0 deletions app/resources/translations/en_GB/messages.en_GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ general.phrase.upload-file: "Upload file"
general.phrase.upload-file-to-directory: "Upload a file to this folder"
general.phrase.upload-image: "Upload image"
general.phrase.upload-not-allowed: "Upload not allowed"
general.phrase.upload-progress: "Current uploads"
general.phrase.used-libraries: "Used Libraries / Components"
general.phrase.user-deleted: "User '%s' is deleted."
general.phrase.user-disabled: "User '%s' is disabled."
Expand Down Expand Up @@ -608,6 +609,7 @@ page.extend.theme.generation.failure: "We were unable to generate the theme. It
page.extend.theme.generation.missing.name: "No theme name found. Theme is not generated."
page.extend.theme.generation.success: "Theme successfully generated. You can now edit it directly from your theme folder."

page.file-management.actions-for-files: "Actions for files"
page.file-management.label.create-file: "Create file"
page.file-management.label.create-folder: "Create folder"
page.file-management.message.access-denied: "Uploading to this folder is not allowed."
Expand Down
1 change: 1 addition & 0 deletions app/src/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = function (grunt) {
'<%= path.src.js %>/modules/extend.js',
'<%= path.src.js %>/modules/events.js',
'<%= path.src.js %>/modules/files.js',
'<%= path.src.js %>/modules/filemanager.js',
'<%= path.src.js %>/modules/liveeditor.js',
'<%= path.src.js %>/modules/omnisearch.js',
'<%= path.src.js %>/modules/secmenu.js',
Expand Down
4 changes: 3 additions & 1 deletion app/src/grunt/concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ module.exports = function (grunt, option) {
'<%= path.tmp %>/bootstrap.min.js', // 24 kb
'<%= path.src.npm %>/select2/dist/js/select2.min.js', // 62 kb
'<%= path.tmp %>/moment.min.js', // 35 kb
'<%= path.tmp %>/dropzone.min.js', // 37 kB
'<%= path.tmp %>/modernizr-custom.min.js', // 5 kb
'<%= path.tmp %>/select2.sortable.min.js' // 5 kb
],
Expand All @@ -120,7 +121,8 @@ module.exports = function (grunt, option) {
'<%= path.src.npm %>/select2/dist/css/select2.css',
'<%= path.src.npm %>/blueimp-file-upload/css/jquery.fileupload.css',
'<%= path.src.npm %>/blueimp-file-upload/css/jquery.fileupload-ui.css',
'<%= path.src.npm %>/magnific-popup/dist/magnific-popup.css'
'<%= path.src.npm %>/magnific-popup/dist/magnific-popup.css',
'<%= path.src.npm %>/dropzone/dist/dropzone.css'
],
dest: '<%= path.dest.css %>/lib.css'
}
Expand Down
1 change: 1 addition & 0 deletions app/src/grunt/uglify.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'<%= path.src.lib %>/jquery-hotkeys/jquery-hotkeys.js',
'<%= path.tmp %>/modernizr-custom.js',
'<%= path.src.npm %>/jquery/dist/jquery.js',
'<%= path.src.npm %>/dropzone/dist/dropzone.js',
'<%= path.src.npm %>/jquery.cookie/jquery.cookie.js',
'<%= path.src.npm %>/jquery-formatdatetime/jquery.formatDateTime.js',
'<%= path.src.npm %>/jquery.tagcloud.js/jquery.tagcloud.js',
Expand Down
3 changes: 2 additions & 1 deletion app/src/js/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
'bootbox': true, // Bootbox.js
'google': true, // Google (Geolocation)
'moment': true, // Moment.js (deprecated)
'UIkit': true // UIkit
'UIkit': true, // UIkit
'Dropzone': true // Dropzone.js
},
'extends': 'eslint:recommended',
'rules': {
Expand Down
1 change: 1 addition & 0 deletions app/src/js/bolt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @mixes Bolt.events
* @mixes Bolt.extend
* @mixes Bolt.files
* @mixes Bolt.filemanager
* @mixes Bolt.omnisearch
* @mixes Bolt.secmenu
* @mixes Bolt.stack
Expand Down
1 change: 1 addition & 0 deletions app/src/js/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
bolt.stack.init();
bolt.omnisearch.init();
bolt.extend.init();
bolt.filemanager.init();

bolt.ckeditor.init();
bolt.datetime.init();
Expand Down
217 changes: 217 additions & 0 deletions app/src/js/modules/filemanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/**
* Enhances file manager with search, multiselect and drag-and-drop magic
*
* @mixin
* @namespace Bolt.filemanager
*
* @param {Object} bolt - The Bolt module
* @param {Object} $ - jQuery
* @param {Object} Dropzone
*
* @author Len van Essen
*/
(function (bolt, $, Dropzone) {
'use strict';

/**
* Bolt.filemanager mixin container.
*
* @private
* @type {Object}
*/
var filemanager = {};

/**
* Pre-processes and regex string to escape characters
*
* @function escapeRegExp
* @param str
*/
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

/**
* Returns matches wrapped in <mark> tags
* @param str
* @param find
*/
function markAll(str, find) {
var replace = '<mark>' + find + '</mark>';
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

/**
* Searches the filemanagers list and marks matching words
*
* TODO since the filenames are capped at 80chars, this possibly does not match when you search for a full filename longer than 80chars
* @function searchFiles
* @memberof Bolt.filemanager
*/
function searchFiles() {
var term = $(this).val();

$('.dashboardlisting').find('[data-bolt-browse-name]').each(function () {
var name = $(this).data('bolt-browse-name');
var hide = name.search(term) < 0;

$(this).toggleClass('hidden', hide);

if (!hide) {
$(this).find('.name').each(function () {

$(this).html( markAll(name, term) );

// Removes marks if search term is empty
if(term.length === 0) {
$(this).html(name);
}
});
}

});
}

/**
* Lazy loads images to increase performance
*
* @function lazyLoadImages
*/
function lazyLoadImages() {
var images = document.querySelectorAll('img[data-src]');

for (var i = 0; i < images.length; i++) {
if (images[i].getAttribute('data-src')) {
images[i].setAttribute('src', images[i].getAttribute('data-src'));
images[i].removeAttribute('data-src');
}
}
}

/**
* Binds internal functions to eventListeners
*
* @function setupEventHandlers
*/
function addEventListeners() {

// Input event
document.getElementById('file-manager-search').addEventListener('keyup', searchFiles);

// Select file
$('#file_upload_select').addClass('btn-secondary').bootstrapFileInput();
document.getElementById('file_upload_select').addEventListener('change', function () {
document.getElementById('file_upload_upload').removeAttribute('disabled');
});

// Lazy load images
window.addEventListener('load', lazyLoadImages);
}

/**
* Native dragleave event gets fired every mousemove
* This function prevents the flickering of the hint
* and also binds this to the drop event
*
* @function handleDropHint
* @param target Dropzone
*/
function dragOver(target) {
var elm = $('body');
var counter = 0;

elm.bind({
dragenter: function (ev) {
ev.preventDefault(); // needed for IE
counter++;
$(this).addClass('dropzone-active');
},

dragleave: function () {
counter--;
if (counter === 0) {
$(this).removeClass('dropzone-active');
}
}
});

// Bind to drop-event
target.on('drop', function () {
elm.removeClass('dropzone-active');
});
}

/**
* Initializes dropzone and handles the request
*
* @function bindDropzone
*/
function bindDropzone() {
var csrf = $('form[name="file_upload"]').find('#file_upload__token').val();

var DropzoneTarget = new Dropzone(document.body, {
url: bolt.conf('uploadConfig.url'),
previewsContainer: "#dropzone-preview",
acceptedFiles: '.' + bolt.conf('uploadConfig.acceptFilesTypes').join(',.'),
uploadMultiple: 'true',
enqueueForUpload: 'true',
hiddenInputContainer: '.form-horizontal',
paramName: 'file_upload[select]',
clickable: false,
autoProcessQueue: true,
params: {
'file_upload[_token]': csrf
},
init: function () {
dragOver(this);
}
});


// Show the progress
DropzoneTarget.on('sending', function () {
$('.panel-uploadprogress').removeClass('hidden');
});

// Removes the file the clear the queue box
DropzoneTarget.on('complete', function (file) {
DropzoneTarget.removeFile(file);
});

DropzoneTarget.on('totaluploadprogress', function (progress) {
if(progress === 100) {
location.reload();
}
});

}


/**
* Initializes the mixin.
*
* @static
* @function run
* @memberof Bolt.filemanager
*
*/
filemanager.init = function () {

// Always disable autoDiscover
Dropzone.autoDiscover = false;

// Bail out if this isn't the filemanager page
if(document.querySelector('.file-manager') !== null) {

// Dropzone events
bindDropzone();

// Hook up listeners for custom functions
addEventListeners();
}
};

// Apply mixin container.
bolt.filemanager = filemanager;

})(Bolt || {}, jQuery, Dropzone);
2 changes: 2 additions & 0 deletions app/src/js/widgets/buic/buicBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
*
* @private
* @param {Object} modal - The modal dialog object
*
* TODO this only marks the first occurence of the string, swap out for Regex solution
*/
_filter: function (modal) {
var term = modal.body.find('input[name="filter"]').val(),
Expand Down
1 change: 1 addition & 0 deletions app/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"blueimp-file-upload": "9.18.0",
"bootbox": "~4.4.0",
"bootstrap-sass": "~3.3.7",
"dropzone": "^5.1.1",
"font-awesome": "~4.7.0",
"jquery": "~2.2.4",
"jquery-formatdatetime": "~1.1.6",
Expand Down
Loading

0 comments on commit 634399c

Please sign in to comment.