Empty Trash: Visually remove deleted items, refresh icon (#2606)
There were a few problems causing the incorrect behavior: 1. Rows were being removed only if they had no non-deleted children, which wasn't the right check. We want to remove all rows with no *deleted* children. 2. Children of the removed rows weren't being removed with them. 3. We weren't invalidating the tree (which _removeRows() doesn't do). Also: * Erase trashed annotation after getAnnotations() test Because ItemTree#notify() doesn't yet correctly handle refresh events on parent items that are themselves children (three-level nesting: item -> attachment -> annotation), this test was causing a failure in itemTreeTest.js.
This commit is contained in:
parent
40ae2e3246
commit
22b00c33de
5 changed files with 25 additions and 9 deletions
|
@ -640,11 +640,8 @@ var CollectionTree = class CollectionTree extends LibraryTree {
|
||||||
this.tree.invalidate();
|
this.tree.invalidate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (action == 'refresh') {
|
if (action == 'refresh' && type != 'trash') {
|
||||||
// If trash is refreshed, we probably need to update the icon from full to empty
|
// Trash handled below
|
||||||
if (type == 'trash') {
|
|
||||||
this.tree.invalidate();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == 'feed' && (action == 'unreadCountUpdated' || action == 'statusChanged')) {
|
if (type == 'feed' && (action == 'unreadCountUpdated' || action == 'statusChanged')) {
|
||||||
|
@ -826,6 +823,11 @@ var CollectionTree = class CollectionTree extends LibraryTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (action == 'refresh' && type == 'trash') {
|
||||||
|
// We need to update the trash's status (full or empty), and if empty,
|
||||||
|
// the row might be removed
|
||||||
|
await this.reload();
|
||||||
|
}
|
||||||
|
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
var promise = this.waitForSelect();
|
var promise = this.waitForSelect();
|
||||||
|
@ -2307,7 +2309,7 @@ var CollectionTree = class CollectionTree extends LibraryTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showTrash) {
|
if (showTrash) {
|
||||||
let deletedItems = await Zotero.Items.getDeleted(libraryID);
|
let deletedItems = await Zotero.Items.getDeleted(libraryID, true);
|
||||||
if (deletedItems.length || Zotero.Prefs.get("showTrashWhenEmpty")) {
|
if (deletedItems.length || Zotero.Prefs.get("showTrashWhenEmpty")) {
|
||||||
var ref = {
|
var ref = {
|
||||||
libraryID: libraryID
|
libraryID: libraryID
|
||||||
|
|
|
@ -446,11 +446,20 @@ var ItemTree = class ItemTree extends LibraryTree {
|
||||||
let row = this.getRowIndexByID(id);
|
let row = this.getRowIndexByID(id);
|
||||||
if (row === false) continue;
|
if (row === false) continue;
|
||||||
let item = Zotero.Items.get(id);
|
let item = Zotero.Items.get(id);
|
||||||
if (!item.deleted && !item.numChildren()) {
|
// Remove parent row if it isn't deleted and doesn't have any deleted children
|
||||||
|
// (shown by the numChildren including deleted being the same as numChildren not including deleted)
|
||||||
|
if (!item.deleted && (!item.isRegularItem() || item.numChildren(true) == item.numChildren(false))) {
|
||||||
rows.push(row);
|
rows.push(row);
|
||||||
|
// And all its children in the tree
|
||||||
|
for (let child = row + 1; child < this.rowCount && this.getLevel(child) > this.getLevel(row); child++) {
|
||||||
|
rows.push(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._removeRows(rows);
|
if (rows.length) {
|
||||||
|
this._removeRows(rows);
|
||||||
|
this.tree.invalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1502,6 +1502,7 @@ Zotero.Items = function() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Zotero.debug("Emptied " + deleted.length + " item(s) from trash in " + (new Date() - t) + " ms");
|
Zotero.debug("Emptied " + deleted.length + " item(s) from trash in " + (new Date() - t) + " ms");
|
||||||
|
Zotero.Notifier.trigger('refresh', 'trash', libraryID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deleted.length;
|
return deleted.length;
|
||||||
|
|
|
@ -1465,6 +1465,10 @@ describe("Zotero.Item", function () {
|
||||||
await annotation2.saveTx();
|
await annotation2.saveTx();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
await annotation2.eraseTx();
|
||||||
|
});
|
||||||
|
|
||||||
it("should return annotations not in trash", async function () {
|
it("should return annotations not in trash", async function () {
|
||||||
var items = attachment.getAnnotations();
|
var items = attachment.getAnnotations();
|
||||||
assert.sameMembers(items, [annotation1]);
|
assert.sameMembers(items, [annotation1]);
|
||||||
|
|
|
@ -684,7 +684,7 @@ describe("Zotero.ItemTree", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Trash", function () {
|
describe("Trash", function () {
|
||||||
it.skip("should remove untrashed parent item when last trashed child is deleted", function* () {
|
it("should remove untrashed parent item when last trashed child is deleted", function* () {
|
||||||
var userLibraryID = Zotero.Libraries.userLibraryID;
|
var userLibraryID = Zotero.Libraries.userLibraryID;
|
||||||
var item = yield createDataObject('item');
|
var item = yield createDataObject('item');
|
||||||
var note = yield createDataObject(
|
var note = yield createDataObject(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue