Display a team drive
This commit is contained in:
parent
222ea650d1
commit
fa2d148df4
@ -40,6 +40,7 @@ define([
|
|||||||
Pinpad.create(ctx.store.network, data, function (e, call) {
|
Pinpad.create(ctx.store.network, data, function (e, call) {
|
||||||
if (e) { return void cb(e); }
|
if (e) { return void cb(e); }
|
||||||
team.rpc = call;
|
team.rpc = call;
|
||||||
|
cb();
|
||||||
// XXX get pin limit?
|
// XXX get pin limit?
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -159,7 +160,6 @@ define([
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
delete ctx.onReadyHandlers[id];
|
delete ctx.onReadyHandlers[id];
|
||||||
console.log(cb);
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ define([
|
|||||||
|
|
||||||
var cfg = {
|
var cfg = {
|
||||||
data: {},
|
data: {},
|
||||||
readOnly: Boolean(secret.keys.signKey),
|
readOnly: !Boolean(secret.keys.signKey),
|
||||||
network: ctx.store.network,
|
network: ctx.store.network,
|
||||||
channel: secret.channel,
|
channel: secret.channel,
|
||||||
crypto: crypto,
|
crypto: crypto,
|
||||||
@ -192,15 +192,13 @@ define([
|
|||||||
var createTeam = function (ctx, data, cId, _cb) {
|
var createTeam = function (ctx, data, cId, _cb) {
|
||||||
var cb = Util.once(_cb);
|
var cb = Util.once(_cb);
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
var password = Hash.createChannelId();
|
var password = Hash.createChannelId();
|
||||||
var hash = Hash.createRandomHash('team', password);
|
var hash = Hash.createRandomHash('team', password);
|
||||||
var secret = Hash.getSecrets('team', hash, password);
|
var secret = Hash.getSecrets('team', hash, password);
|
||||||
var keyPair = Nacl.sign.keyPair(); // keyPair.secretKey , keyPair.publicKey
|
var keyPair = Nacl.sign.keyPair(); // keyPair.secretKey , keyPair.publicKey
|
||||||
|
|
||||||
var membersSecret = Hash.getSecrets('members');
|
var membersSecret = Hash.getSecrets('members');
|
||||||
var membersHashes = Hash.getHashes(secret);
|
var membersHashes = Hash.getHashes(membersSecret);
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
network: ctx.store.network,
|
network: ctx.store.network,
|
||||||
@ -231,8 +229,8 @@ console.log(data);
|
|||||||
// Store keys in our drive
|
// Store keys in our drive
|
||||||
var id = Util.createRandomInteger();
|
var id = Util.createRandomInteger();
|
||||||
var keys = {
|
var keys = {
|
||||||
edPrivate: keyPair.secretKey,
|
edPrivate: Nacl.util.encodeBase64(keyPair.secretKey),
|
||||||
edPublic: keyPair.publicKey
|
edPublic: Nacl.util.encodeBase64(keyPair.publicKey)
|
||||||
};
|
};
|
||||||
ctx.store.proxy.teams[id] = {
|
ctx.store.proxy.teams[id] = {
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -249,7 +247,7 @@ console.log(data);
|
|||||||
members: membersHashes.viewHash,
|
members: membersHashes.viewHash,
|
||||||
};
|
};
|
||||||
// Add rpc key
|
// Add rpc key
|
||||||
proxy.edPublic = keyPair.publicKey;
|
proxy.edPublic = Nacl.util.encodeBase64(keyPair.publicKey);
|
||||||
|
|
||||||
onReady(ctx, id, lm, {
|
onReady(ctx, id, lm, {
|
||||||
edPrivate: keyPair.secretKey,
|
edPrivate: keyPair.secretKey,
|
||||||
|
|||||||
@ -12,19 +12,18 @@
|
|||||||
.drive_main();
|
.drive_main();
|
||||||
.sidebar-layout_main();
|
.sidebar-layout_main();
|
||||||
|
|
||||||
.cp-app-team-container {
|
#cp-sidebarlayout-container {
|
||||||
flex: 1;
|
div#cp-sidebarlayout-rightside.cp-rightside-drive {
|
||||||
display: flex;
|
padding: 0;
|
||||||
width: 100%;
|
& > .cp-team-drive {
|
||||||
flex-flow: row;
|
display: flex;
|
||||||
.cp-app-team-drive {
|
height: 100%;
|
||||||
flex: 1;
|
margin: 0;
|
||||||
display: flex;
|
.cp-app-drive-container {
|
||||||
&.hidden {
|
height: 100%;
|
||||||
display: none;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,8 @@
|
|||||||
<body class="cp-app-team cp-body-drive">
|
<body class="cp-app-team cp-body-drive">
|
||||||
<div id="cp-toolbar" class="cp-toolbar-container"></div>
|
<div id="cp-toolbar" class="cp-toolbar-container"></div>
|
||||||
<div id="cp-sidebarlayout-container" class="cp-app-team-container">
|
<div id="cp-sidebarlayout-container" class="cp-app-team-container">
|
||||||
<!-- <div class="cp-app-team-drive">
|
<!--
|
||||||
|
<div class="cp-app-team-drive">
|
||||||
<div class="cp-app-drive-container" tabindex="0">
|
<div class="cp-app-drive-container" tabindex="0">
|
||||||
<div id="cp-app-drive-tree">
|
<div id="cp-app-drive-tree">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -83,16 +83,137 @@ define([
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
var teamCategories = {
|
var teamCategories = {
|
||||||
'back': [
|
'back': {
|
||||||
],
|
onClick: function (common) {
|
||||||
|
var sframeChan = common.getSframeChannel();
|
||||||
|
sframeChan.query('Q_SET_TEAM', null, function (err) {
|
||||||
|
if (err) { return void console.error(err); }
|
||||||
|
APP.buildUI(common);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
'drive': [
|
'drive': [
|
||||||
|
'cp-team-drive'
|
||||||
],
|
],
|
||||||
'members': [
|
'members': [
|
||||||
|
'cp-team-roster'
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
var create = {};
|
var create = {};
|
||||||
|
|
||||||
|
// Sidebar layout
|
||||||
|
|
||||||
|
var hideCategories = function () {
|
||||||
|
APP.$rightside.find('> div').hide();
|
||||||
|
};
|
||||||
|
var showCategories = function (cat) {
|
||||||
|
hideCategories();
|
||||||
|
cat.forEach(function (c) {
|
||||||
|
APP.$rightside.find('.'+c).show();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var createLeftSide = APP.createLeftSide = function (common, team) {
|
||||||
|
APP.$leftside.empty();
|
||||||
|
var $categories = $('<div>', {'class': 'cp-sidebarlayout-categories'})
|
||||||
|
.appendTo(APP.$leftside);
|
||||||
|
|
||||||
|
var categories = team ? teamCategories : mainCategories;
|
||||||
|
var active = team ? 'drive' : 'list';
|
||||||
|
|
||||||
|
Object.keys(categories).forEach(function (key) {
|
||||||
|
var $category = $('<div>', {'class': 'cp-sidebarlayout-category cp-team-cat-'+key}).appendTo($categories);
|
||||||
|
if (key === 'general') { $category.append($('<span>', {'class': 'fa fa-info-circle'})); }
|
||||||
|
if (key === 'list') { $category.append($('<span>', {'class': 'fa fa-list cp-team-cat-list'})); }
|
||||||
|
if (key === 'create') { $category.append($('<span>', {'class': 'fa fa-plus-circle'})); }
|
||||||
|
if (key === 'back') { $category.append($('<span>', {'class': 'fa fa-arrow-left'})); }
|
||||||
|
if (key === 'members') { $category.append($('<span>', {'class': 'fa fa-users'})); }
|
||||||
|
if (key === 'drive') { $category.append($('<span>', {'class': 'fa fa-hdd-o'})); }
|
||||||
|
|
||||||
|
if (key === active) {
|
||||||
|
$category.addClass('cp-leftside-active');
|
||||||
|
}
|
||||||
|
|
||||||
|
$category.click(function () {
|
||||||
|
if (!Array.isArray(categories[key]) && categories[key].onClick) {
|
||||||
|
categories[key].onClick(common);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (active === key) { return; }
|
||||||
|
active = key;
|
||||||
|
if (key === 'drive') {
|
||||||
|
APP.$rightside.addClass('cp-rightside-drive');
|
||||||
|
} else {
|
||||||
|
APP.$rightside.removeClass('cp-rightside-drive');
|
||||||
|
}
|
||||||
|
|
||||||
|
$categories.find('.cp-leftside-active').removeClass('cp-leftside-active');
|
||||||
|
$category.addClass('cp-leftside-active');
|
||||||
|
showCategories(categories[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$category.append(Messages['team_cat_'+key] || key); // XXX
|
||||||
|
});
|
||||||
|
if (active === 'drive') {
|
||||||
|
APP.$rightside.addClass('cp-rightside-drive');
|
||||||
|
}
|
||||||
|
showCategories(categories[active]);
|
||||||
|
};
|
||||||
|
|
||||||
|
var buildUI = APP.buildUI = function (common, team) {
|
||||||
|
var $rightside = APP.$rightside;
|
||||||
|
$rightside.empty();
|
||||||
|
var addItem = function (cssClass) {
|
||||||
|
var item = cssClass.slice(8);
|
||||||
|
if (typeof (create[item]) === "function") {
|
||||||
|
$rightside.append(create[item](common));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var categories = team ? teamCategories : mainCategories;
|
||||||
|
for (var cat in categories) {
|
||||||
|
if (!Array.isArray(categories[cat])) { continue; }
|
||||||
|
categories[cat].forEach(addItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
createLeftSide(common, team);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Team APP
|
||||||
|
|
||||||
|
var loadTeam = function (common, firstLoad) {
|
||||||
|
var sframeChan = common.getSframeChannel();
|
||||||
|
var proxy = {};
|
||||||
|
var folders = {};
|
||||||
|
if (firstLoad) {
|
||||||
|
buildUI(common, true);
|
||||||
|
}
|
||||||
|
nThen(function (waitFor) {
|
||||||
|
updateObject(sframeChan, proxy, waitFor(function () {
|
||||||
|
updateSharedFolders(sframeChan, null, proxy.drive, folders, waitFor());
|
||||||
|
}));
|
||||||
|
}).nThen(function () {
|
||||||
|
if (!proxy.drive || typeof(proxy.drive) !== 'object') {
|
||||||
|
throw new Error("Corrupted drive");
|
||||||
|
}
|
||||||
|
var drive = DriveUI.create(common, {
|
||||||
|
proxy: proxy,
|
||||||
|
folders: folders,
|
||||||
|
updateObject: updateObject,
|
||||||
|
updateSharedFolders: updateSharedFolders,
|
||||||
|
APP: driveAPP
|
||||||
|
});
|
||||||
|
driveAPP.refresh = drive.refresh;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var loadMain = function (common) {
|
||||||
|
buildUI(common);
|
||||||
|
UI.removeLoadingScreen();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Rightside elements
|
||||||
|
|
||||||
var makeBlock = function (key, getter) {
|
var makeBlock = function (key, getter) {
|
||||||
create[key] = function (common) {
|
create[key] = function (common) {
|
||||||
var $div = $('<div>', {'class': 'cp-team-' + key + ' cp-sidebarlayout-element'});
|
var $div = $('<div>', {'class': 'cp-team-' + key + ' cp-sidebarlayout-element'});
|
||||||
@ -111,6 +232,7 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
var refreshList = function (common, cb) {
|
var refreshList = function (common, cb) {
|
||||||
|
var sframeChan = common.getSframeChannel();
|
||||||
var content = [];
|
var content = [];
|
||||||
content.push(h('h3', 'Your teams'));
|
content.push(h('h3', 'Your teams'));
|
||||||
APP.module.execCommand('LIST_TEAMS', null, function (obj) {
|
APP.module.execCommand('LIST_TEAMS', null, function (obj) {
|
||||||
@ -126,7 +248,10 @@ define([
|
|||||||
h('li', a) // XXX
|
h('li', a) // XXX
|
||||||
])));
|
])));
|
||||||
$(a).click(function () {
|
$(a).click(function () {
|
||||||
console.log('okok'); // XXX
|
sframeChan.query('Q_SET_TEAM', id, function (err) {
|
||||||
|
if (err) { return void console.error(err); }
|
||||||
|
buildUI(common, true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
content.push(h('ul', lis));
|
content.push(h('ul', lis));
|
||||||
@ -174,101 +299,26 @@ define([
|
|||||||
cb(content);
|
cb(content);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sidebar layout
|
makeBlock('back', function (common, cb) {
|
||||||
|
refreshList(common, cb);
|
||||||
|
});
|
||||||
|
|
||||||
var hideCategories = function () {
|
makeBlock('drive', function (common, cb) {
|
||||||
APP.$rightside.find('> div').hide();
|
var $div = $('div.cp-team-drive').empty();
|
||||||
};
|
var content = [
|
||||||
var showCategories = function (cat) {
|
h('div.cp-app-drive-container', {tabindex:0}, [
|
||||||
hideCategories();
|
h('div#cp-app-drive-tree'),
|
||||||
cat.forEach(function (c) {
|
h('div#cp-app-drive-content-container', [
|
||||||
APP.$rightside.find('.'+c).show();
|
h('div#cp-app-drive-toolbar'),
|
||||||
});
|
h('div#cp-app-drive-content', {tabindex:2})
|
||||||
};
|
])
|
||||||
var createLeftside = function (team) {
|
])
|
||||||
APP.$leftside.empty();
|
];
|
||||||
var $categories = $('<div>', {'class': 'cp-sidebarlayout-categories'})
|
UI.addLoadingScreen();
|
||||||
.appendTo(APP.$leftside);
|
cb(content);
|
||||||
|
loadTeam(common, false);
|
||||||
|
});
|
||||||
|
|
||||||
var categories = team ? teamCategories : mainCategories;
|
|
||||||
var active = team ? 'drive' : 'general';
|
|
||||||
|
|
||||||
Object.keys(categories).forEach(function (key) {
|
|
||||||
var $category = $('<div>', {'class': 'cp-sidebarlayout-category cp-team-cat-'+key}).appendTo($categories);
|
|
||||||
if (key === 'general') { $category.append($('<span>', {'class': 'fa fa-info-circle'})); }
|
|
||||||
if (key === 'list') { $category.append($('<span>', {'class': 'fa fa-list cp-team-cat-list'})); }
|
|
||||||
if (key === 'create') { $category.append($('<span>', {'class': 'fa fa-plus-circle'})); }
|
|
||||||
if (key === 'back') { $category.append($('<span>', {'class': 'fa fa-arrow-left'})); }
|
|
||||||
if (key === 'members') { $category.append($('<span>', {'class': 'fa fa-users'})); }
|
|
||||||
if (key === 'drive') { $category.append($('<span>', {'class': 'fa fa-hdd-o'})); }
|
|
||||||
|
|
||||||
if (key === active) {
|
|
||||||
$category.addClass('cp-leftside-active');
|
|
||||||
}
|
|
||||||
|
|
||||||
$category.click(function () {
|
|
||||||
if (!Array.isArray(categories[key]) && categories[key].onClick) {
|
|
||||||
categories[key].onClick();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$categories.find('.cp-leftside-active').removeClass('cp-leftside-active');
|
|
||||||
$category.addClass('cp-leftside-active');
|
|
||||||
showCategories(categories[key]);
|
|
||||||
});
|
|
||||||
|
|
||||||
$category.append(Messages['team_cat_'+key] || key); // XXX
|
|
||||||
});
|
|
||||||
showCategories(categories[active]);
|
|
||||||
};
|
|
||||||
|
|
||||||
var buildUI = function (common, team) {
|
|
||||||
var $rightside = APP.$rightside;
|
|
||||||
$rightside.empty();
|
|
||||||
var addItem = function (cssClass) {
|
|
||||||
var item = cssClass.slice(8);
|
|
||||||
if (typeof (create[item]) === "function") {
|
|
||||||
$rightside.append(create[item](common));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var categories = team ? teamCategories : mainCategories;
|
|
||||||
for (var cat in categories) {
|
|
||||||
if (!Array.isArray(categories[cat])) { continue; }
|
|
||||||
categories[cat].forEach(addItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
createLeftside(team);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Team APP
|
|
||||||
|
|
||||||
var loadTeam = function (common) {
|
|
||||||
var sframeChan = common.getSframeChannel();
|
|
||||||
var proxy = {};
|
|
||||||
var folders = {};
|
|
||||||
nThen(function (waitFor) {
|
|
||||||
updateObject(sframeChan, proxy, waitFor(function () {
|
|
||||||
updateSharedFolders(sframeChan, null, proxy.drive, folders, waitFor());
|
|
||||||
}));
|
|
||||||
}).nThen(function () {
|
|
||||||
if (!proxy.drive || typeof(proxy.drive) !== 'object') {
|
|
||||||
throw new Error("Corrupted drive");
|
|
||||||
}
|
|
||||||
var drive = DriveUI.create(common, {
|
|
||||||
proxy: proxy,
|
|
||||||
folders: folders,
|
|
||||||
updateObject: updateObject,
|
|
||||||
updateSharedFolders: updateSharedFolders,
|
|
||||||
APP: driveAPP
|
|
||||||
});
|
|
||||||
driveAPP.refresh = drive.refresh;
|
|
||||||
});
|
|
||||||
buildUI(common, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
var loadMain = function (common) {
|
|
||||||
buildUI(common);
|
|
||||||
UI.removeLoadingScreen();
|
|
||||||
};
|
|
||||||
|
|
||||||
var onEvent = function (obj) {
|
var onEvent = function (obj) {
|
||||||
var ev = obj.ev;
|
var ev = obj.ev;
|
||||||
@ -351,7 +401,7 @@ define([
|
|||||||
|
|
||||||
$('body').css('display', '');
|
$('body').css('display', '');
|
||||||
if (privateData.teamId) {
|
if (privateData.teamId) {
|
||||||
loadTeam(common, privateData.teamId);
|
loadTeam(common, privateData.teamId, true);
|
||||||
} else {
|
} else {
|
||||||
loadMain(common);
|
loadMain(common);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,7 @@ define([
|
|||||||
var afterSecrets = function (Cryptpad, Utils, secret, cb) {
|
var afterSecrets = function (Cryptpad, Utils, secret, cb) {
|
||||||
var hash = window.location.hash.slice(1);
|
var hash = window.location.hash.slice(1);
|
||||||
if (hash && Utils.LocalStore.isLoggedIn()) {
|
if (hash && Utils.LocalStore.isLoggedIn()) {
|
||||||
|
return; // XXX How to add a shared folder?
|
||||||
// Add a shared folder!
|
// Add a shared folder!
|
||||||
Cryptpad.addSharedFolder(teamId, secret, function (id) {
|
Cryptpad.addSharedFolder(teamId, secret, function (id) {
|
||||||
window.CryptPad_newSharedFolder = id;
|
window.CryptPad_newSharedFolder = id;
|
||||||
@ -58,7 +59,13 @@ define([
|
|||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
var addRpc = function (sframeChan, Cryptpad, Utils) {
|
var addRpc = function (sframeChan, Cryptpad, Utils) {
|
||||||
|
sframeChan.on('Q_SET_TEAM', function (data, cb) {
|
||||||
|
teamId = data;
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
|
||||||
sframeChan.on('Q_DRIVE_USEROBJECT', function (data, cb) {
|
sframeChan.on('Q_DRIVE_USEROBJECT', function (data, cb) {
|
||||||
|
if (!teamId) { return void cb({error: 'EINVAL'}); }
|
||||||
data.teamId = teamId;
|
data.teamId = teamId;
|
||||||
Cryptpad.userObjectCommand(data, cb);
|
Cryptpad.userObjectCommand(data, cb);
|
||||||
});
|
});
|
||||||
@ -68,6 +75,7 @@ define([
|
|||||||
Cryptpad.restoreDrive(data, cb);
|
Cryptpad.restoreDrive(data, cb);
|
||||||
});*/
|
});*/
|
||||||
sframeChan.on('Q_DRIVE_GETOBJECT', function (data, cb) {
|
sframeChan.on('Q_DRIVE_GETOBJECT', function (data, cb) {
|
||||||
|
if (!teamId) { return void cb({error: 'EINVAL'}); }
|
||||||
if (data && data.sharedFolder) {
|
if (data && data.sharedFolder) {
|
||||||
Cryptpad.getSharedFolder({
|
Cryptpad.getSharedFolder({
|
||||||
teamId: teamId,
|
teamId: teamId,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user