Support library-key hashes in zotero://timeline and zotero://select URLs

This commit is contained in:
Dan Stillman 2009-12-05 20:16:42 +00:00
parent 9c5c02ef50
commit 01e9bea66e
2 changed files with 104 additions and 49 deletions

View File

@ -22,23 +22,21 @@
var Zotero_Timeline_Interface = new function() { var Zotero_Timeline_Interface = new function() {
this.loadTimeline = loadTimeline;
/* /*
* Load a timeline for the currently selected collection * Load a timeline for the currently selected collection
*/ */
function loadTimeline() { this.loadTimeline = function () {
var uri = 'zotero://timeline/'; var uri = 'zotero://timeline/';
var id = ZoteroPane.getSelectedCollection(true); var col = ZoteroPane.getSelectedCollection();
if (id) { if (col) {
window.loadURI(uri + 'collection/' + id); window.loadURI(uri + 'collection/' + Zotero.Collections.getLibraryKeyHash(col));
return; return;
} }
var id = ZoteroPane.getSelectedSavedSearch(true); var s = ZoteroPane.getSelectedSavedSearch();
if (id) { if (s) {
window.loadURI(uri + 'search/' + id); window.loadURI(uri + 'search/' + Zotero.Searches.getLibraryKeyHash(s));
return; return;
} }

View File

@ -49,17 +49,17 @@ function ChromeExtensionHandler() {
* Example URLs: * Example URLs:
* *
* zotero://report/ -- library * zotero://report/ -- library
* zotero://report/collection/12345 * zotero://report/collection/0_ABCD1234
* zotero://report/search/12345 * zotero://report/search/0_ABCD1234
* zotero://report/items/12345-23456-34567 * zotero://report/items/0_ABCD1234-0_BCDE2345-0_CDEF3456
* zotero://report/item/12345 * zotero://report/item/0_ABCD1234
* *
* Optional format can be specified after ids * Optional format can be specified after hashes
* *
* - 'html', 'rtf', 'csv' * - 'html', 'rtf', 'csv' ['rtf' and 'csv' not yet supported]
* - defaults to 'html' if not specified * - defaults to 'html' if not specified
* *
* e.g. zotero://report/collection/12345/rtf * e.g. zotero://report/collection/0_ABCD1234/rtf
* *
* *
* Sorting: * Sorting:
@ -68,7 +68,11 @@ function ChromeExtensionHandler() {
* - format is field[/order] [, field[/order], ...] * - format is field[/order] [, field[/order], ...]
* - order can be 'asc', 'a', 'desc' or 'd'; defaults to ascending order * - order can be 'asc', 'a', 'desc' or 'd'; defaults to ascending order
* *
* zotero://report/collection/13245?sort=itemType/d,title * zotero://report/collection/0_ABCD1234?sort=itemType/d,title
*
*
* Also supports ids (e.g., zotero://report/collection/1234), but ids are not
* guaranteed to be consistent across synced machines
*/ */
var ReportExtension = new function(){ var ReportExtension = new function(){
this.newChannel = newChannel; this.newChannel = newChannel;
@ -546,6 +550,54 @@ function ChromeExtensionHandler() {
} }
var pathParts = path.split('/'); var pathParts = path.split('/');
if (pathParts[0] != 'data') {
var [type, id] = pathParts;
}
else {
var [, type, id] = pathParts;
}
// Get the collection or search object
var collection, search;
switch (type) {
case 'collection':
var lkh = Zotero.Collections.parseLibraryKeyHash(id);
if (lkh) {
collection = Zotero.Collections.getByLibraryAndKey(lkh.libraryID, lkh.key);
}
else {
collection = Zotero.Collections.get(id);
}
if (!collection) {
mimeType = 'text/html';
content = 'Invalid collection ID or key';
break generateContent;
}
break;
case 'search':
var lkh = Zotero.Searches.parseLibraryKeyHash(id);
if (lkh) {
var s = Zotero.Searches.getByLibraryAndKey(lkh.libraryID, lkh.key);
}
else {
var s = Zotero.Searches.get(id);
}
if (!s) {
mimeType = 'text/html';
content = 'Invalid search ID or key';
break generateContent;
}
// FIXME: Hack to exclude group libraries for now
var search = new Zotero.Search();
search.setScope(s);
var groups = Zotero.Groups.getAll();
for each(var group in groups) {
search.addCondition('libraryID', 'isNot', group.libraryID);
}
break;
}
if (pathParts[0] != 'data') { if (pathParts[0] != 'data') {
//creates HTML file //creates HTML file
@ -580,12 +632,10 @@ function ChromeExtensionHandler() {
theTemp = 'document.write("<title>'; theTemp = 'document.write("<title>';
if(type == 'collection') { if(type == 'collection') {
var theCollection = Zotero.Collections.get(id); content = content.replace(theTemp, theTemp + collection.name + ' - ');
content = content.replace(theTemp, theTemp + theCollection.getName() + ' - ');
} }
else if(type == 'search') { else if(type == 'search') {
var theSearch = Zotero.Searches.get(id); content = content.replace(theTemp, theTemp + search.name + ' - ');
content = content.replace(theTemp, theTemp + theSearch['name'] + ' - ');
} }
else { else {
content = content.replace(theTemp, theTemp + Zotero.getString('pane.collections.library') + ' - '); content = content.replace(theTemp, theTemp + Zotero.getString('pane.collections.library') + ' - ');
@ -614,20 +664,16 @@ function ChromeExtensionHandler() {
return extChannel; return extChannel;
} }
// Create XML file
else { else {
//creates XML file
var [, type, ids] = pathParts;
switch (type) { switch (type) {
case 'collection': case 'collection':
var col = Zotero.Collections.get(ids); var results = collection.getChildItems();
var results = col.getChildItems();
break; break;
case 'search': case 'search':
var s = new Zotero.Search(); var ids = search.search();
s.id = ids; var results = Zotero.Items.get(ids);
var ids = s.search();
break; break;
default: default:
@ -635,11 +681,9 @@ function ChromeExtensionHandler() {
var s = new Zotero.Search(); var s = new Zotero.Search();
s.addCondition('noChildren', 'true'); s.addCondition('noChildren', 'true');
var ids = s.search(); var ids = s.search();
}
if (!results) {
var results = Zotero.Items.get(ids); var results = Zotero.Items.get(ids);
} }
var items = []; var items = [];
// Only include parent items // Only include parent items
for (var i = 0; i < results.length; i++) { for (var i = 0; i < results.length; i++) {
@ -661,7 +705,6 @@ function ChromeExtensionHandler() {
mimeType = 'application/xml'; mimeType = 'application/xml';
var theDateTypes = new Object(); var theDateTypes = new Object();
theDateTypes['d'] = 'date'; theDateTypes['d'] = 'date';
theDateTypes['da'] = 'dateAdded'; theDateTypes['da'] = 'dateAdded';
@ -673,7 +716,6 @@ function ChromeExtensionHandler() {
} }
content = Zotero.Timeline.generateXMLDetails(items, theDateTypes[dateType]); content = Zotero.Timeline.generateXMLDetails(items, theDateTypes[dateType]);
} }
var uri_str = 'data:' + (mimeType ? mimeType + ',' : '') + encodeURIComponent(content); var uri_str = 'data:' + (mimeType ? mimeType + ',' : '') + encodeURIComponent(content);
@ -770,8 +812,9 @@ function ChromeExtensionHandler() {
}; };
/* /**
zotero://select/type/id * zotero://select/[type]/0_ABCD1234
* zotero://select/[type]/1234 (not consistent across synced machines)
*/ */
var SelectExtension = new function(){ var SelectExtension = new function(){
this.newChannel = newChannel; this.newChannel = newChannel;
@ -799,7 +842,21 @@ function ChromeExtensionHandler() {
win.ZoteroPane.toggleDisplay(); win.ZoteroPane.toggleDisplay();
} }
win.ZoteroPane.selectItem(id); var lkh = Zotero.Items.parseLibraryKeyHash(id);
if (lkh) {
var item = Zotero.Items.getByLibraryAndKey(lkh.libraryID, lkh.key);
}
else {
var item = Zotero.Items.get(id);
}
if (!item) {
var msg = "Item " + id + " not found in zotero://select";
Zotero.debug(msg, 2);
Components.utils.reportError(msg);
return;
}
win.ZoteroPane.selectItem(item.id);
} }
catch (e){ catch (e){
Zotero.debug(e); Zotero.debug(e);