Add team usage bar

pull/1/head
yflory 5 years ago
parent 17fbaea5d0
commit b1dab8e75a

@ -2079,7 +2079,7 @@ define([
*/ */
// NOTE: The callback must stay SYNCHRONOUS // NOTE: The callback must stay SYNCHRONOUS
var LIMIT_REFRESH_RATE = 30000; // milliseconds var LIMIT_REFRESH_RATE = 30000; // milliseconds
UIElements.createUsageBar = function (common, cb) { UIElements.createUsageBar = function (common, teamId, cb) {
if (AppConfig.hideUsageBar) { return cb('USAGE_BAR_HIDDEN'); } if (AppConfig.hideUsageBar) { return cb('USAGE_BAR_HIDDEN'); }
if (!common.isLoggedIn()) { return cb("NOT_LOGGED_IN"); } if (!common.isLoggedIn()) { return cb("NOT_LOGGED_IN"); }
// getPinnedUsage updates common.account.usage, and other values // getPinnedUsage updates common.account.usage, and other values
@ -2161,15 +2161,20 @@ define([
}; };
var updateUsage = Util.notAgainForAnother(function () { var updateUsage = Util.notAgainForAnother(function () {
common.getPinUsage(todo); common.getPinUsage(teamId, todo);
}, LIMIT_REFRESH_RATE); }, LIMIT_REFRESH_RATE);
setInterval(function () { var interval = setInterval(function () {
updateUsage(); updateUsage();
}, LIMIT_REFRESH_RATE * 3); }, LIMIT_REFRESH_RATE * 3);
updateUsage(); updateUsage();
cb(null, $container); cb(null, $container);
return {
stop: function () {
clearInterval(interval);
}
};
}; };
// Create a button with a dropdown menu // Create a button with a dropdown menu

@ -223,8 +223,8 @@ define([
}); });
}; };
common.getPinnedUsage = function (cb) { common.getPinnedUsage = function (data, cb) {
postMessage("GET_PINNED_USAGE", null, function (obj) { postMessage("GET_PINNED_USAGE", data, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj.error) { return void cb(obj.error); }
cb(null, obj.bytes); cb(null, obj.bytes);
}); });
@ -237,14 +237,14 @@ define([
}); });
}; };
common.getPinLimit = function (cb) { common.getPinLimit = function (data, cb) {
postMessage("GET_PIN_LIMIT", null, function (obj) { postMessage("GET_PIN_LIMIT", data, function (obj) {
if (obj.error) { return void cb(obj.error); } if (obj.error) { return void cb(obj.error); }
cb(undefined, obj.limit, obj.plan, obj.note); cb(undefined, obj.limit, obj.plan, obj.note);
}); });
}; };
common.isOverPinLimit = function (cb) { common.isOverPinLimit = function (teamId, cb) {
if (!LocalStore.isLoggedIn()) { return void cb(null, false); } if (!LocalStore.isLoggedIn()) { return void cb(null, false); }
var usage; var usage;
var andThen = function (e, limit, plan) { var andThen = function (e, limit, plan) {
@ -258,9 +258,13 @@ define([
var todo = function (e, used) { var todo = function (e, used) {
if (e) { return void cb(e); } if (e) { return void cb(e); }
usage = used; usage = used;
common.getPinLimit(andThen); common.getPinLimit({
teamId: teamId
}, andThen);
}; };
common.getPinnedUsage(todo); common.getPinnedUsage({
teamId: teamId
}, todo);
}; };
common.clearOwnedChannel = function (channel, cb) { common.clearOwnedChannel = function (channel, cb) {

@ -227,10 +227,11 @@ define([
var account = {}; var account = {};
Store.getPinnedUsage = function (clientId, data, cb) { Store.getPinnedUsage = function (clientId, data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } var s = getStore(data && data.teamId);
if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.getFileListSize(function (err, bytes) { s.rpc.getFileListSize(function (err, bytes) {
if (typeof(bytes) === 'number') { if (!s.id && typeof(bytes) === 'number') {
account.usage = bytes; account.usage = bytes;
} }
cb({bytes: bytes}); cb({bytes: bytes});
@ -250,18 +251,20 @@ define([
}; };
// Get current user limits // Get current user limits
Store.getPinLimit = function (clientId, data, cb) { Store.getPinLimit = function (clientId, data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } var s = getStore(data && data.teamId);
if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
var ALWAYS_REVALIDATE = true; var ALWAYS_REVALIDATE = true;
if (ALWAYS_REVALIDATE || typeof(account.limit) !== 'number' || if (ALWAYS_REVALIDATE || typeof(account.limit) !== 'number' ||
typeof(account.plan) !== 'string' || typeof(account.plan) !== 'string' ||
typeof(account.note) !== 'string') { typeof(account.note) !== 'string') {
return void store.rpc.getLimit(function (e, limit, plan, note) { return void s.rpc.getLimit(function (e, limit, plan, note) {
if (e) { return void cb({error: e}); } if (e) { return void cb({error: e}); }
account.limit = limit; var data = s.id ? {} : account;
account.plan = plan; data.limit = limit;
account.note = note; data.plan = plan;
cb(account); data.note = note;
cb(data);
}); });
} }
cb(account); cb(account);

@ -378,7 +378,7 @@ define([
}); });
sframeChan.on('Q_GET_PIN_LIMIT_STATUS', function (data, cb) { sframeChan.on('Q_GET_PIN_LIMIT_STATUS', function (data, cb) {
Cryptpad.isOverPinLimit(function (e, overLimit, limits) { Cryptpad.isOverPinLimit(null, function (e, overLimit, limits) {
cb({ cb({
error: e, error: e,
overLimit: overLimit, overLimit: overLimit,
@ -905,8 +905,8 @@ define([
} }
}); });
sframeChan.on('Q_PIN_GET_USAGE', function (data, cb) { sframeChan.on('Q_PIN_GET_USAGE', function (teamId, cb) {
Cryptpad.isOverPinLimit(function (err, overLimit, data) { Cryptpad.isOverPinLimit(teamId, function (err, overLimit, data) {
cb({ cb({
error: err, error: err,
data: data data: data

@ -327,9 +327,9 @@ define([
if (cb) { cb(data); } if (cb) { cb(data); }
}); });
}; };
funcs.getPinUsage = function (cb) { funcs.getPinUsage = function (teamId, cb) {
cb = cb || $.noop; cb = cb || $.noop;
ctx.sframeChan.query('Q_PIN_GET_USAGE', null, function (err, data) { ctx.sframeChan.query('Q_PIN_GET_USAGE', teamId, function (err, data) {
cb(err || data.error, data.data); cb(err || data.error, data.data);
}); });
}; };

@ -160,7 +160,7 @@ define([
/* add the usage */ /* add the usage */
if (APP.loggedIn) { if (APP.loggedIn) {
common.createUsageBar(function (err, $limitContainer) { common.createUsageBar(null, function (err, $limitContainer) {
if (err) { return void DriveUI.logError(err); } if (err) { return void DriveUI.logError(err); }
APP.$limit = $limitContainer; APP.$limit = $limitContainer;
}, true); }, true);

@ -1519,7 +1519,7 @@ define([
// Settings app // Settings app
var createUsageButton = function () { var createUsageButton = function () {
common.createUsageBar(function (err, $bar) { common.createUsageBar(null, function (err, $bar) {
if (err) { return void console.error(err); } if (err) { return void console.error(err); }
APP.$usage.html('').append($bar); APP.$usage.html('').append($bar);
}, true); }, true);

@ -213,6 +213,11 @@ define([
if (!proxy.drive || typeof(proxy.drive) !== 'object') { if (!proxy.drive || typeof(proxy.drive) !== 'object') {
throw new Error("Corrupted drive"); throw new Error("Corrupted drive");
} }
if (APP.usageBar) { APP.usageBar.stop(); }
APP.usageBar = common.createUsageBar(APP.team, function (err, $limitContainer) {
if (err) { return void DriveUI.logError(err); }
driveAPP.$limit = $limitContainer;
}, true);
driveAPP.team = id; driveAPP.team = id;
var drive = DriveUI.create(common, { var drive = DriveUI.create(common, {
proxy: proxy, proxy: proxy,
@ -722,16 +727,6 @@ define([
driveAPP.$displayName.text(name); driveAPP.$displayName.text(name);
}); });
/* add the usage */
// XXX Teams
if (false) {
// Synchronous callback...
common.createUsageBar(function (err, $limitContainer) {
if (err) { return void DriveUI.logError(err); }
driveAPP.$limit = $limitContainer;
}, true);
}
// Load the Team module // Load the Team module
var onEvent = function (obj) { var onEvent = function (obj) {
var ev = obj.ev; var ev = obj.ev;

Loading…
Cancel
Save