Fix code from PR comments

This commit is contained in:
Jesús Macias 2015-11-24 08:16:14 +01:00
parent 31cfd43e8a
commit 5580b562a3
4 changed files with 208 additions and 236 deletions

View File

@ -9,105 +9,106 @@
*/ */
if (!OCA.External) { if (!OCA.External) {
/** /**
* @namespace * @namespace
*/ */
OCA.External = {}; OCA.External = {};
} }
/** /**
* @namespace * @namespace
*/ */
OCA.External.App = { OCA.External.App = {
fileList: null, fileList: null,
initList: function($el) { initList: function($el) {
if (this.fileList) { if (this.fileList) {
return this.fileList; return this.fileList;
} }
this.fileList = new OCA.External.FileList( this.fileList = new OCA.External.FileList(
$el, $el,
{ {
scrollContainer: $('#app-content'), scrollContainer: $('#app-content'),
fileActions: this._createFileActions() fileActions: this._createFileActions()
} }
); );
this._extendFileList(this.fileList); this._extendFileList(this.fileList);
this.fileList.appName = t('files_external', 'External storage'); this.fileList.appName = t('files_external', 'External storage');
return this.fileList; return this.fileList;
}, },
removeList: function() { removeList: function() {
if (this.fileList) { if (this.fileList) {
this.fileList.$fileList.empty(); this.fileList.$fileList.empty();
} }
}, },
_createFileActions: function() { _createFileActions: function() {
// inherit file actions from the files app // inherit file actions from the files app
var fileActions = new OCA.Files.FileActions(); var fileActions = new OCA.Files.FileActions();
fileActions.registerDefaultActions(); fileActions.registerDefaultActions();
// when the user clicks on a folder, redirect to the corresponding // when the user clicks on a folder, redirect to the corresponding
// folder in the files app instead of opening it directly // folder in the files app instead of opening it directly
fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) { fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
OCA.Files.App.setActiveView('files', {silent: true}); OCA.Files.App.setActiveView('files', {silent: true});
OCA.Files.App.fileList.changeDirectory(context.$file.attr('data-path') + '/' + filename, true, true); OCA.Files.App.fileList.changeDirectory(context.$file.attr('data-path') + '/' + filename, true, true);
}); });
fileActions.setDefault('dir', 'Open'); fileActions.setDefault('dir', 'Open');
return fileActions; return fileActions;
}, },
_extendFileList: function(fileList) { _extendFileList: function(fileList) {
// remove size column from summary // remove size column from summary
fileList.fileSummary.$el.find('.filesize').remove(); fileList.fileSummary.$el.find('.filesize').remove();
} }
}; };
$(document).ready(function() { $(document).ready(function() {
$('#app-content-extstoragemounts').on('show', function(e) { $('#app-content-extstoragemounts').on('show', function(e) {
OCA.External.App.initList($(e.target)); OCA.External.App.initList($(e.target));
}); });
$('#app-content-extstoragemounts').on('hide', function() { $('#app-content-extstoragemounts').on('hide', function() {
OCA.External.App.removeList(); OCA.External.App.removeList();
}); });
/* Status Manager */ /* Status Manager */
if ($('#filesApp').val()) { if ($('#filesApp').val()) {
$('#app-content-files') $('#app-content-files')
.add('#app-content-extstoragemounts') .add('#app-content-extstoragemounts')
.on('changeDirectory', function(e){ .on('changeDirectory', function(e){
if (e.dir === '/') { if (e.dir === '/') {
var mount_point = e.previousDir.split('/', 2)[1]; var mount_point = e.previousDir.split('/', 2)[1];
// make sure we have a mount point list // Every time that we return to / root folder from a mountpoint, mount_point status is rechecked
OCA.External.StatusManager.getMountPointList(function() { OCA.External.StatusManager.getMountPointList(function() {
OCA.External.StatusManager.recheckConnectivityForMount([mount_point], true, true); OCA.External.StatusManager.recheckConnectivityForMount([mount_point], true);
}); });
} }
}) })
.on('fileActionsReady', function(e){ .on('fileActionsReady', function(e){
if ($.isArray(e.$files)) { if ($.isArray(e.$files)) {
if (OCA.External.StatusManager.mountStatus === null || if (OCA.External.StatusManager.mountStatus === null ||
OCA.External.StatusManager.mountPointList === null || OCA.External.StatusManager.mountPointList === null ||
_.size(OCA.External.StatusManager.mountStatus) !== _.size(OCA.External.StatusManager.mountPointList)) { _.size(OCA.External.StatusManager.mountStatus) !== _.size(OCA.External.StatusManager.mountPointList)) {
// we don't have the data cached, so we'll get it one by one // Will be the very first check when the files view will be loaded
OCA.External.StatusManager.launchFullConnectivityCheckOneByOne(); OCA.External.StatusManager.launchFullConnectivityCheckOneByOne();
} else { } else {
// make sure we have a mount point list // When we change between general files view and external files view
OCA.External.StatusManager.getMountPointList(function(){ OCA.External.StatusManager.getMountPointList(function(){
var fileNames = []; var fileNames = [];
$.each(e.$files, function(key, value){ $.each(e.$files, function(key, value){
fileNames.push(value.attr('data-file')); fileNames.push(value.attr('data-file'));
}); });
OCA.External.StatusManager.recheckConnectivityForMount(fileNames, false, false); // Recheck if launched but work from cache
}); OCA.External.StatusManager.recheckConnectivityForMount(fileNames, false);
} });
} }
}); }
} });
/* End Status Manager */ }
/* End Status Manager */
}); });

