Add comments and improve trim history warnings

pull/1/head
yflory 5 years ago
parent 53f19920f0
commit 5ead391706

@ -12,7 +12,10 @@ define([
var edPublic = Util.find(ctx.store, ['proxy', 'edPublic']);
// Drive
channels.push(ctx.store.driveChannel);
var driveOwned = (Util.find(ctx.store, ['driveMetadata', 'owners']) || []).indexOf(edpublic) !== -1;
if (driveOwned) {
channels.push(ctx.store.driveChannel);
}
// Profile
var profile = ctx.store.proxy.profile;
@ -56,13 +59,14 @@ define([
var channels = data.channels;
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
var warning = [];
// If account trim history, get the correct channels here
if (data.account) {
channels = getAccountChannels(ctx);
}
var size = 0;
var warning = false;
nThen(function (waitFor) {
// TODO: check if owner first?
channels.forEach(function (chan) {
@ -79,7 +83,7 @@ define([
lastKnownHash: lastKnownHash
}, waitFor(function (err, value) {
if (err) {
warning = true;
warning.push(err);
return;
}
size += value;
@ -88,7 +92,7 @@ define([
});
}).nThen(function () {
cb({
warning: warning,
warning: warning.length ? warning : undefined,
size: size
});
});
@ -99,28 +103,33 @@ define([
var channels = data.channels;
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
var warning = [];
// If account trim history, get the correct channels here
if (data.account) {
channels = getAccountChannels(ctx);
}
var warning = false;
nThen(function (waitFor) {
channels.forEach(function (chan) {
/*
ctx.store.rpc.trimHistory(chan, waitFor(function (err) {
if (err) {
warning = err;
chanWarning = true;
warning.push(err);
return;
}
}));
*/ // XXX TODO
});
}).nThen(function () {
if (channels.length === 1 && warning) {
// Only one channel and warning: error
if (channels.length === 1 && warning.length) {
return void cb({error: err});
}
cb({ warning: warning });
cb({
warning: warning.length ? warning : undefined
});
});
};

@ -1200,8 +1200,10 @@ define([
makeBlock('trim-history', function (cb) {
if (!common.isLoggedIn()) { return; }
// XXX settings_trimHistoryTitle, settings_trimHistoryHint, settings_trimHistoryButton, settings_trimHistoryError
// XXX trimHistory_confirm
// XXX settings_trimHistoryTitle, settings_trimHistoryHint, settings_trimHistoryButton, trimHistoryError
// XXX trimHistorySuccess, trimHistory_confirm
if (!privateData.isDriveOwned) { return; } // XXX
var spinner = UI.makeSpinner();
var button = h('button.btn.btn-danger-alt', {
@ -1226,8 +1228,9 @@ define([
}, waitFor(function (obj) {
if (obj && obj.error) {
waitFor.abort();
var error = h('div.alert.alert-danger', Messages.settings_trimHistoryError || 'error'); // XXX
var error = h('div.alert.alert-danger', Messages.trimHistoryError || 'error'); // XXX
$(content).empty().append(error);
// TODO: obj.warning?
return;
}
size = UIElements.prettySize(Number(obj.size));
@ -1248,8 +1251,9 @@ define([
// XXX what are the possible errors?
return;
}
// TODO: obj.warning?
spinner.hide();
$(content).append(h('div.alert.alert-success', Messages.settings_trimHistorySuccess || 'ok')); // XXX
$(content).append(h('div.alert.alert-success', Messages.trimHistorySuccess || 'ok')); // XXX
});
});
}).prop('disabled', '');

Loading…
Cancel
Save