Restore progress for attachments indication in connectors

78b1d2e regression
This commit is contained in:
Adomas Venčkauskas 2017-04-07 13:25:09 +03:00
parent d8fed09578
commit 406f50a3fd
2 changed files with 21 additions and 13 deletions

View file

@ -387,21 +387,25 @@ Zotero.Server.Connector.SaveItem.prototype = {
proxy
});
try {
let items = yield itemSaver.saveItems(
var deferred = Zotero.Promise.defer();
itemSaver.saveItems(
data.items,
Zotero.Server.Connector.AttachmentProgressManager.onProgress
);
// Remove attachments not being saved from item.attachments
for(var i=0; i<data.items.length; i++) {
var item = data.items[i];
for(var j=0; j<item.attachments.length; j++) {
if(!Zotero.Server.Connector.AttachmentProgressManager.has(item.attachments[j])) {
item.attachments.splice(j--, 1);
Zotero.Server.Connector.AttachmentProgressManager.onProgress,
function() {
// Remove attachments not being saved from item.attachments
for(var i=0; i<data.items.length; i++) {
var item = data.items[i];
for(var j=0; j<item.attachments.length; j++) {
if(!Zotero.Server.Connector.AttachmentProgressManager.has(item.attachments[j])) {
item.attachments.splice(j--, 1);
}
}
}
deferred.resolve([201, "application/json", JSON.stringify({items: data.items})]);
}
}
return [201, "application/json", JSON.stringify({items: data.items})];
);
return deferred.promise;
}
catch (e) {
Zotero.logError(e);

View file

@ -81,8 +81,10 @@ Zotero.Translate.ItemSaver.prototype = {
* @param {Function} [attachmentCallback] A callback that receives information about attachment
* save progress. The callback will be called as attachmentCallback(attachment, false, error)
* on failure or attachmentCallback(attachment, progressPercent) periodically during saving.
* @param {Function} [itemsDoneCallback] A callback that is called once all top-level items are
* done saving with a list of items. Will include saved notes, but exclude attachments.
*/
saveItems: Zotero.Promise.coroutine(function* (items, attachmentCallback) {
saveItems: Zotero.Promise.coroutine(function* (items, attachmentCallback, itemsDoneCallback) {
let newItems = [], standaloneAttachments = [], childAttachments = [];
yield Zotero.DB.executeTransaction(function* () {
for (let iitem=0; iitem<items.length; iitem++) {
@ -159,6 +161,8 @@ Zotero.Translate.ItemSaver.prototype = {
newItems.push(newItem);
}
}.bind(this));
itemsDoneCallback(newItems.splice());
// Handle attachments outside of the transaction, because they can involve downloading
for (let item of standaloneAttachments) {