From 1cddd99baa9d098c27c0d71ec918ea2744617563 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Tue, 30 Jul 2019 16:39:28 +0200 Subject: [PATCH] Convert folder into shared folders now working --- www/common/proxy-manager.js | 67 +++++++++++++++++++++++++++++++++++++ www/common/userObject.js | 4 +-- www/drive/inner.js | 2 +- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index d35df4e68..7b79bcb14 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -461,6 +461,62 @@ define([ cb(id); }); }; + + // convert a folder to a Shared Folder + var _convertFolderToSharedFolder = function (Env, data, cb) { + var path = data.path; + var folderElement = Env.user.userObject.find(path); + if (data.path.length <= 1) { return; } + if (_isInSharedFolder(Env, path)) { return; } + if (Env.user.userObject.hasSubSharedFolder(folderElement)) { return; } + var parentPath = path.slice(0, -1); + var parentFolder = Env.user.userObject.find(parentPath); + var folderName = path[path.length - 1]; + var SFId; + var sharedFolderElement; + nThen(function (waitFor) { + // create shared folder + _addSharedFolder(Env, { + path: parentPath, + name: folderName, + owned: true, + password: '', + }, waitFor(function (id) { SFId = id; })); + }).nThen(function (waitFor) { + // move everything from folder to SF + if (!SFId) { return void cb(); } + var paths = []; + for (var el in folderElement) { + if (Env.user.userObject.isFolder(folderElement[el]) || Env.user.userObject.isFile(folderElement[el])) { + paths.push(path.concat(el)); + } + } + var SFKey = Object.keys(parentFolder).find(function (el) { + return parentFolder[el] === SFId; + }); + var newPath = parentPath.concat(SFKey).concat(UserObject.ROOT); + sharedFolderElement = Env.user.proxy[UserObject.SHARED_FOLDERS][SFId]; + _move(Env, { + paths: paths, + newPath: newPath, + copy: false, + }, waitFor()); + }).nThen(function (waitFor) { + // migrate metadata + var metadata = Env.user.userObject.getFolderData(folderElement); + for (var key in metadata) { + if (key === "metadata") { continue; } + sharedFolderElement[key] = metadata[key]; + } + }).nThen(function (waitFor) { + // remove folder + Env.user.userObject.delete([path], waitFor()); + }).nThen(function () { + // call callback + cb(); + }); + } + // Delete permanently some pads or folders var _delete = function (Env, data, cb) { data = data || {}; @@ -598,6 +654,8 @@ define([ _addFolder(Env, data, cb); break; case 'addSharedFolder': _addSharedFolder(Env, data, cb); break; + case 'convertFolderToSharedFolder': + _convertFolderToSharedFolder(Env, data, cb); break; case 'delete': _delete(Env, data, cb); break; case 'emptyTrash': @@ -914,6 +972,14 @@ define([ } }, cb); }; + var convertFolderToSharedFolderInner = function (Env, path, cb) { + return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", { + cmd: "convertFolderToSharedFolder", + data: { + path: path + } + }, cb); + }; var deleteInner = function (Env, paths, cb) { return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", { cmd: "delete", @@ -1117,6 +1183,7 @@ define([ emptyTrash: callWithEnv(emptyTrashInner), addFolder: callWithEnv(addFolderInner), addSharedFolder: callWithEnv(addSharedFolderInner), + convertFolderToSharedFolder: callWithEnv(convertFolderToSharedFolderInner), delete: callWithEnv(deleteInner), restore: callWithEnv(restoreInner), setFolderData: callWithEnv(setFolderDataInner), diff --git a/www/common/userObject.js b/www/common/userObject.js index eed9fc19c..9bf3487d6 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -158,13 +158,13 @@ define([ } }; - exp.hasSubSharedFolder = function (folder) { + var hasSubSharedFolder = exp.hasSubSharedFolder = function (folder) { for (var el in folder) { if (isSharedFolder(folder[el])) { return true; } else if (isFolder(folder[el])) { - if (exp.hasSubSharedFolder(folder[el])) { + if (hasSubSharedFolder(folder[el])) { return true; } } diff --git a/www/drive/inner.js b/www/drive/inner.js index 1694564f9..456e91efb 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3601,7 +3601,7 @@ define([ UI.confirm(Messages.convertFolderToSF_confirm || "In order to be shared, this folder must be converted into a shared folder. Proceed ?", function(res) { if (!res) { return; } if (paths[0].path.length <= 1) { return; } // if root - // convert folder to Shared Folder + manager.convertFolderToSharedFolder(paths[0].path, refresh); }); } } else { // File