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) {
if (e) { return void cb(e); }
team.rpc = call;
cb();
// XXX get pin limit?
});
});
@ -159,7 +160,6 @@ define([
});
}
delete ctx.onReadyHandlers[id];
console.log(cb);
cb();
});
@ -171,7 +171,7 @@ define([
var cfg = {
data: {},
readOnly: Boolean(secret.keys.signKey),
readOnly: !Boolean(secret.keys.signKey),
network: ctx.store.network,
channel: secret.channel,
crypto: crypto,
@ -192,15 +192,13 @@ define([
var createTeam = function (ctx, data, cId, _cb) {
var cb = Util.once(_cb);
console.log(data);
var password = Hash.createChannelId();
var hash = Hash.createRandomHash('team', password);
var secret = Hash.getSecrets('team', hash, password);
var keyPair = Nacl.sign.keyPair(); // keyPair.secretKey , keyPair.publicKey
var membersSecret = Hash.getSecrets('members');
var membersHashes = Hash.getHashes(secret);
var membersHashes = Hash.getHashes(membersSecret);
var config = {
network: ctx.store.network,
@ -231,8 +229,8 @@ console.log(data);
// Store keys in our drive
var id = Util.createRandomInteger();
var keys = {
edPrivate: keyPair.secretKey,
edPublic: keyPair.publicKey
edPrivate: Nacl.util.encodeBase64(keyPair.secretKey),
edPublic: Nacl.util.encodeBase64(keyPair.publicKey)
};
ctx.store.proxy.teams[id] = {
hash: hash,
@ -249,7 +247,7 @@ console.log(data);
members: membersHashes.viewHash,
};
// Add rpc key
proxy.edPublic = keyPair.publicKey;
proxy.edPublic = Nacl.util.encodeBase64(keyPair.publicKey);
onReady(ctx, id, lm, {
edPrivate: keyPair.secretKey,

@ -12,19 +12,18 @@
.drive_main();
.sidebar-layout_main();
.cp-app-team-container {
flex: 1;
#cp-sidebarlayout-container {
div#cp-sidebarlayout-rightside.cp-rightside-drive {
padding: 0;
& > .cp-team-drive {
display: flex;
width: 100%;
flex-flow: row;
.cp-app-team-drive {
flex: 1;
display: flex;
&.hidden {
display: none;
height: 100%;
margin: 0;
.cp-app-drive-container {
height: 100%;
}
}
}
}
}

@ -12,7 +12,8 @@
<body class="cp-app-team cp-body-drive">
<div id="cp-toolbar" class="cp-toolbar-container"></div>
<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 id="cp-app-drive-tree">
</div>

@ -83,97 +83,25 @@ define([
],
};
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': [
'cp-team-drive'
],
'members': [
'cp-team-roster'
],
};
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
var hideCategories = function () {
@ -185,13 +113,13 @@ define([
APP.$rightside.find('.'+c).show();
});
};
var createLeftside = function (team) {
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' : 'general';
var active = team ? 'drive' : 'list';
Object.keys(categories).forEach(function (key) {
var $category = $('<div>', {'class': 'cp-sidebarlayout-category cp-team-cat-'+key}).appendTo($categories);
@ -208,9 +136,17 @@ define([
$category.click(function () {
if (!Array.isArray(categories[key]) && categories[key].onClick) {
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]);
@ -218,10 +154,13 @@ define([
$category.append(Messages['team_cat_'+key] || key); // XXX
});
if (active === 'drive') {
APP.$rightside.addClass('cp-rightside-drive');
}
showCategories(categories[active]);
};
var buildUI = function (common, team) {
var buildUI = APP.buildUI = function (common, team) {
var $rightside = APP.$rightside;
$rightside.empty();
var addItem = function (cssClass) {
@ -236,15 +175,18 @@ define([
categories[cat].forEach(addItem);
}
createLeftside(team);
createLeftSide(common, team);
};
// Team APP
var loadTeam = function (common) {
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());
@ -262,7 +204,6 @@ define([
});
driveAPP.refresh = drive.refresh;
});
buildUI(common, true);
};
var loadMain = function (common) {
@ -270,6 +211,115 @@ define([
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 ev = obj.ev;
var data = obj.data;
@ -351,7 +401,7 @@ define([
$('body').css('display', '');
if (privateData.teamId) {
loadTeam(common, privateData.teamId);
loadTeam(common, privateData.teamId, true);
} else {
loadMain(common);
}

@ -40,6 +40,7 @@ define([
var afterSecrets = function (Cryptpad, Utils, secret, cb) {
var hash = window.location.hash.slice(1);
if (hash && Utils.LocalStore.isLoggedIn()) {
return; // XXX How to add a shared folder?
// Add a shared folder!
Cryptpad.addSharedFolder(teamId, secret, function (id) {
window.CryptPad_newSharedFolder = id;
@ -58,7 +59,13 @@ define([
cb();
};
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) {
if (!teamId) { return void cb({error: 'EINVAL'}); }
data.teamId = teamId;
Cryptpad.userObjectCommand(data, cb);
});
@ -68,6 +75,7 @@ define([
Cryptpad.restoreDrive(data, cb);
});*/
sframeChan.on('Q_DRIVE_GETOBJECT', function (data, cb) {
if (!teamId) { return void cb({error: 'EINVAL'}); }
if (data && data.sharedFolder) {
Cryptpad.getSharedFolder({
teamId: teamId,

Loading…
Cancel
Save