View File

@ -59,77 +59,77 @@
* be executed at the same time * be executed at the same time
*/ */
var RollingQueue = function (functionList, queueWindow, callback) { var RollingQueue = function (functionList, queueWindow, callback) {
this.queueWindow = queueWindow || 1; this.queueWindow = queueWindow || 1;
this.functionList = functionList; this.functionList = functionList;
this.callback = callback; this.callback = callback;
this.counter = 0; this.counter = 0;
this.runQueue = function() { this.runQueue = function() {
this.callbackCalled = false; this.callbackCalled = false;
this.deferredsList = []; this.deferredsList = [];
if (!$.isArray(this.functionList)) { if (!$.isArray(this.functionList)) {
throw "functionList must be an array"; throw "functionList must be an array";
} }
for (i = 0; i < this.queueWindow; i++) { for (i = 0; i < this.queueWindow; i++) {
this.launchNext(); this.launchNext();
} }
}; };
this.hasNext = function() { this.hasNext = function() {
return (this.counter in this.functionList); return (this.counter in this.functionList);
}; };
this.launchNext = function() { this.launchNext = function() {
var currentCounter = this.counter++; var currentCounter = this.counter++;
if (currentCounter in this.functionList) { if (currentCounter in this.functionList) {
var funcData = this.functionList[currentCounter]; var funcData = this.functionList[currentCounter];
if ($.isFunction(funcData.funcName)) { if ($.isFunction(funcData.funcName)) {
var defObj = funcData.funcName.apply(funcData.funcName, funcData.funcArgs); var defObj = funcData.funcName.apply(funcData.funcName, funcData.funcArgs);
this.deferredsList.push(defObj); this.deferredsList.push(defObj);
if ($.isFunction(funcData.done)) { if ($.isFunction(funcData.done)) {
defObj.done(funcData.done); defObj.done(funcData.done);
} }
if ($.isFunction(funcData.fail)) { if ($.isFunction(funcData.fail)) {
defObj.fail(funcData.fail); defObj.fail(funcData.fail);
} }
if ($.isFunction(funcData.always)) { if ($.isFunction(funcData.always)) {
defObj.always(funcData.always); defObj.always(funcData.always);
} }
if (this.hasNext()) { if (this.hasNext()) {
var self = this; var self = this;
defObj.always(function(){ defObj.always(function(){
_.defer($.proxy(function(){ _.defer($.proxy(function(){
self.launchNext(); self.launchNext();
}, self)); }, self));
}); });
} else { } else {
if (!this.callbackCalled) { if (!this.callbackCalled) {
this.callbackCalled = true; this.callbackCalled = true;
if ($.isFunction(this.callback)) { if ($.isFunction(this.callback)) {
$.when.apply($, this.deferredsList) $.when.apply($, this.deferredsList)
.always($.proxy(function(){ .always($.proxy(function(){
this.callback(); this.callback();
}, this) }, this)
); );
} }
} }
} }
return defObj; return defObj;
} }
} }
return false; return false;
}; };
}; };
if (!OCA.External) { if (!OCA.External) {
OCA.External = {}; OCA.External = {};
} }
if (!OCA.External.StatusManager) { if (!OCA.External.StatusManager) {
OCA.External.StatusManager = {}; OCA.External.StatusManager = {};
} }
OCA.External.StatusManager.RollingQueue = RollingQueue; OCA.External.StatusManager.RollingQueue = RollingQueue;

View File

@ -1054,12 +1054,12 @@ MountConfigListView.prototype = _.extend({
} }
return defaultMountPoint + append; return defaultMountPoint + append;
}, },
/** /**
* Toggles the mount options dropdown * Toggles the mount options dropdown
* *
* @param {Object} $tr configuration row * @param {Object} $tr configuration row
*/ */
_showMountOptionsDropdown: function($tr) { _showMountOptionsDropdown: function($tr) {
if (this._preventNextDropdown) { if (this._preventNextDropdown) {
// prevented because the click was on the toggle // prevented because the click was on the toggle

View File

@ -21,9 +21,15 @@ if (!OCA.External.StatusManager) {
} }
OCA.External.StatusManager = { OCA.External.StatusManager = {
mountStatus : null, mountStatus : null,
mountPointList : null, mountPointList : null,
/**
* Function
* @param {callback} afterCallback
*/
getMountStatus : function(afterCallback) { getMountStatus : function(afterCallback) {
var self = this; var self = this;
if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) { if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) {
@ -32,36 +38,14 @@ OCA.External.StatusManager = {
if (self.mountStatus) { if (self.mountStatus) {
afterCallback(self.mountStatus); afterCallback(self.mountStatus);
} else {
self.isGetMountStatusRunning = true;
$.ajax({
type : 'GET',
url : OC.filePath('files_external', 'ajax', 'connectivityCheck.php'),
success : function(response) {
self.mountStatus = response.data;
afterCallback(self.mountStatus);
},
error : function(jqxhr, state, error) {
OC.Notification.showTemporary(t('files_external', 'Couldn\'t get the status of the external mounts: {type}', {type : error}));
if (!self.mountStatus) {
self.mountStatus = {};
}
$.each(self.mountPointList, function(name, value){
if (!self.mountStatus[value.mount_point]) {
self.mountStatus[value.mount_point] = {};
}
self.mountStatus[value.mount_point].status = 'ok';
OCA.External.StatusManager.Utils.restoreFolder(value);
OCA.External.StatusManager.Utils.toggleLink(value.mount_point, true, true);
});
},
complete : function() {
self.isGetMountStatusRunning = false;
}
});
} }
}, },
/**
* Function Check mount point status from cache
* @param {string} mount_point
*/
getMountPointListElement : function(mount_point) { getMountPointListElement : function(mount_point) {
var element; var element;
$.each(this.mountPointList, function(key, value){ $.each(this.mountPointList, function(key, value){
@ -73,6 +57,12 @@ OCA.External.StatusManager = {
return element; return element;
}, },
/**
* Function Check mount point status from cache
* @param {string} mount_point
* @param {string} mount_point
*/
getMountStatusForMount : function(mountData, afterCallback) { getMountStatusForMount : function(mountData, afterCallback) {
var self = this; var self = this;
if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) { if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) {
@ -124,13 +114,17 @@ OCA.External.StatusManager = {
return defObj; return defObj;
}, },
/**
* Function to get external mount point list from the files_external API
* @param {function} afterCallback function to be executed
*/
getMountPointList : function(afterCallback) { getMountPointList : function(afterCallback) {
var self = this; var self = this;
if (typeof afterCallback !== 'function' || self.isGetMountPointListRunning) { if (typeof afterCallback !== 'function' || self.isGetMountPointListRunning) {
return; return;
} }
if (self.mountPointList) { if (self.mountPointList) {
afterCallback(self.mountPointList); afterCallback(self.mountPointList);
} else { } else {
@ -164,13 +158,10 @@ OCA.External.StatusManager = {
} }
}, },
setMountPointAsGood : function(mountPoint) { /**
OCA.External.StatusManager.Utils.restoreFolder(mountPoint); * Function to manage action when a mountpoint status = 1 (Errored). Show a dialog to be redirected to settings page.
OCA.External.StatusManager.Utils.toggleLink(mountPoint, true, true); * @param {string} name MountPoint Name
delete this.mountStatus[mountPoint].code; */
delete this.mountStatus[mountPoint].error;
this.mountStatus[mountPoint].status = 'ok';
},
manageMountPointError : function(name) { manageMountPointError : function(name) {
var self = this; var self = this;
@ -194,27 +185,17 @@ OCA.External.StatusManager = {
}, this)); }, this));
}, },
/**
processMountStatus : function(mounts) { * Function to process a mount point in relation with their status, Called from Async Queue.
var hasErrors = false; * @param {object} mountData
var self = this; * @param {object} mountStatus
$.each(mounts, function(mountPoint, values){ */
hasErrors = !self.processMountStatusIndividual(mountPoint, values) || hasErrors;
});
if (!this.notificationHasShown) {
this.notificationHasShown = true;
if (hasErrors) {
OC.Notification.showTemporary(t('files_external', 'Some of the configured external mount points are not connected. Please click on the red row(s) for more information'));
}
}
},
processMountStatusIndividual : function(mountData, mountStatus) { processMountStatusIndividual : function(mountData, mountStatus) {
var mountPoint = mountData.mount_point; var mountPoint = mountData.mount_point;
if (mountStatus.status === 1) { if (mountStatus.status === 1) {
var trElement = FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(mountPoint)); //$('#fileList tr[data-file=\"' + OCA.External.StatusManager.Utils.jqSelEscape(mountPoint) + '\"]'); var trElement = FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(mountPoint));
route = OCA.External.StatusManager.Utils.getIconRoute(trElement) + '-error'; route = OCA.External.StatusManager.Utils.getIconRoute(trElement) + '-error';
@ -231,6 +212,12 @@ OCA.External.StatusManager = {
} }
}, },
/**
* Function to process a mount point in relation with their status
* @param {object} mountData
* @param {object} mountStatus
*/
processMountList : function(mountList) { processMountList : function(mountList) {
var elementList = null; var elementList = null;
$.each(mountList, function(name, value){ $.each(mountList, function(name, value){
@ -256,39 +243,9 @@ OCA.External.StatusManager = {
} }
}, },
launchFullConnectivityCheck : function() { /**
var self = this; * Function to process the whole mount point list in relation with their status (Async queue)
this.getMountPointList(function(list){ */
// check if we have a list first
if (list === undefined && !self.emptyWarningShown) {
self.emptyWarningShown = true;
OC.Notification.showTemporary(t('files_external', 'Couldn\'t get the list of external mount points: empty response from the server'));
return;
}
if (list && list.length > 0) {
self.processMountList(list);
self.getMountStatus(function(mountStatus){
if (mountStatus === undefined && !self.notificationNoProcessListDone) {
self.notificationNoProcessListDone = true;
OC.Notification.showTemporary(t('files_external', 'Couldn\'t get the status of the external mounts: empty response from the server'));
if (!self.mountStatus) {
self.mountStatus = {};
}
$.each(list, function(name, value){
if (!self.mountStatus[value.mount_point]) {
self.mountStatus[value.mount_point] = {};
}
self.mountStatus[value.mount_point].status = 'ok';
OCA.External.StatusManager.Utils.restoreFolder(value.mount_point);
OCA.External.StatusManager.Utils.toggleLink(value.mount_point, true, true);
});
return;
}
self.processMountStatus(mountStatus);
});
}
});
},
launchFullConnectivityCheckOneByOne : function() { launchFullConnectivityCheckOneByOne : function() {
var self = this; var self = this;
@ -333,6 +290,13 @@ OCA.External.StatusManager = {
}); });
}, },
/**
* Function to process a mount point list in relation with their status (Async queue)
* @param {object} mountListData
* @param {boolean} recheck delete cached info and force api call to check mount point status
*/
launchPartialConnectivityCheck : function(mountListData, recheck) { launchPartialConnectivityCheck : function(mountListData, recheck) {
if (mountListData.length === 0) { if (mountListData.length === 0) {
return; return;
@ -352,7 +316,14 @@ OCA.External.StatusManager = {
new OCA.External.StatusManager.RollingQueue(ajaxQueue, 4).runQueue(); new OCA.External.StatusManager.RollingQueue(ajaxQueue, 4).runQueue();
}, },
recheckConnectivityForMount : function(mountListNames, recheck, checkGlobal) {
/**
* Function to relaunch some mount point status check
* @param {string} mountListNames
* @param {boolean} recheck delete cached info and force api call to check mount point status
*/
recheckConnectivityForMount : function(mountListNames, recheck) {
if (mountListNames.length === 0) { if (mountListNames.length === 0) {
return; return;
} }
@ -486,28 +457,28 @@ OCA.External.StatusManager.Utils = {
icon = OC.imagePath('sharepoint', 'folder-sharepoint'); icon = OC.imagePath('sharepoint', 'folder-sharepoint');
break; break;
case 'amazons3': case 'amazons3':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
case 'dav': case 'dav':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
case 'dropbox': case 'dropbox':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
case 'ftp': case 'ftp':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
case 'google': case 'google':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
case 'owncloud': case 'owncloud':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
case 'sftp': case 'sftp':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
case 'swift': case 'swift':
icon = OC.imagePath('core', 'filesystem/folder-external'); icon = OC.imagePath('core', 'filetypes/folder-external');
break; break;
} }