Fix display of Duplicate/Unfiled Items rows
This commit is contained in:
parent
394aa8dded
commit
f795240bbf
|
@ -156,25 +156,28 @@ Zotero.CollectionTreeView.prototype.refresh = Zotero.Promise.coroutine(function*
|
|||
this._containerState = {};
|
||||
}
|
||||
|
||||
if (this.hideSources.indexOf('duplicates') == -1) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
var userLibraryID = Zotero.Libraries.userLibraryID;
|
||||
|
||||
try {
|
||||
this._unfiledLibraries = Zotero.Prefs.get('unfiledLibraries').split(',').map(function (val) parseInt(val));
|
||||
var readPref = function (pref) {
|
||||
let ids = Zotero.Prefs.get(pref);
|
||||
if (ids === "") {
|
||||
this["_" + pref] = [];
|
||||
}
|
||||
catch (e) {
|
||||
// Add to personal library by default
|
||||
Zotero.Prefs.set('unfiledLibraries', '0');
|
||||
this._unfiledLibraries = [0];
|
||||
else {
|
||||
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 newRows = [];
|
||||
|
@ -916,10 +919,10 @@ Zotero.CollectionTreeView.prototype.selectByID = Zotero.Promise.coroutine(functi
|
|||
break;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
var row = this._rowMap[type + id];
|
||||
if (!row) {
|
||||
return false;
|
||||
}
|
||||
var row = this._rowMap[type + id];
|
||||
this._treebox.ensureRowIsVisible(row);
|
||||
yield this.selectWait(row);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
case 'duplicates':
|
||||
var prefKey = 'duplicateLibraries';
|
||||
|
@ -873,7 +873,7 @@ var ZoteroPane = new function()
|
|||
break;
|
||||
|
||||
default:
|
||||
throw ("Invalid virtual mode '" + mode + "' in ZoteroPane.setVirtual()");
|
||||
throw new Error("Invalid virtual mode '" + mode + "'");
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -883,10 +883,6 @@ var ZoteroPane = new function()
|
|||
var ids = [];
|
||||
}
|
||||
|
||||
if (!libraryID) {
|
||||
libraryID = Zotero.Libraries.userLibraryID;
|
||||
}
|
||||
|
||||
var newids = [];
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
let id = ids[i];
|
||||
|
@ -898,8 +894,8 @@ var ZoteroPane = new function()
|
|||
if (id == libraryID && !show) {
|
||||
continue;
|
||||
}
|
||||
// Remove libraryIDs that no longer exist
|
||||
if (id != 0 && !Zotero.Libraries.exists(id)) {
|
||||
// Remove libraries that no longer exist
|
||||
if (!Zotero.Libraries.exists(id)) {
|
||||
continue;
|
||||
}
|
||||
newids.push(id);
|
||||
|
@ -914,10 +910,10 @@ var ZoteroPane = new function()
|
|||
|
||||
Zotero.Prefs.set(prefKey, newids.join());
|
||||
|
||||
this.collectionsView.refresh();
|
||||
yield this.collectionsView.refresh();
|
||||
|
||||
// If group is closed, open it
|
||||
this.collectionsView.selectLibrary(libraryID);
|
||||
yield this.collectionsView.selectLibrary(libraryID);
|
||||
row = this.collectionsView.selection.currentIndex;
|
||||
if (!this.collectionsView.isContainerOpen(row)) {
|
||||
this.collectionsView.toggleOpenState(row);
|
||||
|
@ -925,10 +921,9 @@ var ZoteroPane = new function()
|
|||
|
||||
// Select new row
|
||||
if (show) {
|
||||
Zotero.Prefs.set('lastViewedFolder', lastViewedFolderID);
|
||||
this.collectionsView.selectByID(lastViewedFolderID); // async
|
||||
}
|
||||
yield this.collectionsView.selectByID(lastViewedFolderID);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.openLookupWindow = Zotero.Promise.coroutine(function* () {
|
||||
|
|
|
@ -16,6 +16,28 @@ describe("Zotero.CollectionTreeView", function() {
|
|||
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 () {
|
||||
it("should close and open My Library repeatedly", function* () {
|
||||
var libraryID = Zotero.Libraries.userLibraryID;
|
||||
|
|
Loading…
Reference in New Issue
Block a user