zotero://select improvements

- Support items within collections and searches:

zotero://select/library/collections/:collectionKey/items/:itemKey
zotero://select/groups/:groupID/collections/:collectionKey/items/:itemKey

- Fix the 'itemKey' parameter:

zotero://select/library/collections/:collectionKey/items?itemKey=:itemKey1,:itemKey2

- Select library root if collection/search not specified
This commit is contained in:
Dan Stillman 2019-05-09 01:59:43 -04:00
parent 32de0d4037
commit ebda79a958
2 changed files with 38 additions and 6 deletions

View file

@ -66,6 +66,10 @@ Zotero.API = {
throw new Error('Invalid collection ID or key');
}
results = col.getChildItems();
if (params.objectKey) {
let item = results.find(item => item.key == params.objectKey);
results = item ? [item] : [];
}
break;
case 'searches':
@ -81,14 +85,13 @@ Zotero.API = {
throw new Error('Invalid search ID or key');
}
// FIXME: Hack to exclude group libraries for now
var s2 = new Zotero.Search();
s2.setScope(s);
var groups = Zotero.Groups.getAll();
for (let group of groups) {
s2.addCondition('libraryID', 'isNot', group.libraryID);
}
var ids = yield s2.search();
if (params.objectKey) {
let id = Zotero.Items.getIDFromLibraryAndKey(s.libraryID, params.objectKey);
ids = ids.includes(id) ? [id] : [];
}
break;
default:
@ -126,7 +129,7 @@ Zotero.API = {
if (results) {
// Filter results by item key
if (params.itemKey) {
results = results.filter(key => itemKeys.has(key));
results = results.filter(item => itemKeys.has(item.key));
}
}
else if (ids) {

View file

@ -874,6 +874,35 @@ function ZoteroProtocolHandler() {
return zp.collectionsView.selectCollection(results[0].id);
}
else {
// Select collection first if specified
if (params.scopeObject == 'collections') {
let col;
if (params.scopeObjectKey) {
col = Zotero.Collections.getByLibraryAndKey(
params.libraryID, params.scopeObjectKey
);
}
else {
col = Zotero.Collections.get(params.scopeObjectID);
}
yield zp.collectionsView.selectCollection(col.id);
}
else if (params.scopeObject == 'searches') {
let s;
if (params.scopeObjectKey) {
s = Zotero.Searches.getByLibraryAndKey(
params.libraryID, params.scopeObjectKey
);
}
else {
s = Zotero.Searches.get(params.scopeObjectID);
}
yield zp.collectionsView.selectSearch(s.id);
}
// If collection not specified, select library root
else {
yield zp.collectionsView.selectLibrary(params.libraryID);
}
return zp.selectItems(results.map(x => x.id));
}
}),