mirror of
https://github.com/zotero/zotero.git
synced 2026-10-04 02:31:47 +00:00
Display the number of items that would be deleted when replacing the online library (#5359)
And require checkbox or text challenge depending on the severity of the action --------- Co-authored-by: Dan Stillman <dstillman@zotero.org>
This commit is contained in:
parent
562fed6e7e
commit
e3fc1e62a0
4 changed files with 84 additions and 36 deletions
|
|
@ -831,44 +831,74 @@ Zotero_Preferences.Sync = {
|
|||
}
|
||||
break;*/
|
||||
|
||||
case 'restore-to-server':
|
||||
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
|
||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL)
|
||||
+ ps.BUTTON_POS_1_DEFAULT;
|
||||
var index = ps.confirmEx(
|
||||
null,
|
||||
Zotero.getString('general.warning'),
|
||||
Zotero.getString(
|
||||
'zotero.preferences.sync.reset.restoreToServer',
|
||||
[Zotero.clientName, library.name, ZOTERO_CONFIG.DOMAIN_NAME]
|
||||
),
|
||||
buttonFlags,
|
||||
Zotero.getString('zotero.preferences.sync.reset.restoreToServer.button'),
|
||||
null, null, null, {}
|
||||
);
|
||||
case 'restore-to-server': {
|
||||
const CHECKBOX_THRESHOLD = 10;
|
||||
const CONFIRMATION_TEXT_MAX_ITEMS = 5;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
var resetButton = document.getElementById('sync-reset-button');
|
||||
resetButton.disabled = true;
|
||||
try {
|
||||
await Zotero.Sync.Runner.sync({
|
||||
libraries: [libraryID],
|
||||
resetMode: Zotero.Sync.Runner.RESET_MODE_TO_SERVER
|
||||
});
|
||||
}
|
||||
finally {
|
||||
resetButton.disabled = false;
|
||||
}
|
||||
break;
|
||||
|
||||
// Cancel
|
||||
case 1:
|
||||
return;
|
||||
let apiKey = await Zotero.Sync.Data.Local.getAPIKey();
|
||||
let client = Zotero.Sync.Runner.getAPIClient({ apiKey });
|
||||
var keyInfo = await Zotero.Sync.Runner.checkAccess(client, { timeout: 5000 });
|
||||
let { keys: remoteKeysArray } = await client.getKeys('user', keyInfo.userID, { target: 'items', itemType: '-annotation' });
|
||||
let remoteKeys = new Set(remoteKeysArray);
|
||||
let localItems = await Zotero.Items.getAll(Zotero.Libraries.userLibraryID, false, false, false);
|
||||
let localItemsCount = localItems.length;
|
||||
let localKeys = new Set(localItems
|
||||
.filter(item => item.isRegularItem() || item.isNote() || item.isAttachment())
|
||||
.map(item => item.key));
|
||||
let remoteButNotLocal = remoteKeys.difference(localKeys); // NOTE: `difference` requires FF 127
|
||||
let remoteItemsDeletedCount = remoteButNotLocal.size;
|
||||
|
||||
let [title, text, warning1, warning2, checkboxLabel, yes] = await document.l10n.formatValues([
|
||||
'general-warning',
|
||||
{ id: 'preferences-sync-reset-restore-to-server-body', args: { libraryName: library.name, domain: ZOTERO_CONFIG.DOMAIN_NAME } },
|
||||
{ id: 'preferences-sync-reset-restore-to-server-deleted-items-text', args: { remoteItemsDeletedCount } },
|
||||
{ id: 'preferences-sync-reset-restore-to-server-remaining-items-text', args: { localItemsCount } },
|
||||
{ id: 'preferences-sync-reset-restore-to-server-checkbox-label', args: { remoteItemsDeletedCount } },
|
||||
'preferences-sync-reset-restore-to-server-yes',
|
||||
]);
|
||||
let confirmationText;
|
||||
|
||||
text = remoteItemsDeletedCount > 0 ? `${text}\n\n${warning1}` : text;
|
||||
|
||||
if (remoteItemsDeletedCount < CHECKBOX_THRESHOLD) {
|
||||
checkboxLabel = null;
|
||||
}
|
||||
else if (localItemsCount < CONFIRMATION_TEXT_MAX_ITEMS) {
|
||||
text += warning2;
|
||||
checkboxLabel = null;
|
||||
confirmationText = await document.l10n.formatValue(
|
||||
'preferences-sync-reset-restore-to-server-confirmation-text',
|
||||
)
|
||||
text += "\n\n" + await document.l10n.formatValue(
|
||||
'general-type-to-continue',
|
||||
{ text: confirmationText}
|
||||
);
|
||||
}
|
||||
var io = {
|
||||
title,
|
||||
text,
|
||||
acceptLabel: yes,
|
||||
checkboxLabel,
|
||||
confirmationText
|
||||
};
|
||||
window.openDialog("chrome://zotero/content/hardConfirmationDialog.xhtml", "",
|
||||
"chrome,dialog,dependent,modal,centerscreen", io);
|
||||
|
||||
if (io.accept) {
|
||||
let resetButton = document.getElementById('sync-reset-button');
|
||||
resetButton.disabled = true;
|
||||
try {
|
||||
await Zotero.Sync.Runner.sync({
|
||||
libraries: [libraryID],
|
||||
resetMode: Zotero.Sync.Runner.RESET_MODE_TO_SERVER
|
||||
});
|
||||
}
|
||||
finally {
|
||||
resetButton.disabled = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case 'reset-file-sync-history':
|
||||
var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING
|
||||
|
|
|
|||
|
|
@ -103,3 +103,19 @@ preferences-advanced-custom-data-dir =
|
|||
preferences-advanced-default-data-dir =
|
||||
.value = (Default: { $directory })
|
||||
.aria-label = Default location
|
||||
|
||||
preferences-sync-reset-restore-to-server-body = { -app-name } will replace “{ $libraryName }” on { $domain } with data from this computer.
|
||||
preferences-sync-reset-restore-to-server-deleted-items-text = { $remoteItemsDeletedCount } { $remoteItemsDeletedCount ->
|
||||
[one] item
|
||||
*[other] items
|
||||
} in the online library will be permanently deleted.
|
||||
preferences-sync-reset-restore-to-server-remaining-items-text = { general-sentence-separator }{ $localItemsCount ->
|
||||
[0] The library on this computer and the online library will be empty.
|
||||
[one] 1 item will remain on this computer and in the online library.
|
||||
*[other] { $localItemsCount } items will remain on this computer and in the online library.
|
||||
}
|
||||
preferences-sync-reset-restore-to-server-checkbox-label = { $remoteItemsDeletedCount ->
|
||||
*[other] Delete { $remoteItemsDeletedCount } items
|
||||
}
|
||||
preferences-sync-reset-restore-to-server-confirmation-text = delete online library
|
||||
preferences-sync-reset-restore-to-server-yes = Replace Data in Online Library
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
general-sentence-separator = { " " }
|
||||
|
||||
general-key-control = Control
|
||||
general-key-shift = Shift
|
||||
general-key-alt = Alt
|
||||
|
|
@ -58,6 +60,8 @@ general-et-al = et al.
|
|||
general-previous = Previous
|
||||
general-next = Next
|
||||
general-learn-more = Learn More
|
||||
general-warning = Warning
|
||||
general-type-to-continue = Type “{ $text }” to continue.
|
||||
|
||||
general-red = Red
|
||||
general-orange = Orange
|
||||
|
|
|
|||
|
|
@ -718,8 +718,6 @@ zotero.preferences.sync.reset.userInfoMissing = You must enter a username and
|
|||
zotero.preferences.sync.reset.restoreFromServer = All data in this copy of Zotero will be erased and replaced with data belonging to user '%S' on the Zotero server.
|
||||
zotero.preferences.sync.reset.replaceLocalData = Replace Local Data
|
||||
zotero.preferences.sync.reset.restartToComplete = Firefox must be restarted to complete the restore process.
|
||||
zotero.preferences.sync.reset.restoreToServer = %1$S will replace data in “%2$S” on %3$S with data from this computer.
|
||||
zotero.preferences.sync.reset.restoreToServer.button = Replace Data in Online Library
|
||||
zotero.preferences.sync.reset.fileSyncHistory = On the next sync, %1$S will check all attachment files in “%2$S” against the storage service. Any remote attachment files that are missing locally will be downloaded, and local attachment files missing remotely will be uploaded.\n\nThis option is not necessary during normal usage.
|
||||
zotero.preferences.sync.reset.fileSyncHistory.cleared = The file sync history for “%S” has been cleared.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue