diff options
author | John MolakvoƦ <skjnldsv@protonmail.com> | 2023-07-13 09:58:24 +0200 |
---|---|---|
committer | John MolakvoƦ <skjnldsv@protonmail.com> | 2023-08-01 16:38:06 +0200 |
commit | 38480fda3cd1f10652bc1e854207b074921e66b8 (patch) | |
tree | c4c9112123f649802c9f86d056fe6da5e89be068 /apps/files_external/js | |
parent | 385f987a28a535e8b6b0020693daa5347093c186 (diff) | |
download | nextcloud-server-38480fda3cd1f10652bc1e854207b074921e66b8.tar.gz nextcloud-server-38480fda3cd1f10652bc1e854207b074921e66b8.zip |
feat(files_external): migrate to vue
Signed-off-by: John MolakvoƦ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files_external/js')
-rw-r--r-- | apps/files_external/js/app.js | 112 | ||||
-rw-r--r-- | apps/files_external/js/mountsfilelist.js | 149 | ||||
-rw-r--r-- | apps/files_external/js/oauth1.js | 82 | ||||
-rw-r--r-- | apps/files_external/js/oauth2.js | 96 | ||||
-rw-r--r-- | apps/files_external/js/public_key.js | 64 | ||||
-rw-r--r-- | apps/files_external/js/rollingqueue.js | 137 | ||||
-rw-r--r-- | apps/files_external/js/statusmanager.js | 613 |
7 files changed, 0 insertions, 1253 deletions
diff --git a/apps/files_external/js/app.js b/apps/files_external/js/app.js deleted file mode 100644 index 4f91e2e78b0..00000000000 --- a/apps/files_external/js/app.js +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ - -if (!OCA.Files_External) { - /** - * @namespace - */ - OCA.Files_External = {}; -} -/** - * @namespace - */ -OCA.Files_External.App = { - - fileList: null, - - initList: function($el) { - if (this.fileList) { - return this.fileList; - } - - this.fileList = new OCA.Files_External.FileList( - $el, - { - fileActions: this._createFileActions() - } - ); - - this._extendFileList(this.fileList); - this.fileList.appName = t('files_external', 'External storage'); - return this.fileList; - }, - - 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(); - - // 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(OC.joinPaths(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(); - } -}; - -window.addEventListener('DOMContentLoaded', function() { - $('#app-content-extstoragemounts').on('show', function(e) { - OCA.Files_External.App.initList($(e.target)); - }); - $('#app-content-extstoragemounts').on('hide', function() { - OCA.Files_External.App.removeList(); - }); - - /* 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]; - // Every time that we return to / root folder from a mountpoint, mount_point status is rechecked - OCA.Files_External.StatusManager.getMountPointList(function() { - OCA.Files_External.StatusManager.recheckConnectivityForMount([mount_point], true); - }); - } - }) - .on('fileActionsReady', function(e){ - if ($.isArray(e.$files)) { - if (OCA.Files_External.StatusManager.mountStatus === null || - OCA.Files_External.StatusManager.mountPointList === null || - _.size(OCA.Files_External.StatusManager.mountStatus) !== _.size(OCA.Files_External.StatusManager.mountPointList)) { - // Will be the very first check when the files view will be loaded - OCA.Files_External.StatusManager.launchFullConnectivityCheckOneByOne(); - } else { - // When we change between general files view and external files view - OCA.Files_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.Files_External.StatusManager.recheckConnectivityForMount(fileNames, false); - }); - } - } - }); - } - /* End Status Manager */ -}); diff --git a/apps/files_external/js/mountsfilelist.js b/apps/files_external/js/mountsfilelist.js deleted file mode 100644 index 3b88ec070db..00000000000 --- a/apps/files_external/js/mountsfilelist.js +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ -(function() { - - /** - * @class OCA.Files_External.FileList - * @augments OCA.Files.FileList - * - * @classdesc External storage file list. - * - * Displays a list of mount points visible - * for the current user. - * - * @param $el container element with existing markup for the .files-controls - * and a table - * @param [options] map of options, see other parameters - **/ - var FileList = function($el, options) { - this.initialize($el, options); - }; - - FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, - /** @lends OCA.Files_External.FileList.prototype */ { - appName: 'External storage', - - _allowSelection: false, - - /** - * @private - */ - initialize: function($el, options) { - OCA.Files.FileList.prototype.initialize.apply(this, arguments); - if (this.initialized) { - return; - } - }, - - /** - * @param {OCA.Files_External.MountPointInfo} fileData - */ - _createRow: function(fileData) { - // TODO: hook earlier and render the whole row here - var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments); - var $scopeColumn = $('<td class="column-scope column-last"><span></span></td>'); - var $backendColumn = $('<td class="column-backend"></td>'); - var scopeText = t('files_external', 'Personal'); - if (fileData.scope === 'system') { - scopeText = t('files_external', 'System'); - } - $tr.find('.filesize,.date').remove(); - $scopeColumn.find('span').text(scopeText); - $backendColumn.text(fileData.backend); - $tr.find('td.filename').after($scopeColumn).after($backendColumn); - return $tr; - }, - - updateEmptyContent: function() { - var dir = this.getCurrentDirectory(); - if (dir === '/') { - // root has special permissions - this.$el.find('.emptyfilelist.emptycontent').toggleClass('hidden', !this.isEmpty); - this.$el.find('.files-filestable thead th').toggleClass('hidden', this.isEmpty); - } - else { - OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments); - } - }, - - getDirectoryPermissions: function() { - return OC.PERMISSION_READ | OC.PERMISSION_DELETE; - }, - - updateStorageStatistics: function() { - // no op because it doesn't have - // storage info like free space / used space - }, - - reload: function() { - this.showMask(); - if (this._reloadCall?.abort) { - this._reloadCall.abort(); - } - - // there is only root - this._setCurrentDir('/', false); - - this._reloadCall = $.ajax({ - url: OC.linkToOCS('apps/files_external/api/v1') + 'mounts', - data: { - format: 'json' - }, - type: 'GET', - beforeSend: function(xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - } - }); - var callBack = this.reloadCallback.bind(this); - return this._reloadCall.then(callBack, callBack); - }, - - reloadCallback: function(result) { - delete this._reloadCall; - this.hideMask(); - - if (result.ocs && result.ocs.data) { - this.setFiles(this._makeFiles(result.ocs.data)); - return true; - } - return false; - }, - - /** - * Converts the OCS API response data to a file info - * list - * @param OCS API mounts array - * @return array of file info maps - */ - _makeFiles: function(data) { - var files = _.map(data, function(fileData) { - fileData.icon = OC.imagePath('core', 'filetypes/folder-external'); - fileData.mountType = 'external'; - return fileData; - }); - - files.sort(this._sortComparator); - - return files; - } - }); - - /** - * Mount point info attributes. - * - * @typedef {Object} OCA.Files_External.MountPointInfo - * - * @property {String} name mount point name - * @property {String} scope mount point scope "personal" or "system" - * @property {String} backend external storage backend name - */ - - OCA.Files_External.FileList = FileList; -})(); diff --git a/apps/files_external/js/oauth1.js b/apps/files_external/js/oauth1.js deleted file mode 100644 index 0fee36077c6..00000000000 --- a/apps/files_external/js/oauth1.js +++ /dev/null @@ -1,82 +0,0 @@ -window.addEventListener('DOMContentLoaded', function() { - - function displayGranted($tr) { - $tr.find('.configuration input.auth-param').attr('disabled', 'disabled').addClass('disabled-success'); - } - - OCA.Files_External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { - if (authMechanism === 'oauth1::oauth1') { - var config = $tr.find('.configuration'); - config.append($(document.createElement('input')) - .addClass('button auth-param') - .attr('type', 'button') - .attr('value', t('files_external', 'Grant access')) - .attr('name', 'oauth1_grant') - ); - - onCompletion.then(function() { - var configured = $tr.find('[data-parameter="configured"]'); - if ($(configured).val() == 'true') { - displayGranted($tr); - } else { - var app_key = $tr.find('.configuration [data-parameter="app_key"]').val(); - var app_secret = $tr.find('.configuration [data-parameter="app_secret"]').val(); - if (app_key != '' && app_secret != '') { - var pos = window.location.search.indexOf('oauth_token') + 12; - var token = $tr.find('.configuration [data-parameter="token"]'); - if (pos != -1 && window.location.search.substr(pos, $(token).val().length) == $(token).val()) { - var token_secret = $tr.find('.configuration [data-parameter="token_secret"]'); - var statusSpan = $tr.find('.status span'); - statusSpan.removeClass(); - statusSpan.addClass('waiting'); - $.post(OC.filePath('files_external', 'ajax', 'oauth1.php'), { step: 2, app_key: app_key, app_secret: app_secret, request_token: $(token).val(), request_token_secret: $(token_secret).val() }, function(result) { - if (result && result.status == 'success') { - $(token).val(result.access_token); - $(token_secret).val(result.access_token_secret); - $(configured).val('true'); - OCA.Files_External.Settings.mountConfig.saveStorageConfig($tr, function(status) { - if (status) { - displayGranted($tr); - } - }); - } else { - OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring OAuth1')); - } - }); - } - } - } - }); - } - }); - - $('#externalStorage').on('click', '[name="oauth1_grant"]', function(event) { - event.preventDefault(); - var tr = $(this).parent().parent(); - var app_key = $(this).parent().find('[data-parameter="app_key"]').val(); - var app_secret = $(this).parent().find('[data-parameter="app_secret"]').val(); - if (app_key != '' && app_secret != '') { - var configured = $(this).parent().find('[data-parameter="configured"]'); - var token = $(this).parent().find('[data-parameter="token"]'); - var token_secret = $(this).parent().find('[data-parameter="token_secret"]'); - $.post(OC.filePath('files_external', 'ajax', 'oauth1.php'), { step: 1, app_key: app_key, app_secret: app_secret, callback: location.protocol + '//' + location.host + location.pathname }, function(result) { - if (result && result.status == 'success') { - $(configured).val('false'); - $(token).val(result.data.request_token); - $(token_secret).val(result.data.request_token_secret); - OCA.Files_External.Settings.mountConfig.saveStorageConfig(tr, function() { - window.location = result.data.url; - }); - } else { - OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring OAuth1')); - } - }); - } else { - OC.dialogs.alert( - t('files_external', 'Please provide a valid app key and secret.'), - t('files_external', 'Error configuring OAuth1') - ); - } - }); - -}); diff --git a/apps/files_external/js/oauth2.js b/apps/files_external/js/oauth2.js deleted file mode 100644 index 086a95f038f..00000000000 --- a/apps/files_external/js/oauth2.js +++ /dev/null @@ -1,96 +0,0 @@ -window.addEventListener('DOMContentLoaded', function() { - - function displayGranted($tr) { - $tr.find('.configuration input.auth-param').attr('disabled', 'disabled').addClass('disabled-success'); - } - - OCA.Files_External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { - if (authMechanism === 'oauth2::oauth2') { - var config = $tr.find('.configuration'); - config.append($(document.createElement('input')) - .addClass('button auth-param') - .attr('type', 'button') - .attr('value', t('files_external', 'Grant access')) - .attr('name', 'oauth2_grant') - ); - - onCompletion.then(function() { - var configured = $tr.find('[data-parameter="configured"]'); - if ($(configured).val() == 'true') { - displayGranted($tr); - } else { - var client_id = $tr.find('.configuration [data-parameter="client_id"]').val(); - var client_secret = $tr.find('.configuration [data-parameter="client_secret"]') - .val(); - if (client_id != '' && client_secret != '') { - var params = {}; - window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { - params[key] = value; - }); - if (params['code'] !== undefined) { - var token = $tr.find('.configuration [data-parameter="token"]'); - var statusSpan = $tr.find('.status span'); - statusSpan.removeClass(); - statusSpan.addClass('waiting'); - $.post(OC.filePath('files_external', 'ajax', 'oauth2.php'), - { - step: 2, - client_id: client_id, - client_secret: client_secret, - redirect: location.protocol + '//' + location.host + location.pathname, - code: params['code'], - }, function(result) { - if (result && result.status == 'success') { - $(token).val(result.data.token); - $(configured).val('true'); - OCA.Files_External.Settings.mountConfig.saveStorageConfig($tr, function(status) { - if (status) { - displayGranted($tr); - } - }); - } else { - OC.dialogs.alert(result.data.message, - t('files_external', 'Error configuring OAuth2') - ); - } - } - ); - } - } - } - }); - } - }); - - $('#externalStorage').on('click', '[name="oauth2_grant"]', function(event) { - event.preventDefault(); - var tr = $(this).parent().parent(); - var configured = $(this).parent().find('[data-parameter="configured"]'); - var client_id = $(this).parent().find('[data-parameter="client_id"]').val(); - var client_secret = $(this).parent().find('[data-parameter="client_secret"]').val(); - if (client_id != '' && client_secret != '') { - var token = $(this).parent().find('[data-parameter="token"]'); - $.post(OC.filePath('files_external', 'ajax', 'oauth2.php'), - { - step: 1, - client_id: client_id, - client_secret: client_secret, - redirect: location.protocol + '//' + location.host + location.pathname, - }, function(result) { - if (result && result.status == 'success') { - $(configured).val('false'); - $(token).val('false'); - OCA.Files_External.Settings.mountConfig.saveStorageConfig(tr, function(status) { - window.location = result.data.url; - }); - } else { - OC.dialogs.alert(result.data.message, - t('files_external', 'Error configuring OAuth2') - ); - } - } - ); - } - }); - -}); diff --git a/apps/files_external/js/public_key.js b/apps/files_external/js/public_key.js deleted file mode 100644 index 7fa47f09f1b..00000000000 --- a/apps/files_external/js/public_key.js +++ /dev/null @@ -1,64 +0,0 @@ -window.addEventListener('DOMContentLoaded', function() { - - OCA.Files_External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { - if (scheme === 'publickey' && authMechanism === 'publickey::rsa') { - var config = $tr.find('.configuration'); - if ($(config).find('[name="public_key_generate"]').length === 0) { - setupTableRow($tr, config); - onCompletion.then(function() { - // If there's no private key, build one - if (0 === $(config).find('[data-parameter="private_key"]').val().length) { - generateKeys($tr); - } - }); - } - } - }); - - $('#externalStorage').on('click', '[name="public_key_generate"]', function(event) { - event.preventDefault(); - var tr = $(this).parent().parent(); - generateKeys(tr); - }); - - function setupTableRow(tr, config) { - var selectList = document.createElement('select'); - selectList.id = 'keyLength'; - - var options = [1024, 2048, 4096]; - for (var i = 0; i < options.length; i++) { - var option = document.createElement('option'); - option.value = options[i]; - option.text = options[i]; - selectList.appendChild(option); - } - - $(config).append(selectList); - - $(config).append($(document.createElement('input')) - .addClass('button auth-param') - .attr('type', 'button') - .attr('value', t('files_external', 'Generate keys')) - .attr('name', 'public_key_generate') - ); - } - - function generateKeys(tr) { - var config = $(tr).find('.configuration'); - var keyLength = config.find('#keyLength').val(); - - $.post(OC.filePath('files_external', 'ajax', 'public_key.php'), { - keyLength: keyLength - }, function(result) { - if (result && result.status === 'success') { - $(config).find('[data-parameter="public_key"]').val(result.data.public_key).keyup(); - $(config).find('[data-parameter="private_key"]').val(result.data.private_key); - OCA.Files_External.Settings.mountConfig.saveStorageConfig(tr, function() { - // Nothing to do - }); - } else { - OC.dialogs.alert(result.data.message, t('files_external', 'Error generating key pair') ); - } - }); - } -}); diff --git a/apps/files_external/js/rollingqueue.js b/apps/files_external/js/rollingqueue.js deleted file mode 100644 index df3797ada89..00000000000 --- a/apps/files_external/js/rollingqueue.js +++ /dev/null @@ -1,137 +0,0 @@ -/** - * ownCloud - * - * @author Juan Pablo VillafaƱez Ramos <jvillafanez@owncloud.com> - * @author Jesus Macias Portela <jesus@owncloud.com> - * @copyright (C) 2014 ownCloud, Inc. - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ - -(function(){ -/** - * Launch several functions at thee same time. The number of functions - * running at the same time is controlled by the queueWindow param - * - * The function list come in the following format: - * - * var flist = [ - * { - * funcName: function () { - * var d = $.Deferred(); - * setTimeout(function(){d.resolve();}, 1000); - * return d; - * } - * }, - * { - * funcName: $.get, - * funcArgs: [ - * OC.filePath('files_external', 'ajax', 'connectivityCheck.php'), - * {}, - * function () { - * console.log('titoooo'); - * } - * ] - * }, - * { - * funcName: $.get, - * funcArgs: [ - * OC.filePath('files_external', 'ajax', 'connectivityCheck.php') - * ], - * done: function () { - * console.log('yuupi'); - * }, - * always: function () { - * console.log('always done'); - * } - * } - *]; - * - * functions MUST implement the deferred interface - * - * @param functionList list of functions that the queue will run - * (check example above for the expected format) - * @param queueWindow specify the number of functions that will - * 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"; - } - - for (var i = 0; i < this.queueWindow; i++) { - this.launchNext(); - } - }; - - 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); - } - - if ($.isFunction(funcData.fail)) { - defObj.fail(funcData.fail); - } - - 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 (!OCA.Files_External) { - OCA.Files_External = {}; -} - -if (!OCA.Files_External.StatusManager) { - OCA.Files_External.StatusManager = {}; -} - -OCA.Files_External.StatusManager.RollingQueue = RollingQueue; - -})(); diff --git a/apps/files_external/js/statusmanager.js b/apps/files_external/js/statusmanager.js deleted file mode 100644 index 5f94192ea35..00000000000 --- a/apps/files_external/js/statusmanager.js +++ /dev/null @@ -1,613 +0,0 @@ -/** - * ownCloud - * - * @author Juan Pablo VillafaƱez Ramos <jvillafanez@owncloud.com> - * @author Jesus Macias Portela <jesus@owncloud.com> - * @copyright (C) 2014 ownCloud, Inc. - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ - -/** @global Handlebars */ - -if (!OCA.Files_External) { - OCA.Files_External = {}; -} - -if (!OCA.Files_External.StatusManager) { - OCA.Files_External.StatusManager = {}; -} - -OCA.Files_External.StatusManager = { - - mountStatus: null, - mountPointList: null, - - /** - * Function - * @param {callback} afterCallback - */ - - getMountStatus: function (afterCallback) { - var self = this; - if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) { - return; - } - - if (self.mountStatus) { - afterCallback(self.mountStatus); - } - }, - - /** - * Function Check mount point status from cache - * @param {string} mount_point - */ - - getMountPointListElement: function (mount_point) { - var element; - $.each(this.mountPointList, function (key, value) { - if (value.mount_point === mount_point) { - element = value; - return false; - } - }); - 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) { - return $.Deferred().resolve(); - } - - var defObj; - if (self.mountStatus[mountData.mount_point]) { - defObj = $.Deferred(); - afterCallback(mountData, self.mountStatus[mountData.mount_point]); - defObj.resolve(); // not really useful, but it'll keep the same behaviour - } else { - defObj = $.ajax({ - type: 'GET', - url: OC.getRootPath() + '/index.php/apps/files_external/' + ((mountData.type === 'personal') ? 'userstorages' : 'userglobalstorages') + '/' + mountData.id, - data: {'testOnly' : false}, - success: function (response) { - if (response && response.status === 0) { - self.mountStatus[mountData.mount_point] = response; - } else { - var statusCode = response.status ? response.status : 1; - var statusMessage = response.statusMessage ? response.statusMessage : t('files_external', 'Empty response from the server') - // failure response with error message - self.mountStatus[mountData.mount_point] = { - type: mountData.type, - status: statusCode, - id: mountData.id, - error: statusMessage, - userProvided: response.userProvided, - authMechanism: response.authMechanism, - canEdit: response.can_edit, - }; - } - afterCallback(mountData, self.mountStatus[mountData.mount_point]); - }, - error: function (jqxhr, state, error) { - var message; - if (mountData.location === 3) { - // In this case the error is because mount point use Login credentials and don't exist in the session - message = t('files_external', 'Couldn\'t access. Please log out and in again to activate this mount point'); - } else { - message = t('files_external', 'Couldn\'t get the information from the remote server: {code} {type}', { - code: jqxhr.status, - type: error - }); - } - self.mountStatus[mountData.mount_point] = { - type: mountData.type, - status: 1, - location: mountData.location, - error: message - }; - afterCallback(mountData, self.mountStatus[mountData.mount_point]); - } - }); - } - 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 { - self.isGetMountPointListRunning = true; - $.ajax({ - type: 'GET', - url: OC.linkToOCS('apps/files_external/api/v1') + 'mounts?format=json', - success: function (response) { - self.mountPointList = []; - _.each(response.ocs.data, function (mount) { - var element = {}; - element.mount_point = mount.name; - element.type = mount.scope; - element.location = ""; - element.id = mount.id; - element.backendText = mount.backend; - element.backend = mount.class; - - self.mountPointList.push(element); - }); - afterCallback(self.mountPointList); - }, - error: function (jqxhr, state, error) { - self.mountPointList = []; - OC.Notification.show(t('files_external', 'Couldn\'t get the list of external mount points: {type}', - {type: error}), {type: 'error'} - ); - }, - complete: function () { - self.isGetMountPointListRunning = false; - } - }); - } - }, - - /** - * 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) { - this.getMountStatus($.proxy(function (allMountStatus) { - if (allMountStatus.hasOwnProperty(name) && allMountStatus[name].status > 0 && allMountStatus[name].status < 7) { - var mountData = allMountStatus[name]; - if (mountData.type === "system") { - if (mountData.userProvided || mountData.authMechanism === 'password::global::user') { - // personal mount whit credentials problems - this.showCredentialsDialog(name, mountData); - } else if (mountData.canEdit) { - OC.dialogs.confirm(t('files_external', 'There was an error with message: ') + mountData.error + '. Do you want to review mount point config in admin settings page?', t('files_external', 'External mount error'), function (e) { - if (e === true) { - OC.redirect(OC.generateUrl('/settings/admin/externalstorages')); - } - }); - } else { - OC.dialogs.info(t('files_external', 'There was an error with message: ') + mountData.error + '. Please contact your system administrator.', t('files_external', 'External mount error'), () => {}); - } - } else { - OC.dialogs.confirm(t('files_external', 'There was an error with message: ') + mountData.error + '. Do you want to review mount point config in personal settings page?', t('files_external', 'External mount error'), function (e) { - if (e === true) { - OC.redirect(OC.generateUrl('/settings/personal#' + t('files_external', 'external-storage'))); - } - }); - } - } - }, this)); - }, - - /** - * 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 > 0) { - var trElement = FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(mountPoint)); - - var route = OCA.Files_External.StatusManager.Utils.getIconRoute(trElement) + '-error'; - - if (OCA.Files_External.StatusManager.Utils.isCorrectViewAndRootFolder()) { - OCA.Files_External.StatusManager.Utils.showIconError(mountPoint, $.proxy(OCA.Files_External.StatusManager.manageMountPointError, OCA.Files_External.StatusManager), route); - } - return false; - } else { - if (OCA.Files_External.StatusManager.Utils.isCorrectViewAndRootFolder()) { - OCA.Files_External.StatusManager.Utils.restoreFolder(mountPoint); - OCA.Files_External.StatusManager.Utils.toggleLink(mountPoint, true, true); - } - return true; - } - }, - - /** - * 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) { - var trElement = $('.files-fileList tr[data-file=\"' + OCA.Files_External.StatusManager.Utils.jqSelEscape(value.mount_point) + '\"]'); //FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(value.mount_point)); - trElement.attr('data-external-backend', value.backend); - if (elementList) { - elementList = elementList.add(trElement); - } else { - elementList = trElement; - } - }); - - if (elementList instanceof $) { - if (OCA.Files_External.StatusManager.Utils.isCorrectViewAndRootFolder()) { - // Put their custom icon - OCA.Files_External.StatusManager.Utils.changeFolderIcon(elementList); - // Save default view - OCA.Files_External.StatusManager.Utils.storeDefaultFolderIconAndBgcolor(elementList); - OCA.Files_External.StatusManager.Utils.toggleLink(elementList.find('a.name'), false, false); - } - } - }, - - /** - * Function to process the whole mount point list in relation with their status (Async queue) - */ - - launchFullConnectivityCheckOneByOne: 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.show(t('files_external', 'Couldn\'t fetch list of Windows network drive mount points: Empty response from server'), - {type: 'error'} - ); - return; - } - if (list && list.length > 0) { - self.processMountList(list); - - if (!self.mountStatus) { - self.mountStatus = {}; - } - - var ajaxQueue = []; - $.each(list, function (key, value) { - var queueElement = { - funcName: $.proxy(self.getMountStatusForMount, self), - funcArgs: [value, - $.proxy(self.processMountStatusIndividual, self)] - }; - ajaxQueue.push(queueElement); - }); - - var rolQueue = new OCA.Files_External.StatusManager.RollingQueue(ajaxQueue, 4, function () { - if (!self.notificationHasShown) { - $.each(self.mountStatus, function (key, value) { - if (value.status === 1) { - self.notificationHasShown = true; - } - }); - } - }); - rolQueue.runQueue(); - } - }); - }, - - - /** - * 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; - } - - var self = this; - var ajaxQueue = []; - $.each(mountListData, function (key, value) { - if (recheck && value.mount_point in self.mountStatus) { - delete self.mountStatus[value.mount_point]; - } - var queueElement = { - funcName: $.proxy(self.getMountStatusForMount, self), - funcArgs: [value, - $.proxy(self.processMountStatusIndividual, self)] - }; - ajaxQueue.push(queueElement); - }); - new OCA.Files_External.StatusManager.RollingQueue(ajaxQueue, 4).runQueue(); - }, - - - /** - * 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; - } - - var self = this; - var mountListData = []; - - if (!self.mountStatus) { - self.mountStatus = {}; - } - - $.each(mountListNames, function (key, value) { - var mountData = self.getMountPointListElement(value); - if (mountData) { - mountListData.push(mountData); - } - }); - - // for all mounts in the list, delete the cached status values - if (recheck) { - $.each(mountListData, function (key, value) { - if (value.mount_point in self.mountStatus) { - delete self.mountStatus[value.mount_point]; - } - }); - } - - self.processMountList(mountListData); - self.launchPartialConnectivityCheck(mountListData, recheck); - }, - - credentialsDialogTemplate: - '<div id="files_external_div_form"><div>' + - '<div>{{credentials_text}}</div>' + - '<form>' + - '<input type="text" name="username" placeholder="{{placeholder_username}}"/>' + - '<input type="password" name="password" placeholder="{{placeholder_password}}"/>' + - '</form>' + - '</div></div>', - - /** - * Function to display custom dialog to enter credentials - * @param {any} mountPoint - - * @param {any} mountData - - */ - showCredentialsDialog: function (mountPoint, mountData) { - var dialog = $(OCA.Files_External.Templates.credentialsDialog({ - credentials_text: t('files_external', 'Please enter the credentials for the {mount} mount', { - 'mount': mountPoint - }), - placeholder_username: t('files_external', 'Username'), - placeholder_password: t('files_external', 'Password') - })); - - $('body').append(dialog); - - var apply = function () { - var username = dialog.find('[name=username]').val(); - var password = dialog.find('[name=password]').val(); - var endpoint = OC.generateUrl('apps/files_external/userglobalstorages/{id}', { - id: mountData.id - }); - $('.oc-dialog-close').hide(); - $.ajax({ - type: 'PUT', - url: endpoint, - data: { - backendOptions: { - user: username, - password: password - } - }, - success: function (data) { - OC.Notification.show(t('files_external', 'Credentials saved'), {type: 'success'}); - dialog.ocdialog('close'); - /* Trigger status check again */ - OCA.Files_External.StatusManager.recheckConnectivityForMount([OC.basename(data.mountPoint)], true); - }, - error: function () { - $('.oc-dialog-close').show(); - OC.Notification.show(t('files_external', 'Credentials saving failed'), {type: 'error'}); - } - }); - return false; - }; - - var ocdialogParams = { - modal: true, - title: t('files_external', 'Credentials required'), - buttons: [{ - text: t('files_external', 'Save'), - click: apply, - closeOnEscape: true - }], - closeOnExcape: true - }; - - dialog.ocdialog(ocdialogParams) - .bind('ocdialogclose', function () { - dialog.ocdialog('destroy').remove(); - }); - - dialog.find('form').on('submit', apply); - dialog.find('form input:first').focus(); - dialog.find('form input').keyup(function (e) { - if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) { - $(e.target).closest('form').submit(); - return false; - } else { - return true; - } - }); - } -}; - -OCA.Files_External.StatusManager.Utils = { - - showIconError: function (folder, clickAction, errorImageUrl) { - var imageUrl = "url(" + errorImageUrl + ")"; - var trFolder = $('.files-fileList tr[data-file=\"' + OCA.Files_External.StatusManager.Utils.jqSelEscape(folder) + '\"]'); //FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(folder)); - this.changeFolderIcon(folder, imageUrl); - this.toggleLink(folder, false, clickAction); - trFolder.addClass('externalErroredRow'); - }, - - /** - * @param folder string with the folder or jQuery element pointing to the tr element - */ - storeDefaultFolderIconAndBgcolor: function (folder) { - var trFolder; - if (folder instanceof $) { - trFolder = folder; - } else { - trFolder = $('.files-fileList tr[data-file=\"' + OCA.Files_External.StatusManager.Utils.jqSelEscape(folder) + '\"]'); //FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(folder)); //$('.files-fileList tr[data-file=\"' + OCA.Files_External.StatusManager.Utils.jqSelEscape(folder) + '\"]'); - } - trFolder.each(function () { - var thisElement = $(this); - if (thisElement.data('oldbgcolor') === undefined) { - thisElement.data('oldbgcolor', thisElement.css('background-color')); - } - }); - - var icon = trFolder.find('td.filename div.thumbnail'); - icon.each(function () { - var thisElement = $(this); - if (thisElement.data('oldImage') === undefined) { - thisElement.data('oldImage', thisElement.css('background-image')); - } - }); - }, - - /** - * @param folder string with the folder or jQuery element pointing to the tr element - */ - restoreFolder: function (folder) { - var trFolder; - if (folder instanceof $) { - trFolder = folder; - } else { - // can't use here FileList.findFileEl(OCA.Files_External.StatusManager.Utils.jqSelEscape(folder)); return incorrect instance of filelist - trFolder = $('.files-fileList tr[data-file=\"' + OCA.Files_External.StatusManager.Utils.jqSelEscape(folder) + '\"]'); - } - var tdChilds = trFolder.find("td.filename div.thumbnail"); - tdChilds.each(function () { - var thisElement = $(this); - thisElement.css('background-image', thisElement.data('oldImage')); - }); - }, - - /** - * @param folder string with the folder or jQuery element pointing to the first td element - * of the tr matching the folder name - */ - changeFolderIcon: function (filename) { - var file; - var route; - if (filename instanceof $) { - //trElementList - $.each(filename, function (index) { - route = OCA.Files_External.StatusManager.Utils.getIconRoute($(this)); - $(this).attr("data-icon", route); - $(this).find('td.filename div.thumbnail').css('background-image', "url(" + route + ")").css('display', 'none').css('display', 'inline'); - }); - } else { - file = $(".files-fileList tr[data-file=\"" + this.jqSelEscape(filename) + "\"] > td.filename div.thumbnail"); - var parentTr = file.parents('tr:first'); - route = OCA.Files_External.StatusManager.Utils.getIconRoute(parentTr); - parentTr.attr("data-icon", route); - file.css('background-image', "url(" + route + ")").css('display', 'none').css('display', 'inline'); - } - }, - - /** - * @param backend string with the name of the external storage backend - * of the tr matching the folder name - */ - getIconRoute: function (tr) { - if (OCA.Theming) { - var icon = OC.generateUrl('/apps/theming/img/core/filetypes/folder-external.svg?v=' + OCA.Theming.cacheBuster); - } else { - var icon = OC.imagePath('core', 'filetypes/folder-external'); - } - var backend = null; - - if (tr instanceof $) { - backend = tr.attr('data-external-backend'); - } - - switch (backend) { - case 'windows_network_drive': - icon = OC.imagePath('windows_network_drive', 'folder-windows'); - break; - } - - return icon; - }, - - toggleLink: function (filename, active, action) { - var link; - if (filename instanceof $) { - link = filename; - } else { - link = $(".files-fileList tr[data-file=\"" + this.jqSelEscape(filename) + "\"] > td.filename a.name"); - } - if (active) { - link.off('click.connectivity'); - OCA.Files.App.fileList.fileActions.display(link.parent(), true, OCA.Files.App.fileList); - } else { - link.find('.fileactions, .nametext .action').remove(); // from files/js/fileactions (display) - link.off('click.connectivity'); - link.on('click.connectivity', function (e) { - if (action && $.isFunction(action)) { - action(filename); - } - e.preventDefault(); - return false; - }); - } - }, - - isCorrectViewAndRootFolder: function () { - // correct views = files & extstoragemounts - if (OCA.Files.App.getActiveView() === 'files' || OCA.Files.App.getActiveView() === 'extstoragemounts') { - return OCA.Files.App.currentFileList.getCurrentDirectory() === '/'; - } - return false; - }, - - /* escape a selector expression for jQuery */ - jqSelEscape: function (expression) { - if (expression) { - return expression.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&'); - } - return null; - }, - - /* Copied from http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key */ - checkNested: function (cobj /*, level1, level2, ... levelN*/) { - var args = Array.prototype.slice.call(arguments), - obj = args.shift(); - - for (var i = 0; i < args.length; i++) { - if (!obj || !obj.hasOwnProperty(args[i])) { - return false; - } - obj = obj[args[i]]; - } - return true; - } -}; |