Add history trim in the properties modal
parent
5ead391706
commit
4ac2f64726
|
@ -26,6 +26,42 @@
|
|||
// Properties modal
|
||||
.cp-app-prop {
|
||||
margin-bottom: 10px;
|
||||
.cp-app-prop-size-container {
|
||||
height: 20px;
|
||||
background-color: @colortheme_logo-2;
|
||||
margin: 10px 0;
|
||||
padding: 0;
|
||||
div {
|
||||
height: 20px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #CCCCCC;
|
||||
}
|
||||
}
|
||||
.cp-app-prop-size-legend {
|
||||
color: @colortheme_modal-fg;
|
||||
display: flex;
|
||||
margin: 10px 0;
|
||||
& > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-basis: 50%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.cp-app-prop-history-size-color, .cp-app-prop-contents-size-color {
|
||||
display: inline-block;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.cp-app-prop-history-size-color {
|
||||
background-color: #CCCCCC;
|
||||
}
|
||||
.cp-app-prop-contents-size-color {
|
||||
background-color: @colortheme_logo-2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cp-app-prop-content {
|
||||
|
|
|
@ -689,6 +689,9 @@ define([
|
|||
var $d = $('<div>');
|
||||
if (!data) { return void cb(void 0, $d); }
|
||||
|
||||
var priv = common.getMetadataMgr().getPrivateData();
|
||||
var edPublic = priv.edPublic;
|
||||
|
||||
if (data.href) {
|
||||
$('<label>', {'for': 'cp-app-prop-link'}).text(Messages.editShare).appendTo($d);
|
||||
$d.append(UI.dialog.selectable(data.href, {
|
||||
|
@ -715,13 +718,29 @@ define([
|
|||
$d.append(h('div.cp-app-prop', [Messages.fm_lastAccess, h('br'), h('span.cp-app-prop-content', new Date(data.atime).toLocaleString())]));
|
||||
}
|
||||
|
||||
var owned = false;
|
||||
if (common.isLoggedIn()) {
|
||||
if (Array.isArray(data.owners)) {
|
||||
if (data.owners.indexOf(edPublic) !== -1) {
|
||||
owned = true;
|
||||
} else {
|
||||
Object.keys(priv.teams || {}).some(function (id) {
|
||||
var team = priv.teams[id] || {};
|
||||
if (team.viewer) { return; }
|
||||
if (data.owners.indexOf(team.edPublic) === -1) { return; }
|
||||
owned = id;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
// check the size of this file...
|
||||
var bytes = 0;
|
||||
var historyBytes;
|
||||
var chan = [data.channel];
|
||||
if (data.rtChannel) { chan.push(data.rtChannel); }
|
||||
if (data.lastVersion) { chan.push(Hash.hrefToHexChannelId(data.lastVersion)); }
|
||||
var history = common.makeUniversal('history');
|
||||
NThen(function (waitFor) {
|
||||
var chan = [data.channel];
|
||||
if (data.rtChannel) { chan.push(data.rtChannel); }
|
||||
if (data.lastVersion) { chan.push(Hash.hrefToHexChannelId(data.lastVersion)); }
|
||||
chan.forEach(function (c) {
|
||||
common.getFileSize(c, waitFor(function (e, _bytes) {
|
||||
if (e) {
|
||||
|
@ -731,20 +750,79 @@ define([
|
|||
bytes += _bytes;
|
||||
}));
|
||||
});
|
||||
|
||||
if (!owned) { return; }
|
||||
history.execCommand('GET_HISTORY_SIZE', {
|
||||
pad: true,
|
||||
channels: chan.filter(function (c) { return c.length === 32; }),
|
||||
teamId: typeof(owned) === "number" && owned
|
||||
}, waitFor(function (obj) {
|
||||
if (obj && obj.error) { return; }
|
||||
historyBytes = obj.size;
|
||||
}));
|
||||
}).nThen(function () {
|
||||
if (bytes === 0) { return void cb(void 0, $d); }
|
||||
var KB = Util.bytesToKilobytes(bytes);
|
||||
var formatted = UIElements.prettySize(bytes);
|
||||
|
||||
var formatted = Messages._getKey('formattedKB', [KB]);
|
||||
$d.append(h('div.cp-app-prop', [Messages.upload_size, h('br'), h('span.cp-app-prop-content', formatted)]));
|
||||
historyBytes = Math.floor(0.2*bytes); // XXX test data
|
||||
|
||||
if (data.sharedFolder && false) {
|
||||
$('<label>', {'for': 'cp-app-prop-channel'}).text('Channel ID').appendTo($d);
|
||||
if (AppConfig.pinBugRecovery) { $d.append(h('p', AppConfig.pinBugRecovery)); }
|
||||
$d.append(UI.dialog.selectable(data.channel, {
|
||||
id: 'cp-app-prop-link',
|
||||
}));
|
||||
}
|
||||
if (!owned || !historyBytes || historyBytes > bytes) {
|
||||
$d.append(h('div.cp-app-prop', [Messages.upload_size, h('br'), h('span.cp-app-prop-content', formatted)]));
|
||||
return void cb(void 0, $d);
|
||||
}
|
||||
|
||||
Messages.historyTrim_historySize = 'History: {0}'; // XXX
|
||||
Messages.historyTrim_contentsSize = 'Contents: {0}'; // XXX
|
||||
|
||||
var p = Math.round((historyBytes / bytes) * 100);
|
||||
var historyPrettySize = UIElements.prettySize(historyBytes);
|
||||
var contentsPrettySize = UIElements.prettySize(bytes - historyBytes);
|
||||
var button;
|
||||
var spinner = UI.makeSpinner();
|
||||
var size = h('div.cp-app-prop', [
|
||||
Messages.upload_size,
|
||||
h('br'),
|
||||
h('div.cp-app-prop-size-container', [
|
||||
h('div.cp-app-prop-size-history', { style: 'width:'+p+'%;' })
|
||||
]),
|
||||
h('div.cp-app-prop-size-legend', [
|
||||
h('div.cp-app-prop-history-size', [
|
||||
h('span.cp-app-prop-history-size-color'),
|
||||
h('span.cp-app-prop-content', Messages._getKey('historyTrim_historySize', [historyPrettySize]))
|
||||
]),
|
||||
h('div.cp-app-prop-contents-size', [
|
||||
h('span.cp-app-prop-contents-size-color'),
|
||||
h('span.cp-app-prop-content', Messages._getKey('historyTrim_contentsSize', [contentsPrettySize]))
|
||||
]),
|
||||
]),
|
||||
button = h('button.btn.btn-danger-alt.no-margin', Messages.trimHistory_button || 'test'), // XXX
|
||||
spinner.spinner
|
||||
]);
|
||||
$d.append(size);
|
||||
|
||||
var $button = $(button);
|
||||
$button.click(function () {
|
||||
UI.confirm(Messages.trimHistory_confirm, function (yes) {
|
||||
if (!yes) { return; }
|
||||
|
||||
$button.remove();
|
||||
spinner.spin();
|
||||
history.execCommand('TRIM_HISTORY', {
|
||||
pad: true,
|
||||
channels: chan.filter(function (c) { return c.length === 32; }),
|
||||
teamId: typeof(owned) === "number" && owned
|
||||
}, function (obj) {
|
||||
if (obj && obj.error) {
|
||||
console.error(obj.error);
|
||||
// XXX what are the possible errors?
|
||||
return;
|
||||
}
|
||||
// TODO: obj.warning?
|
||||
spinner.hide();
|
||||
$(size).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
cb(void 0, $d);
|
||||
});
|
||||
|
|
|
@ -39,7 +39,6 @@ define([
|
|||
// Shared folders owned by me
|
||||
var sf = ctx.store.proxy[UserObject.SHARED_FOLDERS];
|
||||
if (sf) {
|
||||
console.log(sf);
|
||||
var sfChannels = Object.keys(sf).map(function (fId) {
|
||||
var data = sf[fId];
|
||||
if (!data || !data.owners) { return; }
|
||||
|
@ -47,18 +46,29 @@ define([
|
|||
if (!isOwner) { return; }
|
||||
return data.channel;
|
||||
}).filter(Boolean);
|
||||
console.log(sfChannels);
|
||||
Array.prototype.push.apply(channels, sfChannels);
|
||||
}
|
||||
|
||||
return channels;
|
||||
};
|
||||
|
||||
var getRpc = function (ctx, teamId) {
|
||||
if (!teamId) { return ctx.store.rpc; }
|
||||
var teams = ctx.store.modules['team'];
|
||||
if (!teams) { return; }
|
||||
var team = teams.getTeam(teamId);
|
||||
if (!team) { return; }
|
||||
return team.rpc;
|
||||
};
|
||||
|
||||
commands.GET_HISTORY_SIZE = function (ctx, data, cId, cb) {
|
||||
if (!ctx.store.loggedIn || !ctx.store.rpc) { return void cb({ error: 'INSUFFICIENT_PERMISSIONS' }); }
|
||||
var channels = data.channels;
|
||||
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
|
||||
|
||||
var rpc = getRpc(ctx, data.teamid);
|
||||
if (!rpc) { return void cb({ error: 'ENORPC'}); }
|
||||
|
||||
var warning = [];
|
||||
|
||||
// If account trim history, get the correct channels here
|
||||
|
@ -78,7 +88,7 @@ define([
|
|||
channel = chan.channel;
|
||||
lastKnownHash = chan.lastKnownHash;
|
||||
}
|
||||
ctx.store.rpc.getHistorySize({
|
||||
rpc.getHistorySize({
|
||||
channel: channel,
|
||||
lastKnownHash: lastKnownHash
|
||||
}, waitFor(function (err, value) {
|
||||
|
@ -103,6 +113,9 @@ define([
|
|||
var channels = data.channels;
|
||||
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
|
||||
|
||||
var rpc = getRpc(ctx, data.teamid);
|
||||
if (!rpc) { return void cb({ error: 'ENORPC'}); }
|
||||
|
||||
var warning = [];
|
||||
|
||||
// If account trim history, get the correct channels here
|
||||
|
@ -113,7 +126,7 @@ define([
|
|||
nThen(function (waitFor) {
|
||||
channels.forEach(function (chan) {
|
||||
/*
|
||||
ctx.store.rpc.trimHistory(chan, waitFor(function (err) {
|
||||
rpc.trimHistory(chan, waitFor(function (err) {
|
||||
if (err) {
|
||||
chanWarning = true;
|
||||
warning.push(err);
|
||||
|
|
|
@ -1200,15 +1200,15 @@ define([
|
|||
|
||||
makeBlock('trim-history', function (cb) {
|
||||
if (!common.isLoggedIn()) { return; }
|
||||
// XXX settings_trimHistoryTitle, settings_trimHistoryHint, settings_trimHistoryButton, trimHistoryError
|
||||
// XXX trimHistorySuccess, trimHistory_confirm
|
||||
// XXX settings_trimHistoryTitle, settings_trimHistoryHint, trimHistory_button, trimHistory_error
|
||||
// XXX trimHistory_success, trimHistory_confirm
|
||||
|
||||
if (!privateData.isDriveOwned) { return; } // XXX
|
||||
|
||||
var spinner = UI.makeSpinner();
|
||||
var button = h('button.btn.btn-danger-alt', {
|
||||
disabled: 'disabled'
|
||||
}, Messages.trimHistoryButton || 'test'); // XXX
|
||||
}, Messages.trimHistory_button || 'test'); // XXX
|
||||
var currentSize = h('p', $(spinner.spinner).clone()[0]);
|
||||
var content = h('div', [
|
||||
currentSize,
|
||||
|
@ -1228,7 +1228,7 @@ define([
|
|||
}, waitFor(function (obj) {
|
||||
if (obj && obj.error) {
|
||||
waitFor.abort();
|
||||
var error = h('div.alert.alert-danger', Messages.trimHistoryError || 'error'); // XXX
|
||||
var error = h('div.alert.alert-danger', Messages.trimHistory_error || 'error'); // XXX
|
||||
$(content).empty().append(error);
|
||||
// TODO: obj.warning?
|
||||
return;
|
||||
|
@ -1253,7 +1253,7 @@ define([
|
|||
}
|
||||
// TODO: obj.warning?
|
||||
spinner.hide();
|
||||
$(content).append(h('div.alert.alert-success', Messages.trimHistorySuccess || 'ok')); // XXX
|
||||
$(content).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
|
||||
});
|
||||
});
|
||||
}).prop('disabled', '');
|
||||
|
|
Loading…
Reference in New Issue