Remove non-matching parent items when deleting items from trash
Fixes #866, Trash doesn't refresh properly when emptying deleted attachments
This commit is contained in:
parent
81d5618346
commit
46531a4c69
|
@ -4017,6 +4017,10 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
|
||||||
? (yield this.ObjectsClass.getByLibraryAndKeyAsync(this.libraryID, parentItem))
|
? (yield this.ObjectsClass.getByLibraryAndKeyAsync(this.libraryID, parentItem))
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
if (parentItem) {
|
||||||
|
Zotero.Notifier.queue('refresh', 'item', parentItem.id);
|
||||||
|
}
|
||||||
|
|
||||||
// // Delete associated attachment files
|
// // Delete associated attachment files
|
||||||
if (this.isAttachment()) {
|
if (this.isAttachment()) {
|
||||||
let linkMode = this.getAttachmentLinkMode();
|
let linkMode = this.getAttachmentLinkMode();
|
||||||
|
|
|
@ -593,6 +593,20 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
this._cellTextCache = {};
|
this._cellTextCache = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For a refresh on an item in the trash, check if the item still belongs
|
||||||
|
if (type == 'item' && collectionTreeRow.isTrash()) {
|
||||||
|
let rows = [];
|
||||||
|
for (let id of ids) {
|
||||||
|
let row = this.getRowIndexByID(id);
|
||||||
|
if (row === false) continue;
|
||||||
|
let item = Zotero.Items.get(id);
|
||||||
|
if (!item.deleted && !item.numChildren()) {
|
||||||
|
rows.push(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._removeRows(rows);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,14 +678,7 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rows.length > 0) {
|
if (rows.length > 0) {
|
||||||
// Child items might have been added more than once
|
this._removeRows(rows);
|
||||||
rows = Zotero.Utilities.arrayUnique(rows);
|
|
||||||
rows.sort(function(a,b) { return a-b });
|
|
||||||
|
|
||||||
for (let i = rows.length - 1; i >= 0; i--) {
|
|
||||||
this._removeRow(rows[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
madeChanges = true;
|
madeChanges = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,6 +279,15 @@ Zotero.LibraryTreeView.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
_removeRows: function (rows) {
|
||||||
|
rows = Zotero.Utilities.arrayUnique(rows);
|
||||||
|
rows.sort((a, b) => a - b);
|
||||||
|
for (let i = rows.length - 1; i >= 0; i--) {
|
||||||
|
this._removeRow(rows[i]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
getLevel: function (row) {
|
getLevel: function (row) {
|
||||||
return this._rows[row].level;
|
return this._rows[row].level;
|
||||||
},
|
},
|
||||||
|
|
|
@ -530,6 +530,23 @@ describe("Zotero.ItemTreeView", function() {
|
||||||
assert.isFalse(zp.itemsView.getRowIndexByID(item.id));
|
assert.isFalse(zp.itemsView.getRowIndexByID(item.id));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Trash", function () {
|
||||||
|
it("should remove untrashed parent item when last trashed child is deleted", function* () {
|
||||||
|
var userLibraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
var item = yield createDataObject('item');
|
||||||
|
var note = yield createDataObject(
|
||||||
|
'item', { itemType: 'note', parentID: item.id, deleted: true }
|
||||||
|
);
|
||||||
|
yield cv.selectByID("T" + userLibraryID);
|
||||||
|
yield waitForItemsLoad(win);
|
||||||
|
assert.isNumber(zp.itemsView.getRowIndexByID(item.id));
|
||||||
|
var promise = waitForDialog();
|
||||||
|
yield zp.emptyTrash();
|
||||||
|
yield promise;
|
||||||
|
assert.isFalse(zp.itemsView.getRowIndexByID(item.id));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("My Publications", function () {
|
describe("My Publications", function () {
|
||||||
before(function* () {
|
before(function* () {
|
||||||
var libraryID = Zotero.Libraries.userLibraryID;
|
var libraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user