From b585cbba4216861d77d5fecdfe12a987fe9f521a Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 11 Feb 2020 12:05:09 +0100 Subject: [PATCH] Improve trim history UI when completed --- www/common/common-ui-elements.js | 16 +++++++++---- www/common/outer/history.js | 2 -- www/settings/inner.js | 40 +++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 358f2c703..62ac47083 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -789,7 +789,11 @@ define([ var formatted = UIElements.prettySize(bytes); if (!owned || !historyBytes || historyBytes > bytes || historyBytes < 0) { - $d.append(h('div.cp-app-prop', [Messages.upload_size, h('br'), h('span.cp-app-prop-content', formatted)])); + $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); } @@ -838,12 +842,16 @@ define([ }, function (obj) { spinner.hide(); if (obj && obj.error) { - console.error(obj.error); - // XXX what are the possible errors? $(size).append(h('div.alert.alert-danger', Messages.trimHistory_error || 'error')); // XXX return; } - $(size).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX + $(size).remove(); + var formatted = UIElements.prettySize(bytes - historyBytes); + $d.append(h('div.cp-app-prop', [ + Messages.upload_size, + h('br'), + h('span.cp-app-prop-content', formatted) + ])); }); }); }); diff --git a/www/common/outer/history.js b/www/common/outer/history.js index bae186174..efb39e11c 100644 --- a/www/common/outer/history.js +++ b/www/common/outer/history.js @@ -191,9 +191,7 @@ define([ nThen(function (waitFor) { channels.forEach(function (obj) { - console.warn(obj); // XXX rpc.trimHistory(obj, waitFor(function (err) { - console.error(obj.channel, arguments); // XXX if (err) { warning.push(err); return; diff --git a/www/settings/inner.js b/www/settings/inner.js index 408029344..b7ad7998a 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -1216,25 +1216,29 @@ define([ return $div; }; - makeBlock('trim-history', function (cb) { - if (!common.isLoggedIn()) { return; } - // XXX settings_trimHistoryTitle, settings_trimHistoryHint, trimHistory_button, trimHistory_error - // XXX trimHistory_success, trimHistory_confirm, trimHistory_noHistory - - //if (!privateData.isDriveOwned) { return; } // XXX - + var redrawTrimHistory = function (cb, $div) { var spinner = UI.makeSpinner(); var button = h('button.btn.btn-danger-alt', { disabled: 'disabled' }, Messages.trimHistory_button || 'delete history... xxx'); // XXX var currentSize = h('p', $(spinner.spinner).clone()[0]); - var content = h('div', [ + var content = h('div#cp-settings-trim-container', [ currentSize, button, spinner.ok, spinner.spinner ]); + if (!privateData.isDriveOwned) { + var href = privateData.origin + privateData.pathname + '#' + 'account'; + $(currentSize).html(Messages.trimHistory_needMigration || 'Need migration Click'); // XXX + $(currentSize).find('a').prop('href', href).click(function (e) { + e.preventDefault(); + $('.cp-sidebarlayout-category[data-category="account"]').click(); + }); + return void cb(content); + } + Messages.trimHistory_currentSize = 'Size XXX: {0}'; // XXX var $button = $(button); @@ -1273,19 +1277,26 @@ define([ channels: channels }, function (obj) { if (obj && obj.error) { - // XXX what are the possible errors? + var error = h('div.alert.alert-danger', Messages.trimHistory_error || 'error'); // XXX + $(content).empty().append(error); return; } spinner.hide(); - // XXX redraw this block instead of displaying a green message? - $(currentSize).remove(); - $(content).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX + redrawTrimHistory(cb, $div); }); }); }).prop('disabled', ''); }); + $div.find('#cp-settings-trim-container').remove(); cb(content); + }; + makeBlock('trim-history', function (cb, $div) { + if (!common.isLoggedIn()) { return; } + // XXX settings_trimHistoryTitle, settings_trimHistoryHint, trimHistory_button, trimHistory_error + // XXX trimHistory_success, trimHistory_confirm, trimHistory_noHistory + // XXX trimHistory_needMigration (clickable tag (no attribute) to go to the "account" part of settings) + redrawTrimHistory(cb, $div); }, true); /* @@ -1713,7 +1724,10 @@ define([ APP.$usage = $('
', {'class': 'usage'}).appendTo(APP.$leftside); var active = privateData.category || 'account'; Object.keys(categories).forEach(function (key) { - var $category = $('
', {'class': 'cp-sidebarlayout-category'}).appendTo($categories); + var $category = $('
', { + 'class': 'cp-sidebarlayout-category', + 'data-category': key + }).appendTo($categories); if (key === 'account') { $category.append($('', {'class': 'fa fa-user-o'})); } if (key === 'drive') { $category.append($('', {'class': 'fa fa-hdd-o'})); } if (key === 'cursor') { $category.append($('', {'class': 'fa fa-i-cursor' })); }