Fixes #982, Reports do not properly sort notes about an item

- Notes and attachments are now properly sorted -- ?sort=note is no longer required for title sort, and sorting by columns other than title (e.g. dateModified) will work as expected for notes and attachments
- Item order of reports generated from a collection was reversed
- With certain combinations of combineChildItems and includeAllChildItems settings, top-level items without visible children weren't displayed
This commit is contained in:
Dan Stillman 2008-05-22 09:42:10 +00:00
parent 2d4c555938
commit 3e739f9152
3 changed files with 67 additions and 36 deletions

View File

@ -36,10 +36,10 @@ var Zotero_Report_Interface = new function() {
var id = ZoteroPane.getSelectedCollection(true); var id = ZoteroPane.getSelectedCollection(true);
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 + queryString = '?sort=' + sortColumn +
(sortDirection != 'ascending' ? '/d' : ''); (sortDirection != 'descending' ? '/d' : '');
} }
if (id) { if (id) {

View File

@ -1376,7 +1376,9 @@ Zotero.ItemTreeView.prototype.getSortField = function() {
/* /*
* Returns 'ascending' or 'descending' * Returns 'ascending' or 'descending'
* *
* A-Z == 'descending' * A-Z == 'descending', because Mozilla is confused
* (an upwards-facing triangle is A-Z on OS X and Windows,
* but Firefox uses the opposite)
*/ */
Zotero.ItemTreeView.prototype.getSortDirection = function() { Zotero.ItemTreeView.prototype.getSortDirection = function() {
var column = this._treebox.columns.getSortedColumn(); var column = this._treebox.columns.getSortedColumn();

View File

@ -142,6 +142,7 @@ function ChromeExtensionHandler() {
var includeAllChildItems = Zotero.Prefs.get('report.includeAllChildItems'); var includeAllChildItems = Zotero.Prefs.get('report.includeAllChildItems');
var combineChildItems = Zotero.Prefs.get('report.combineChildItems'); var combineChildItems = Zotero.Prefs.get('report.combineChildItems');
var unhandledParents = {};
for (var i=0; i<results.length; i++) { for (var i=0; i<results.length; i++) {
// Don't add child items directly // Don't add child items directly
// (instead mark their parents for inclusion below) // (instead mark their parents for inclusion below)
@ -155,12 +156,16 @@ function ChromeExtensionHandler() {
includeAllChildItems = false; includeAllChildItems = false;
} }
// If combining children or standalone note/attachment, add matching parents // If combining children or standalone note/attachment, add matching parents
else if (combineChildItems || !results[i].isRegularItem()) { else if (combineChildItems || !results[i].isRegularItem()
itemsHash[results[i].getID()] = items.length; || results[i].numChildren() == 0) {
itemsHash[results[i].getID()] = [items.length];
items.push(results[i].toArray(2)); items.push(results[i].toArray(2));
// Flag item as a search match // Flag item as a search match
items[items.length - 1].reportSearchMatch = true; items[items.length - 1].reportSearchMatch = true;
} }
else {
unhandledParents[i] = true;
}
searchItemIDs[results[i].getID()] = true; searchItemIDs[results[i].getID()] = true;
} }
@ -186,11 +191,21 @@ function ChromeExtensionHandler() {
} }
} }
} }
// If not including all children, add matching parents,
// in case they don't have any matching children below
else {
for (var i in unhandledParents) {
itemsHash[results[i].id] = [items.length];
items.push(results[i].toArray(2));
// Flag item as a search match
items[items.length - 1].reportSearchMatch = true;
}
}
if (combineChildItems) { if (combineChildItems) {
// Add parents of matches if parents aren't matches themselves // Add parents of matches if parents aren't matches themselves
for (var id in searchParentIDs) { for (var id in searchParentIDs) {
if (!searchItemIDs[id]) { if (!searchItemIDs[id] && !itemsHash[id]) {
var item = Zotero.Items.get(id); var item = Zotero.Items.get(id);
itemsHash[id] = items.length; itemsHash[id] = items.length;
items.push(item.toArray(2)); items.push(item.toArray(2));
@ -290,51 +305,65 @@ function ChromeExtensionHandler() {
// Multidimensional sort // Multidimensional sort
do { do {
// Note and attachment sorting when combineChildItems is false // In combineChildItems, use note or attachment as item
if (!combineChildItems && sorts[index].field == 'note') { if (!combineChildItems) {
if (a.itemType == 'note' || a.itemType == 'attachment') { if (a.reportChildren) {
var valA = a.note; if (a.reportChildren.notes.length) {
} a = a.reportChildren.notes[0];
else if (a.reportChildren) {
var valA = a.reportChildren.notes[0].note;
} }
else { else {
var valA = ''; a = a.reportChildren.attachments[0];
}
} }
if (b.itemType == 'note' || b.itemType == 'attachment') { if (b.reportChildren) {
var valB = b.note; if (b.reportChildren.notes.length) {
} b = b.reportChildren.notes[0];
else if (b.reportChildren) {
var valB = b.reportChildren.notes[0].note;
} }
else { else {
var valB = ''; b = b.reportChildren.attachments[0];
}
}
} }
// Put items without notes last var valA, valB;
if (valA == '' && valB != '') {
if (sorts[index].field == 'title') {
// For notes, use content for 'title'
if (a.itemType == 'note') {
valA = a.note;
}
else {
valA = a.title;
}
if (b.itemType == 'note') {
valB = b.note;
}
else {
valB = b.title;
}
}
else {
var valA = a[sorts[index].field];
var valB = b[sorts[index].field];
}
// Put empty values last
if (!valA && valB) {
var cmp = 1; var cmp = 1;
} }
else if (valA != '' && valB == '') { else if (valA && !valB) {
var cmp = -1; var cmp = -1;
} }
else { else {
var cmp = collation.compareString(0, valA, valB); var cmp = collation.compareString(0, valA, valB);
} }
}
else {
var cmp = collation.compareString(0,
a[sorts[index].field],
b[sorts[index].field]
);
}
if (cmp == 0) { var result = 0;
continue; if (cmp != 0) {
result = cmp * sorts[index].order;
} }
var result = cmp * sorts[index].order;
index++; index++;
} }
while (result == 0 && sorts[index]); while (result == 0 && sorts[index]);