Fix display of Duplicate/Unfiled Items rows

This commit is contained in:
Dan Stillman 2016-03-11 07:34:57 -05:00
parent 394aa8dded
commit f795240bbf
3 changed files with 52 additions and 32 deletions

View File

@ -156,25 +156,28 @@ Zotero.CollectionTreeView.prototype.refresh = Zotero.Promise.coroutine(function*
this._containerState = {}; this._containerState = {};
} }
if (this.hideSources.indexOf('duplicates') == -1) { var userLibraryID = Zotero.Libraries.userLibraryID;
try {
this._duplicateLibraries = Zotero.Prefs.get('duplicateLibraries').split(',').map(function (val) parseInt(val));
}
catch (e) {
// Add to personal library by default
Zotero.Prefs.set('duplicateLibraries', '0');
this._duplicateLibraries = [0];
}
}
try { var readPref = function (pref) {
this._unfiledLibraries = Zotero.Prefs.get('unfiledLibraries').split(',').map(function (val) parseInt(val)); let ids = Zotero.Prefs.get(pref);
} if (ids === "") {
catch (e) { this["_" + pref] = [];
// Add to personal library by default }
Zotero.Prefs.set('unfiledLibraries', '0'); else {
this._unfiledLibraries = [0]; if (ids === undefined || typeof ids != 'string') {
ids = "" + userLibraryID;
Zotero.Prefs.set(pref, "" + userLibraryID);
}
this["_" + pref] = ids.split(',')
// Convert old id and convert to int
.map(id => id === "0" ? userLibraryID : parseInt(id));
}
}.bind(this);
if (this.hideSources.indexOf('duplicates') == -1) {
readPref('duplicateLibraries');
} }
readPref('unfiledLibraries');
var oldCount = this.rowCount || 0; var oldCount = this.rowCount || 0;
var newRows = []; var newRows = [];
@ -916,10 +919,10 @@ Zotero.CollectionTreeView.prototype.selectByID = Zotero.Promise.coroutine(functi
break; break;
} }
if (!found) { var row = this._rowMap[type + id];
if (!row) {
return false; return false;
} }
var row = this._rowMap[type + id];
this._treebox.ensureRowIsVisible(row); this._treebox.ensureRowIsVisible(row);
yield this.selectWait(row); yield this.selectWait(row);

View File

@ -860,7 +860,7 @@ var ZoteroPane = new function()
}); });
this.setVirtual = function (libraryID, mode, show) { this.setVirtual = Zotero.Promise.coroutine(function* (libraryID, mode, show) {
switch (mode) { switch (mode) {
case 'duplicates': case 'duplicates':
var prefKey = 'duplicateLibraries'; var prefKey = 'duplicateLibraries';
@ -873,7 +873,7 @@ var ZoteroPane = new function()
break; break;
default: default:
throw ("Invalid virtual mode '" + mode + "' in ZoteroPane.setVirtual()"); throw new Error("Invalid virtual mode '" + mode + "'");
} }
try { try {
@ -883,10 +883,6 @@ var ZoteroPane = new function()
var ids = []; var ids = [];
} }
if (!libraryID) {
libraryID = Zotero.Libraries.userLibraryID;
}
var newids = []; var newids = [];
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
let id = ids[i]; let id = ids[i];
@ -898,8 +894,8 @@ var ZoteroPane = new function()
if (id == libraryID && !show) { if (id == libraryID && !show) {
continue; continue;
} }
// Remove libraryIDs that no longer exist // Remove libraries that no longer exist
if (id != 0 && !Zotero.Libraries.exists(id)) { if (!Zotero.Libraries.exists(id)) {
continue; continue;
} }
newids.push(id); newids.push(id);
@ -914,10 +910,10 @@ var ZoteroPane = new function()
Zotero.Prefs.set(prefKey, newids.join()); Zotero.Prefs.set(prefKey, newids.join());
this.collectionsView.refresh(); yield this.collectionsView.refresh();
// If group is closed, open it // If group is closed, open it
this.collectionsView.selectLibrary(libraryID); yield this.collectionsView.selectLibrary(libraryID);
row = this.collectionsView.selection.currentIndex; row = this.collectionsView.selection.currentIndex;
if (!this.collectionsView.isContainerOpen(row)) { if (!this.collectionsView.isContainerOpen(row)) {
this.collectionsView.toggleOpenState(row); this.collectionsView.toggleOpenState(row);
@ -925,10 +921,9 @@ var ZoteroPane = new function()
// Select new row // Select new row
if (show) { if (show) {
Zotero.Prefs.set('lastViewedFolder', lastViewedFolderID); yield this.collectionsView.selectByID(lastViewedFolderID);
this.collectionsView.selectByID(lastViewedFolderID); // async
} }
} });
this.openLookupWindow = Zotero.Promise.coroutine(function* () { this.openLookupWindow = Zotero.Promise.coroutine(function* () {

View File

@ -16,6 +16,28 @@ describe("Zotero.CollectionTreeView", function() {
win.close(); win.close();
}); });
describe("#refresh()", function () {
it("should show Duplicate Items and Unfiled Items in My Library by default", function* () {
Zotero.Prefs.clear('duplicateLibraries');
Zotero.Prefs.clear('unfiledLibraries');
yield cv.refresh();
yield assert.eventually.ok(cv.selectByID("D" + userLibraryID));
yield assert.eventually.ok(cv.selectByID("U" + userLibraryID));
assert.equal(Zotero.Prefs.get('duplicateLibraries'), "" + userLibraryID);
assert.equal(Zotero.Prefs.get('unfiledLibraries'), "" + userLibraryID);
});
it("shouldn't show Duplicate Items and Unfiled Items if hidden", function* () {
Zotero.Prefs.set('duplicateLibraries', "");
Zotero.Prefs.set('unfiledLibraries', "");
yield cv.refresh();
yield assert.eventually.notOk(cv.selectByID("D" + userLibraryID));
yield assert.eventually.notOk(cv.selectByID("U" + userLibraryID));
assert.strictEqual(Zotero.Prefs.get('duplicateLibraries'), "");
assert.strictEqual(Zotero.Prefs.get('unfiledLibraries'), "");
});
});
describe("collapse/expand", function () { describe("collapse/expand", function () {
it("should close and open My Library repeatedly", function* () { it("should close and open My Library repeatedly", function* () {
var libraryID = Zotero.Libraries.userLibraryID; var libraryID = Zotero.Libraries.userLibraryID;