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

View File

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

View File

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

View File

@ -21,9 +21,15 @@ if (!OCA.External.StatusManager) {
}
OCA.External.StatusManager = {
mountStatus : null,
mountPointList : null,
/**
* Function
* @param {callback} afterCallback
*/
getMountStatus : function(afterCallback) {
var self = this;
if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) {
@ -32,36 +38,14 @@ OCA.External.StatusManager = {
if (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) {
var element;
$.each(this.mountPointList, function(key, value){
@ -73,6 +57,12 @@ OCA.External.StatusManager = {
return element;
},
/**
* Function Check mount point status from cache
* @param {string} mount_point
* @param {string} mount_point
*/
getMountStatusForMount : function(mountData, afterCallback) {
var self = this;
if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) {
@ -124,13 +114,17 @@ OCA.External.StatusManager = {
return defObj;
},
/**
* Function to get external mount point list from the files_external API
* @param {function} afterCallback function to be executed
*/
getMountPointList : function(afterCallback) {
var self = this;
if (typeof afterCallback !== 'function' || self.isGetMountPointListRunning) {
return;
}
if (self.mountPointList) {
afterCallback(self.mountPointList);
} else {
@ -164,13 +158,10 @@ OCA.External.StatusManager = {
}
},
setMountPointAsGood : function(mountPoint) {
OCA.External.StatusManager.Utils.restoreFolder(mountPoint);
OCA.External.StatusManager.Utils.toggleLink(mountPoint, true, true);
delete this.mountStatus[mountPoint].code;
delete this.mountStatus[mountPoint].error;
this.mountStatus[mountPoint].status = 'ok';
},
/**
* Function to manage action when a mountpoint status = 1 (Errored). Show a dialog to be redirected to settings page.
* @param {string} name MountPoint Name
*/
manageMountPointError : function(name) {
var self = this;
@ -194,27 +185,17 @@ OCA.External.StatusManager = {
}, this));
},
processMountStatus : function(mounts) {
var hasErrors = false;
var self = this;
$.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'));
}
}
},
/**
* Function to process a mount point in relation with their status, Called from Async Queue.
* @param {object} mountData
* @param {object} mountStatus
*/
processMountStatusIndividual : function(mountData, mountStatus) {
var mountPoint = mountData.mount_point;
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';
@ -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) {
var elementList = null;
$.each(mountList, function(name, value){
@ -256,39 +243,9 @@ OCA.External.StatusManager = {
}
},
launchFullConnectivityCheck : function() {
var self = this;
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);
});
}
});
},
/**
* Function to process the whole mount point list in relation with their status (Async queue)
*/
launchFullConnectivityCheckOneByOne : function() {
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) {
if (mountListData.length === 0) {
return;
@ -352,7 +316,14 @@ OCA.External.StatusManager = {
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) {
return;
}
@ -486,28 +457,28 @@ OCA.External.StatusManager.Utils = {
icon = OC.imagePath('sharepoint', 'folder-sharepoint');
break;
case 'amazons3':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
case 'dav':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
case 'dropbox':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
case 'ftp':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
case 'google':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
case 'owncloud':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
case 'sftp':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
case 'swift':
icon = OC.imagePath('core', 'filesystem/folder-external');
icon = OC.imagePath('core', 'filetypes/folder-external');
break;
}