Display a team drive

pull/1/head
yflory 5 years ago
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 {
padding: 0;
& > .cp-team-drive {
display: flex; display: flex;
width: 100%; height: 100%;
flex-flow: row; margin: 0;
.cp-app-team-drive { .cp-app-drive-container {
flex: 1; height: 100%;
display: flex; }
&.hidden {
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,97 +83,25 @@ 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 = {};
var makeBlock = function (key, getter) {
create[key] = function (common) {
var $div = $('<div>', {'class': 'cp-team-' + key + ' cp-sidebarlayout-element'});
getter(common, function (content) {
$div.append(content);
}, $div);
return $div;
};
};
makeBlock('info', function (common, cb) {
cb([
h('h3', 'Team application'), // XXX
h('p', 'From here you can ...') // XXX
]);
});
var refreshList = function (common, cb) {
var content = [];
content.push(h('h3', 'Your teams'));
APP.module.execCommand('LIST_TEAMS', null, function (obj) {
if (!obj) { return; }
if (obj.error) { return void console.error(obj.error); }
var lis = [];
Object.keys(obj).forEach(function (id) {
var team = obj[id];
var a = h('a', 'Open');
lis.push(h('li', h('ul', [
h('li', 'Name: ' + team.name), // XXX
h('li', 'ID: ' + id), // XXX
h('li', a) // XXX
])));
$(a).click(function () {
console.log('okok'); // XXX
});
});
content.push(h('ul', lis));
cb(content);
});
return content;
};
makeBlock('list', function (common, cb) {
refreshList(common, cb);
});
makeBlock('create', function (common, cb) {
var content = [];
content.push(h('h3', 'Create a team')); // XXX
content.push(h('label', 'Team name')); // XXX
var input = h('input', {type:'text'});
content.push(input);
var button = h('button.btn.btn-success', 'Create'); // XXX
content.push(h('br'));
content.push(h('br'));
content.push(button);
var state = false;
$(button).click(function () {
if (state) { return; }
var name = $(input).val();
if (!name.trim()) { return; }
state = true;
UI.confirm('Are you sure?', function (yes) {
if (!yes) {
state = false;
return;
}
APP.module.execCommand('CREATE_TEAM', {
name: name
}, function () {
var $div = $('div.cp-team-list').empty();
refreshList(common, function (content) {
state = false;
$div.append(content);
$('div.cp-team-cat-list').click();
});
});
});
});
cb(content);
});
// Sidebar layout // Sidebar layout
var hideCategories = function () { var hideCategories = function () {
@ -185,13 +113,13 @@ define([
APP.$rightside.find('.'+c).show(); APP.$rightside.find('.'+c).show();
}); });
}; };
var createLeftside = function (team) { var createLeftSide = APP.createLeftSide = function (common, team) {
APP.$leftside.empty(); APP.$leftside.empty();
var $categories = $('<div>', {'class': 'cp-sidebarlayout-categories'}) var $categories = $('<div>', {'class': 'cp-sidebarlayout-categories'})
.appendTo(APP.$leftside); .appendTo(APP.$leftside);
var categories = team ? teamCategories : mainCategories; var categories = team ? teamCategories : mainCategories;
var active = team ? 'drive' : 'general'; var active = team ? 'drive' : 'list';
Object.keys(categories).forEach(function (key) { Object.keys(categories).forEach(function (key) {
var $category = $('<div>', {'class': 'cp-sidebarlayout-category cp-team-cat-'+key}).appendTo($categories); var $category = $('<div>', {'class': 'cp-sidebarlayout-category cp-team-cat-'+key}).appendTo($categories);
@ -208,9 +136,17 @@ define([
$category.click(function () { $category.click(function () {
if (!Array.isArray(categories[key]) && categories[key].onClick) { if (!Array.isArray(categories[key]) && categories[key].onClick) {
categories[key].onClick(); categories[key].onClick(common);
return; 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'); $categories.find('.cp-leftside-active').removeClass('cp-leftside-active');
$category.addClass('cp-leftside-active'); $category.addClass('cp-leftside-active');
showCategories(categories[key]); showCategories(categories[key]);
@ -218,10 +154,13 @@ define([
$category.append(Messages['team_cat_'+key] || key); // XXX $category.append(Messages['team_cat_'+key] || key); // XXX
}); });
if (active === 'drive') {
APP.$rightside.addClass('cp-rightside-drive');
}
showCategories(categories[active]); showCategories(categories[active]);
}; };
var buildUI = function (common, team) { var buildUI = APP.buildUI = function (common, team) {
var $rightside = APP.$rightside; var $rightside = APP.$rightside;
$rightside.empty(); $rightside.empty();
var addItem = function (cssClass) { var addItem = function (cssClass) {
@ -236,15 +175,18 @@ define([
categories[cat].forEach(addItem); categories[cat].forEach(addItem);
} }
createLeftside(team); createLeftSide(common, team);
}; };
// Team APP // Team APP
var loadTeam = function (common) { var loadTeam = function (common, firstLoad) {
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
var proxy = {}; var proxy = {};
var folders = {}; var folders = {};
if (firstLoad) {
buildUI(common, true);
}
nThen(function (waitFor) { nThen(function (waitFor) {
updateObject(sframeChan, proxy, waitFor(function () { updateObject(sframeChan, proxy, waitFor(function () {
updateSharedFolders(sframeChan, null, proxy.drive, folders, waitFor()); updateSharedFolders(sframeChan, null, proxy.drive, folders, waitFor());
@ -262,7 +204,6 @@ define([
}); });
driveAPP.refresh = drive.refresh; driveAPP.refresh = drive.refresh;
}); });
buildUI(common, true);
}; };
var loadMain = function (common) { var loadMain = function (common) {
@ -270,6 +211,115 @@ define([
UI.removeLoadingScreen(); UI.removeLoadingScreen();
}; };
// Rightside elements
var makeBlock = function (key, getter) {
create[key] = function (common) {
var $div = $('<div>', {'class': 'cp-team-' + key + ' cp-sidebarlayout-element'});
getter(common, function (content) {
$div.append(content);
}, $div);
return $div;
};
};
makeBlock('info', function (common, cb) {
cb([
h('h3', 'Team application'), // XXX
h('p', 'From here you can ...') // XXX
]);
});
var refreshList = function (common, cb) {
var sframeChan = common.getSframeChannel();
var content = [];
content.push(h('h3', 'Your teams'));
APP.module.execCommand('LIST_TEAMS', null, function (obj) {
if (!obj) { return; }
if (obj.error) { return void console.error(obj.error); }
var lis = [];
Object.keys(obj).forEach(function (id) {
var team = obj[id];
var a = h('a', 'Open');
lis.push(h('li', h('ul', [
h('li', 'Name: ' + team.name), // XXX
h('li', 'ID: ' + id), // XXX
h('li', a) // XXX
])));
$(a).click(function () {
sframeChan.query('Q_SET_TEAM', id, function (err) {
if (err) { return void console.error(err); }
buildUI(common, true);
});
});
});
content.push(h('ul', lis));
cb(content);
});
return content;
};
makeBlock('list', function (common, cb) {
refreshList(common, cb);
});
makeBlock('create', function (common, cb) {
var content = [];
content.push(h('h3', 'Create a team')); // XXX
content.push(h('label', 'Team name')); // XXX
var input = h('input', {type:'text'});
content.push(input);
var button = h('button.btn.btn-success', 'Create'); // XXX
content.push(h('br'));
content.push(h('br'));
content.push(button);
var state = false;
$(button).click(function () {
if (state) { return; }
var name = $(input).val();
if (!name.trim()) { return; }
state = true;
UI.confirm('Are you sure?', function (yes) {
if (!yes) {
state = false;
return;
}
APP.module.execCommand('CREATE_TEAM', {
name: name
}, function () {
var $div = $('div.cp-team-list').empty();
refreshList(common, function (content) {
state = false;
$div.append(content);
$('div.cp-team-cat-list').click();
});
});
});
});
cb(content);
});
makeBlock('back', function (common, cb) {
refreshList(common, cb);
});
makeBlock('drive', function (common, cb) {
var $div = $('div.cp-team-drive').empty();
var content = [
h('div.cp-app-drive-container', {tabindex:0}, [
h('div#cp-app-drive-tree'),
h('div#cp-app-drive-content-container', [
h('div#cp-app-drive-toolbar'),
h('div#cp-app-drive-content', {tabindex:2})
])
])
];
UI.addLoadingScreen();
cb(content);
loadTeam(common, false);
});
var onEvent = function (obj) { var onEvent = function (obj) {
var ev = obj.ev; var ev = obj.ev;
var data = obj.data; var data = obj.data;
@ -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…
Cancel
Save