- 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:
parent
b2589585db
commit
f6c8494a6b
|
@ -33,23 +33,25 @@ var Zotero_Report_Interface = new function() {
|
||||||
function loadCollectionReport() {
|
function loadCollectionReport() {
|
||||||
var queryString = '';
|
var queryString = '';
|
||||||
|
|
||||||
var id = ZoteroPane.getSelectedCollection(true);
|
var col = ZoteroPane.getSelectedCollection();
|
||||||
var sortColumn = ZoteroPane.getSortField();
|
var sortColumn = ZoteroPane.getSortField();
|
||||||
var sortDirection = ZoteroPane.getSortDirection();
|
var sortDirection = ZoteroPane.getSortDirection();
|
||||||
// See note re: 'ascending'/'descending' for ItemTreeView.getSortDirection()
|
if (sortColumn != 'title' || sortDirection != 'ascending') {
|
||||||
if (sortColumn != 'title' || sortDirection != 'descending') {
|
queryString = '?sort=' + sortColumn + (sortDirection != 'ascending' ? '' : '/d');
|
||||||
queryString = '?sort=' + sortColumn +
|
|
||||||
(sortDirection != 'descending' ? '/d' : '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id) {
|
if (col) {
|
||||||
window.loadURI('zotero://report/collection/' + id + '/html/report.html' + queryString);
|
window.loadURI('zotero://report/collection/'
|
||||||
|
+ Zotero.Collections.getLibraryKeyHash(col)
|
||||||
|
+ '/html/report.html' + queryString);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var id = ZoteroPane.getSelectedSavedSearch(true);
|
var s = ZoteroPane.getSelectedSavedSearch();
|
||||||
if (id) {
|
if (s) {
|
||||||
window.loadURI('zotero://report/search/' + id + '/html/report.html' + queryString);
|
window.loadURI('zotero://report/search/'
|
||||||
|
+ Zotero.Searches.getLibraryKeyHash(s)
|
||||||
|
+ '/html/report.html' + queryString);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,13 +63,18 @@ var Zotero_Report_Interface = new function() {
|
||||||
* Load a report for the currently selected items
|
* Load a report for the currently selected items
|
||||||
*/
|
*/
|
||||||
function loadItemReport() {
|
function loadItemReport() {
|
||||||
var items = ZoteroPane.getSelectedItems(true);
|
var items = ZoteroPane.getSelectedItems();
|
||||||
|
|
||||||
if (!items || !items.length) {
|
if (!items || !items.length) {
|
||||||
throw ('No items currently selected');
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ Zotero.DataObjects = function (object, objectPlural, id, table) {
|
||||||
|
|
||||||
this.parseLibraryKeyHash = function (libraryKey) {
|
this.parseLibraryKeyHash = function (libraryKey) {
|
||||||
var [libraryID, key] = libraryKey.split('_');
|
var [libraryID, key] = libraryKey.split('_');
|
||||||
|
if (!key) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
libraryID = parseInt(libraryID);
|
libraryID = parseInt(libraryID);
|
||||||
return {
|
return {
|
||||||
libraryID: libraryID ? libraryID : null,
|
libraryID: libraryID ? libraryID : null,
|
||||||
|
|
|
@ -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(){
|
function getAll(){
|
||||||
var sql = "SELECT savedSearchID AS id, savedSearchName AS name "
|
var sql = "SELECT savedSearchID AS id, savedSearchName AS name "
|
||||||
+ "FROM savedSearches ORDER BY name COLLATE NOCASE";
|
+ "FROM savedSearches ORDER BY name COLLATE NOCASE";
|
||||||
var searches = Zotero.DB.query(sql);
|
var rows = Zotero.DB.query(sql);
|
||||||
if (!searches) {
|
if (!rows) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do proper collation sort
|
// Do proper collation sort
|
||||||
var collation = Zotero.getLocaleCollation();
|
var collation = Zotero.getLocaleCollation();
|
||||||
searches.sort(function (a, b) {
|
rows.sort(function (a, b) {
|
||||||
return collation.compareString(1, a.name, b.name);
|
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;
|
return searches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,19 +104,72 @@ function ChromeExtensionHandler() {
|
||||||
|
|
||||||
switch (type){
|
switch (type){
|
||||||
case 'collection':
|
case 'collection':
|
||||||
|
var lkh = Zotero.Collections.parseLibraryKeyHash(ids);
|
||||||
|
if (lkh) {
|
||||||
|
var col = Zotero.Collections.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
||||||
|
}
|
||||||
|
else {
|
||||||
var col = Zotero.Collections.get(ids);
|
var col = Zotero.Collections.get(ids);
|
||||||
|
}
|
||||||
|
if (!col) {
|
||||||
|
mimeType = 'text/html';
|
||||||
|
content = 'Invalid collection ID or key';
|
||||||
|
break generateContent;
|
||||||
|
}
|
||||||
var results = col.getChildItems();
|
var results = col.getChildItems();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'search':
|
case 'search':
|
||||||
var s = new Zotero.Search();
|
var lkh = Zotero.Searches.parseLibraryKeyHash(ids);
|
||||||
s.id = ids;
|
if (lkh) {
|
||||||
ids = s.search();
|
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;
|
break;
|
||||||
|
|
||||||
case 'items':
|
case 'items':
|
||||||
case 'item':
|
case 'item':
|
||||||
ids = ids.split('-');
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -140,16 +193,7 @@ 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);
|
||||||
|
|
||||||
if (!results) {
|
|
||||||
mimeType = 'text/html';
|
|
||||||
content = 'Invalid ID';
|
|
||||||
break generateContent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = [];
|
var items = [];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user