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 = {};
|
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 === "") {
|
||||||
|
this["_" + pref] = [];
|
||||||
}
|
}
|
||||||
catch (e) {
|
else {
|
||||||
// Add to personal library by default
|
if (ids === undefined || typeof ids != 'string') {
|
||||||
Zotero.Prefs.set('unfiledLibraries', '0');
|
ids = "" + userLibraryID;
|
||||||
this._unfiledLibraries = [0];
|
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);
|
||||||
|
|
||||||
|
|
|
@ -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* () {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user