- Use keys rather than ids for report URLs

- Collection report sorting was backwards (since Fx3.5, probably)
- Return full Zotero.Search objects from Zotero.Searches.getAll()
This commit is contained in:
Dan Stillman 2009-12-05 04:26:22 +00:00
parent b2589585db
commit f6c8494a6b
4 changed files with 93 additions and 31 deletions

View file

@ -33,23 +33,25 @@ var Zotero_Report_Interface = new function() {
function loadCollectionReport() {
var queryString = '';
var id = ZoteroPane.getSelectedCollection(true);
var col = ZoteroPane.getSelectedCollection();
var sortColumn = ZoteroPane.getSortField();
var sortDirection = ZoteroPane.getSortDirection();
// See note re: 'ascending'/'descending' for ItemTreeView.getSortDirection()
if (sortColumn != 'title' || sortDirection != 'descending') {
queryString = '?sort=' + sortColumn +
(sortDirection != 'descending' ? '/d' : '');
if (sortColumn != 'title' || sortDirection != 'ascending') {
queryString = '?sort=' + sortColumn + (sortDirection != 'ascending' ? '' : '/d');
}
if (id) {
window.loadURI('zotero://report/collection/' + id + '/html/report.html' + queryString);
if (col) {
window.loadURI('zotero://report/collection/'
+ Zotero.Collections.getLibraryKeyHash(col)
+ '/html/report.html' + queryString);
return;
}
var id = ZoteroPane.getSelectedSavedSearch(true);
if (id) {
window.loadURI('zotero://report/search/' + id + '/html/report.html' + queryString);
var s = ZoteroPane.getSelectedSavedSearch();
if (s) {
window.loadURI('zotero://report/search/'
+ Zotero.Searches.getLibraryKeyHash(s)
+ '/html/report.html' + queryString);
return;
}
@ -61,13 +63,18 @@ var Zotero_Report_Interface = new function() {
* Load a report for the currently selected items
*/
function loadItemReport() {
var items = ZoteroPane.getSelectedItems(true);
var items = ZoteroPane.getSelectedItems();
if (!items || !items.length) {
throw ('No items currently selected');
}
window.loadURI('zotero://report/items/' + items.join('-') + '/html/report.html');
var keyHashes = [];
for each(var item in items) {
keyHashes.push(Zotero.Items.getLibraryKeyHash(item));
}
window.loadURI('zotero://report/items/' + keyHashes.join('-') + '/html/report.html');
}

View file

@ -41,6 +41,9 @@ Zotero.DataObjects = function (object, objectPlural, id, table) {
this.parseLibraryKeyHash = function (libraryKey) {
var [libraryID, key] = libraryKey.split('_');
if (!key) {
return false;
}
libraryID = parseInt(libraryID);
return {
libraryID: libraryID ? libraryID : null,

View file

@ -1560,20 +1560,28 @@ Zotero.Searches = new function(){
/*
* Returns an array of saved searches with 'id' and 'name', ordered by name
* Returns an array of saved searches, ordered by name
*/
function getAll(){
var sql = "SELECT savedSearchID AS id, savedSearchName AS name "
+ "FROM savedSearches ORDER BY name COLLATE NOCASE";
var searches = Zotero.DB.query(sql);
if (!searches) {
+ "FROM savedSearches ORDER BY name COLLATE NOCASE";
var rows = Zotero.DB.query(sql);
if (!rows) {
return [];
}
// Do proper collation sort
var collation = Zotero.getLocaleCollation();
searches.sort(function (a, b) {
rows.sort(function (a, b) {
return collation.compareString(1, a.name, b.name);
});
var searches = [];
for each(var row in rows) {
var search = new Zotero.Search;
search.id = row.id;
searches.push(search);
}
return searches;
}

View file

@ -104,19 +104,72 @@ function ChromeExtensionHandler() {
switch (type){
case 'collection':
var col = Zotero.Collections.get(ids);
var lkh = Zotero.Collections.parseLibraryKeyHash(ids);
if (lkh) {
var col = Zotero.Collections.getByLibraryAndKey(lkh.libraryID, lkh.key);
}
else {
var col = Zotero.Collections.get(ids);
}
if (!col) {
mimeType = 'text/html';
content = 'Invalid collection ID or key';
break generateContent;
}
var results = col.getChildItems();
break;
case 'search':
var s = new Zotero.Search();
s.id = ids;
ids = s.search();
var lkh = Zotero.Searches.parseLibraryKeyHash(ids);
if (lkh) {
var s = Zotero.Searches.getByLibraryAndKey(lkh.libraryID, lkh.key);
}
else {
var s = Zotero.Searches.get(ids);
}
if (!s) {
mimeType = 'text/html';
content = 'Invalid search ID or key';
break generateContent;
}
// FIXME: Hack to exclude group libraries for now
var s2 = new Zotero.Search();
s2.setScope(s);
var groups = Zotero.Groups.getAll();
for each(var group in groups) {
s2.addCondition('libraryID', 'isNot', group.libraryID);
}
var ids = s2.search();
var results = Zotero.Items.get(ids);
break;
case 'items':
case 'item':
ids = ids.split('-');
// Keys
if (Zotero.Items.parseLibraryKeyHash(ids[0])) {
var results = [];
for each(var lkh in ids) {
var lkh = Zotero.Items.parseLibraryKeyHash(lkh);
var item = Zotero.Items.getByLibraryAndKey(lkh.libraryID, lkh.key);
if (item) {
results.push(item);
}
}
}
// IDs
else {
var results = Zotero.Items.get(ids);
}
if (!results.length) {
mimeType = 'text/html';
content = 'Invalid ID';
break generateContent;
}
break;
default:
@ -140,16 +193,7 @@ function ChromeExtensionHandler() {
var s = new Zotero.Search();
s.addCondition('noChildren', 'true');
var ids = s.search();
}
if (!results) {
var results = Zotero.Items.get(ids);
if (!results) {
mimeType = 'text/html';
content = 'Invalid ID';
break generateContent;
}
var results = Zotero.Items.get(ids);
}
var items = [];