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:
parent
32de0d4037
commit
ebda79a958
2 changed files with 38 additions and 6 deletions
|
@ -66,6 +66,10 @@ Zotero.API = {
|
||||||
throw new Error('Invalid collection ID or key');
|
throw new Error('Invalid collection ID or key');
|
||||||
}
|
}
|
||||||
results = col.getChildItems();
|
results = col.getChildItems();
|
||||||
|
if (params.objectKey) {
|
||||||
|
let item = results.find(item => item.key == params.objectKey);
|
||||||
|
results = item ? [item] : [];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'searches':
|
case 'searches':
|
||||||
|
@ -81,14 +85,13 @@ Zotero.API = {
|
||||||
throw new Error('Invalid search ID or key');
|
throw new Error('Invalid search ID or key');
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Hack to exclude group libraries for now
|
|
||||||
var s2 = new Zotero.Search();
|
var s2 = new Zotero.Search();
|
||||||
s2.setScope(s);
|
s2.setScope(s);
|
||||||
var groups = Zotero.Groups.getAll();
|
|
||||||
for (let group of groups) {
|
|
||||||
s2.addCondition('libraryID', 'isNot', group.libraryID);
|
|
||||||
}
|
|
||||||
var ids = yield s2.search();
|
var ids = yield s2.search();
|
||||||
|
if (params.objectKey) {
|
||||||
|
let id = Zotero.Items.getIDFromLibraryAndKey(s.libraryID, params.objectKey);
|
||||||
|
ids = ids.includes(id) ? [id] : [];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -126,7 +129,7 @@ Zotero.API = {
|
||||||
if (results) {
|
if (results) {
|
||||||
// Filter results by item key
|
// Filter results by item key
|
||||||
if (params.itemKey) {
|
if (params.itemKey) {
|
||||||
results = results.filter(key => itemKeys.has(key));
|
results = results.filter(item => itemKeys.has(item.key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ids) {
|
else if (ids) {
|
||||||
|
|
|
@ -874,6 +874,35 @@ function ZoteroProtocolHandler() {
|
||||||
return zp.collectionsView.selectCollection(results[0].id);
|
return zp.collectionsView.selectCollection(results[0].id);
|
||||||
}
|
}
|
||||||
else {
|
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));
|
return zp.selectItems(results.map(x => x.id));
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue