Add team usage bar

This commit is contained in:
yflory 2019-09-23 15:45:24 +02:00
parent 17fbaea5d0
commit b1dab8e75a
8 changed files with 43 additions and 36 deletions

View file

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

View file

@ -223,8 +223,8 @@ define([
});
};
common.getPinnedUsage = function (cb) {
postMessage("GET_PINNED_USAGE", null, function (obj) {
common.getPinnedUsage = function (data, cb) {
postMessage("GET_PINNED_USAGE", data, function (obj) {
if (obj.error) { return void cb(obj.error); }
cb(null, obj.bytes);
});
@ -237,14 +237,14 @@ define([
});
};
common.getPinLimit = function (cb) {
postMessage("GET_PIN_LIMIT", null, function (obj) {
common.getPinLimit = function (data, cb) {
postMessage("GET_PIN_LIMIT", data, function (obj) {
if (obj.error) { return void cb(obj.error); }
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); }
var usage;
var andThen = function (e, limit, plan) {
@ -258,9 +258,13 @@ define([
var todo = function (e, used) {
if (e) { return void cb(e); }
usage = used;
common.getPinLimit(andThen);
common.getPinLimit({
teamId: teamId
}, andThen);
};
common.getPinnedUsage(todo);
common.getPinnedUsage({
teamId: teamId
}, todo);
};
common.clearOwnedChannel = function (channel, cb) {

View file

@ -227,10 +227,11 @@ define([
var account = {};
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) {
if (typeof(bytes) === 'number') {
s.rpc.getFileListSize(function (err, bytes) {
if (!s.id && typeof(bytes) === 'number') {
account.usage = bytes;
}
cb({bytes: bytes});
@ -250,18 +251,20 @@ define([
};
// Get current user limits
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;
if (ALWAYS_REVALIDATE || typeof(account.limit) !== 'number' ||
typeof(account.plan) !== '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}); }
account.limit = limit;
account.plan = plan;
account.note = note;
cb(account);
var data = s.id ? {} : account;
data.limit = limit;
data.plan = plan;
data.note = note;
cb(data);
});
}
cb(account);

View file

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

View file

@ -327,9 +327,9 @@ define([
if (cb) { cb(data); }
});
};
funcs.getPinUsage = function (cb) {
funcs.getPinUsage = function (teamId, cb) {
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);
});
};

View file

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

View file

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

View file

@ -213,6 +213,11 @@ define([
if (!proxy.drive || typeof(proxy.drive) !== 'object') {
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;
var drive = DriveUI.create(common, {
proxy: proxy,
@ -722,16 +727,6 @@ define([
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
var onEvent = function (obj) {
var ev = obj.ev;