Shared folders UI

pull/1/head
yflory 6 years ago
parent bc7524c134
commit 4b86ed2dec

@ -454,6 +454,7 @@ define(function () {
out.fc_delete_owned = "Supprimer du serveur";
out.fc_restore = "Restaurer";
out.fc_remove = "Supprimer de votre CryptDrive";
out.fc_remove_sharedfolder = "Supprimer";
out.fc_empty = "Vider la corbeille";
out.fc_prop = "Propriétés";
out.fc_hashtag = "Mots-clés";

@ -454,6 +454,7 @@ define(function () {
out.fc_delete_owned = "Delete from the server";
out.fc_restore = "Restore";
out.fc_remove = "Remove from your CryptDrive";
out.fc_remove_sharedfolder = "Remove";
out.fc_empty = "Empty the trash";
out.fc_prop = "Properties";
out.fc_hashtag = "Tags";

@ -222,17 +222,21 @@ define([
}));
}
$('<label>', {'for': 'cp-app-prop-ctime'}).text(Messages.fm_creation)
.appendTo($d);
$d.append(UI.dialog.selectable(new Date(data.ctime).toLocaleString(), {
id: 'cp-app-prop-ctime',
}));
if (data.ctime) {
$('<label>', {'for': 'cp-app-prop-ctime'}).text(Messages.fm_creation)
.appendTo($d);
$d.append(UI.dialog.selectable(new Date(data.ctime).toLocaleString(), {
id: 'cp-app-prop-ctime',
}));
}
$('<label>', {'for': 'cp-app-prop-atime'}).text(Messages.fm_lastAccess)
.appendTo($d);
$d.append(UI.dialog.selectable(new Date(data.atime).toLocaleString(), {
id: 'cp-app-prop-atime',
}));
if (data.atime) {
$('<label>', {'for': 'cp-app-prop-atime'}).text(Messages.fm_lastAccess)
.appendTo($d);
$d.append(UI.dialog.selectable(new Date(data.atime).toLocaleString(), {
id: 'cp-app-prop-atime',
}));
}
if (common.isLoggedIn() && AppConfig.enablePinning) {
// check the size of this file...

@ -111,6 +111,17 @@ define([
cb(obj);
});
};
common.addSharedFolder = function (secret, cb) {
postMessage("ADD_SHARED_FOLDER", {
path: ['root'],
folderData: {
href: '/drive/#' + Hash.getEditHashFromKeys(secret),
roHref: '/drive/#' + Hash.getViewHashFromKeys(secret),
channel: secret.channel,
ctime: +new Date()
}
}, cb);
};
common.drive = {};
common.drive.onLog = Util.mkEvent();
common.drive.onChange = Util.mkEvent();

@ -1147,7 +1147,7 @@ define([
// SHARED FOLDERS
var loadSharedFolder = function (id, data, cb) {
var parsed = Hash.parsePadUrl(data.href);
var secret = Hash.getSecrets('folder', parsed.hash, data.password);
var secret = Hash.getSecrets('drive', parsed.hash, data.password);
var listmapConfig = {
data: {},
websocketURL: NetConfig.getWebsocketURL(),
@ -1191,7 +1191,12 @@ define([
onSync(waitFor());
// 2b. load the proxy
loadSharedFolder(id, data, waitFor());
rt = loadSharedFolder(id, data.folderData, waitFor(function () {
if (data.metadata) { // Creating a new shared folder
rt.proxy.metadata = data.metadata;
onSync(waitFor());
}
}));
}).nThen(function () {
sendDriveEvent('DRIVE_CHANGE', {
path: ['drive'].concat(path)
@ -1201,16 +1206,19 @@ define([
};
store.createSharedFolder = function () {
// XXX
var hash = Hash.createRandomHash('folder');
var href = '/folder/#' + hash;
var secret = Hash.getSecrets('folder', hash);
var hash = Hash.createRandomHash('drive');
var href = '/drive/#' + hash;
var secret = Hash.getSecrets('drive', hash);
Store.addSharedFolder(null, {
path: ['root'],
folderData: {
href: href,
roHref: '/folder/#' + Hash.getViewHashFromKeys(secret),
roHref: '/drive/#' + Hash.getViewHashFromKeys(secret),
channel: secret.channel,
title: "Test",
ctime: +new Date()
},
metadata: {
title: "Test"
}
}, function () {
console.log('done');

@ -53,6 +53,7 @@ define([
GET_STRONGER_HASH: Store.getStrongerHash,
INCREMENT_TEMPLATE_USE: Store.incrementTemplateUse,
GET_SHARED_FOLDER: Store.getSharedFolder,
ADD_SHARED_FOLDER: Store.addSharedFolder,
// Messaging
INVITE_FROM_USERLIST: Store.inviteFromUserlist,
ADD_DIRECT_MESSAGE_HANDLERS: Store.addDirectMessageHandlers,

@ -71,6 +71,14 @@ define([
exp.pushSharedFolder = function (data, cb) {
if (typeof cb !== "function") { cb = function () {}; }
// Check we already have this shared folder in our drive
if (Object.keys(files[SHARED_FOLDERS]).some(function (k) {
return files[SHARED_FOLDERS][k].channel === data.channel;
})) {
return void cb ('EEXISTS');
}
// Add the folder
var todo = function () {
var id = Util.createRandomInteger();
files[SHARED_FOLDERS][id] = data;
@ -695,11 +703,11 @@ define([
});
};
fixSharedFolders();
fixRoot();
fixTrashRoot();
fixTemplate();
fixFilesData();
fixSharedFolders();
fixDrive();
if (JSON.stringify(files) !== before) {

@ -259,7 +259,17 @@ define([
data = data || {};
var resolved = _resolvePath(Env, data.path);
if (!resolved || !resolved.userObject) { return void cb({error: 'E_NOTFOUND'}); }
resolved.userObject.addFolder(resolved.path, data.name, cb);
resolved.userObject.addFolder(resolved.path, data.name, function (obj) {
// The result is the relative path of the new folder. We have to make it absolute.
if (obj.newPath && resolved.id) {
var fPath = _getUserObjectPath(Env, resolved.userObject);
if (fPath) {
// This is a shared folder, we have to fix the paths in the search results
Array.prototype.unshift.apply(obj.newPath, fPath);
}
}
cb(obj);
});
};
// Delete permanently some pads or folders
var _delete = function (Env, data, cb) {
@ -290,6 +300,13 @@ define([
data = data || {};
var resolved = _resolvePath(Env, data.path);
if (!resolved || !resolved.userObject) { return void cb({error: 'E_NOTFOUND'}); }
if (!resolved.id) {
var el = Env.user.userObject.find(resolved.path);
if (Env.user.userObject.isSharedFolder(el) && Env.folders[el]) {
Env.folders[el].proxy.metadata.title = data.newName;
return void cb();
}
}
resolved.userObject.rename(resolved.path, data.newName, cb);
};
var onCommand = function (Env, cmdData, cb) {
@ -298,7 +315,6 @@ define([
switch (cmd) {
case 'move':
_move(Env, data, cb); break;
//store.userObject.move(data.paths, data.newPath, cb2); break;
case 'restore':
_restore(Env, data, cb); break;
case 'addFolder':
@ -580,7 +596,7 @@ define([
};
var _getUserObjectPath = function (Env, uo) {
var fId = uo.id;
var fId = Number(uo.id);
if (!fId) { return; }
var fPath = Env.user.userObject.findFile(fId)[0];
return fPath;
@ -686,6 +702,11 @@ define([
return obj;
};
var isInSharedFolder = function (Env, path) {
var resolved = _resolvePath(Env, path);
return typeof resolved.id === "number";
};
/* Generic: doesn't need access to a proxy */
var isFile = function (Env, el, allowStr) {
return Env.user.userObject.isFile(el, allowStr);
@ -772,6 +793,7 @@ define([
findFile: callWithEnv(findFile),
findChannels: callWithEnv(findChannels),
getSharedFolderData: callWithEnv(getSharedFolderData),
isInSharedFolder: callWithEnv(isInSharedFolder),
// Generic
isFile: callWithEnv(isFile),
isFolder: callWithEnv(isFolder),

@ -313,6 +313,10 @@ define([
'tabindex': '-1',
'data-icon': faDelete,
}, Messages.fc_remove)),
h('li', h('a.cp-app-drive-context-removesf.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faDelete,
}, Messages.fc_remove_sharedfolder)),
h('li', h('a.cp-app-drive-context-properties.dropdown-item', {
'tabindex': '-1',
'data-icon': faProperties,
@ -715,6 +719,9 @@ define([
$name.hide();
var el = manager.find(path);
var name = manager.isFile(el) ? manager.getTitle(el) : path[path.length - 1];
if (manager.isSharedFolder(el)) {
name = manager.getSharedFolderData(el).title;
}
var $input = $('<input>', {
placeholder: name,
value: name
@ -812,6 +819,14 @@ define([
} else if ($element.is('.cp-app-drive-element-noreadonly')) {
hide.push('openro'); // Remove open 'view' mode
}
} else if ($element.is('.cp-app-drive-element-sharedf')) {
if (containsFolder) {
// More than 1 folder selected: cannot create a new subfolder
hide.push('newfolder');
}
containsFolder = true;
hide.push('openro');
hide.push('hashtag');
} else { // it's a folder
if (containsFolder) {
// More than 1 folder selected: cannot create a new subfolder
@ -827,6 +842,13 @@ define([
hide.push('restore');
hide.push('properties');
}
// If we're not in the trash nor in a shared folder, hide "remove"
if (!manager.isInSharedFolder(path)) {
hide.push('removesf');
} else if (type === "tree") {
hide.push('delete');
hide.push('deleteowned');
}
});
if (paths.length > 1) {
hide.push('restore');
@ -850,8 +872,8 @@ define([
show = ['newfolder', 'newdoc'];
break;
case 'tree':
show = ['open', 'openro', 'rename', 'delete', 'deleteowned', 'newfolder',
'properties', 'hashtag'];
show = ['open', 'openro', 'rename', 'delete', 'deleteowned', 'removesf',
'newfolder', 'properties', 'hashtag'];
break;
case 'default':
show = ['open', 'openro', 'openparent', 'delete', 'deleteowned', 'properties', 'hashtag'];
@ -1277,6 +1299,16 @@ define([
addDragAndDropHandlers($content, null, true, true);
// In list mode, display metadata from the filesData object
var _addOwnership = function ($span, $state, data) {
if (data.owners && data.owners.indexOf(edPublic) !== -1) {
var $owned = $ownedIcon.clone().appendTo($state);
$owned.attr('title', Messages.fm_padIsOwned);
$span.addClass('cp-app-drive-element-owned');
} else if (data.owners && data.owners.length) {
var $owner = $ownerIcon.clone().appendTo($state);
$owner.attr('title', Messages.fm_padIsOwnedOther);
}
};
var addFileData = function (element, $span) {
if (!manager.isFile(element)) { return; }
@ -1298,14 +1330,7 @@ define([
var $renamed = $renamedIcon.clone().appendTo($state);
$renamed.attr('title', Messages._getKey('fm_renamedPad', [data.title]));
}
if (data.owners && data.owners.indexOf(edPublic) !== -1) {
var $owned = $ownedIcon.clone().appendTo($state);
$owned.attr('title', Messages.fm_padIsOwned);
$span.addClass('cp-app-drive-element-owned');
} else if (data.owners && data.owners.length) {
var $owner = $ownerIcon.clone().appendTo($state);
$owner.attr('title', Messages.fm_padIsOwnedOther);
}
_addOwnership($span, $state, data);
var name = manager.getTitle(element);
@ -1339,16 +1364,18 @@ define([
var addFolderData = function (element, key, $span) {
if (!element || !manager.isFolder(element)) { return; }
// The element with the class '.name' is underlined when the 'li' is hovered
var $state = $('<span>', {'class': 'cp-app-drive-element-state'});
if (manager.isSharedFolder(element)) {
var data = manager.getSharedFolderData(element);
key = data && data.title ? data.title : key;
element = manager.folders[element].proxy[manager.user.userObject.ROOT];
$span.addClass('cp-app-drive-element-sharedf');
_addOwnership($span, $state, data);
}
var sf = manager.hasSubfolder(element);
var files = manager.hasFile(element);
var $name = $('<span>', {'class': 'cp-app-drive-element-name'}).text(key);
var $state = $('<span>', {'class': 'cp-app-drive-element-state'});
var $subfolders = $('<span>', {
'class': 'cp-app-drive-element-folders cp-app-drive-element-list'
}).text(sf);
@ -2594,6 +2621,10 @@ define([
var $element = createTreeElement(key, $icon.clone(), newPath, true, true, subfolder, isCurrentFolder);
$element.appendTo($list);
$element.find('>.cp-app-drive-element-row').contextmenu(openContextMenu('tree'));
if (isSharedFolder) {
$element.find('>.cp-app-drive-element-row')
.addClass('cp-app-drive-element-sharedf');
}
createTree($element, newPath);
});
};
@ -2750,12 +2781,17 @@ define([
});
var getProperties = APP.getProperties = function (el, cb) {
if (!manager.isFile(el)) {
if (!manager.isFile(el) && !manager.isSharedFolder(el)) {
return void cb('NOT_FILE');
}
//var ro = manager.isReadOnlyFile(el);
var base = APP.origin;
var data = JSON.parse(JSON.stringify(manager.getFileData(el)));
var data;
if (manager.isSharedFolder(el)) {
data = JSON.parse(JSON.stringify(manager.getSharedFolderData(el)));
} else {
data = JSON.parse(JSON.stringify(manager.getFileData(el)));
}
if (!data || !(data.href || data.roHref)) { return void cb('INVALID_FILE'); }
if (data.href) {
@ -2902,6 +2938,9 @@ define([
else if ($(this).hasClass("cp-app-drive-context-remove")) {
return void deletePaths(paths);
}
else if ($(this).hasClass("cp-app-drive-context-removesf")) {
return void deletePaths(paths);
}
else if ($(this).hasClass("cp-app-drive-context-restore")) {
if (paths.length !== 1) { return; }
var restorePath = paths[0].path;

@ -37,10 +37,19 @@ define([
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
var getSecrets = function (Cryptpad, Utils, cb) {
var hash = window.location.hash.slice(1) || Utils.LocalStore.getUserHash() ||
Utils.LocalStore.getFSHash();
var hash = window.location.hash.slice(1);
var secret = Utils.Hash.getSecrets('drive', hash);
if (hash) {
// Add a shared folder!
// XXX password?
Cryptpad.addSharedFolder(secret, function (obj) {
window.location.hash = "";
cb(null, secret);
});
return;
}
// No password for drive
cb(null, Utils.Hash.getSecrets('drive', hash));
cb(null, secret);
};
var addRpc = function (sframeChan, Cryptpad, Utils) {
sframeChan.on('EV_BURN_ANON_DRIVE', function () {
@ -91,6 +100,7 @@ define([
SFCommonO.start({
getSecrets: getSecrets,
noHash: true,
noRealtime: true,
driveEvents: true,
addRpc: addRpc
});

Loading…
Cancel
Save