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

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

Loading…
Cancel
Save