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:
parent
2d4c555938
commit
3e739f9152
|
@ -36,10 +36,10 @@ var Zotero_Report_Interface = new function() {
|
|||
var id = ZoteroPane.getSelectedCollection(true);
|
||||
var sortColumn = ZoteroPane.getSortField();
|
||||
var sortDirection = ZoteroPane.getSortDirection();
|
||||
|
||||
if (sortColumn != 'title' || sortDirection != 'ascending') {
|
||||
// See note re: 'ascending'/'descending' for ItemTreeView.getSortDirection()
|
||||
if (sortColumn != 'title' || sortDirection != 'descending') {
|
||||
queryString = '?sort=' + sortColumn +
|
||||
(sortDirection != 'ascending' ? '/d' : '');
|
||||
(sortDirection != 'descending' ? '/d' : '');
|
||||
}
|
||||
|
||||
if (id) {
|
||||
|
|
|
@ -1376,7 +1376,9 @@ Zotero.ItemTreeView.prototype.getSortField = function() {
|
|||
/*
|
||||
* 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() {
|
||||
var column = this._treebox.columns.getSortedColumn();
|
||||
|
|
|
@ -142,6 +142,7 @@ function ChromeExtensionHandler() {
|
|||
var includeAllChildItems = Zotero.Prefs.get('report.includeAllChildItems');
|
||||
var combineChildItems = Zotero.Prefs.get('report.combineChildItems');
|
||||
|
||||
var unhandledParents = {};
|
||||
for (var i=0; i<results.length; i++) {
|
||||
// Don't add child items directly
|
||||
// (instead mark their parents for inclusion below)
|
||||
|
@ -155,12 +156,16 @@ function ChromeExtensionHandler() {
|
|||
includeAllChildItems = false;
|
||||
}
|
||||
// If combining children or standalone note/attachment, add matching parents
|
||||
else if (combineChildItems || !results[i].isRegularItem()) {
|
||||
itemsHash[results[i].getID()] = items.length;
|
||||
else if (combineChildItems || !results[i].isRegularItem()
|
||||
|| results[i].numChildren() == 0) {
|
||||
itemsHash[results[i].getID()] = [items.length];
|
||||
items.push(results[i].toArray(2));
|
||||
// Flag item as a search match
|
||||
items[items.length - 1].reportSearchMatch = true;
|
||||
}
|
||||
else {
|
||||
unhandledParents[i] = 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) {
|
||||
// Add parents of matches if parents aren't matches themselves
|
||||
for (var id in searchParentIDs) {
|
||||
if (!searchItemIDs[id]) {
|
||||
if (!searchItemIDs[id] && !itemsHash[id]) {
|
||||
var item = Zotero.Items.get(id);
|
||||
itemsHash[id] = items.length;
|
||||
items.push(item.toArray(2));
|
||||
|
@ -290,51 +305,65 @@ function ChromeExtensionHandler() {
|
|||
|
||||
// Multidimensional sort
|
||||
do {
|
||||
// Note and attachment sorting when combineChildItems is false
|
||||
if (!combineChildItems && sorts[index].field == 'note') {
|
||||
if (a.itemType == 'note' || a.itemType == 'attachment') {
|
||||
var valA = a.note;
|
||||
}
|
||||
else if (a.reportChildren) {
|
||||
var valA = a.reportChildren.notes[0].note;
|
||||
}
|
||||
else {
|
||||
var valA = '';
|
||||
// In combineChildItems, use note or attachment as item
|
||||
if (!combineChildItems) {
|
||||
if (a.reportChildren) {
|
||||
if (a.reportChildren.notes.length) {
|
||||
a = a.reportChildren.notes[0];
|
||||
}
|
||||
else {
|
||||
a = a.reportChildren.attachments[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (b.itemType == 'note' || b.itemType == 'attachment') {
|
||||
var valB = b.note;
|
||||
if (b.reportChildren) {
|
||||
if (b.reportChildren.notes.length) {
|
||||
b = b.reportChildren.notes[0];
|
||||
}
|
||||
else {
|
||||
b = b.reportChildren.attachments[0];
|
||||
}
|
||||
}
|
||||
else if (b.reportChildren) {
|
||||
var valB = b.reportChildren.notes[0].note;
|
||||
}
|
||||
|
||||
var valA, valB;
|
||||
|
||||
if (sorts[index].field == 'title') {
|
||||
// For notes, use content for 'title'
|
||||
if (a.itemType == 'note') {
|
||||
valA = a.note;
|
||||
}
|
||||
else {
|
||||
var valB = '';
|
||||
valA = a.title;
|
||||
}
|
||||
|
||||
// Put items without notes last
|
||||
if (valA == '' && valB != '') {
|
||||
var cmp = 1;
|
||||
}
|
||||
else if (valA != '' && valB == '') {
|
||||
var cmp = -1;
|
||||
if (b.itemType == 'note') {
|
||||
valB = b.note;
|
||||
}
|
||||
else {
|
||||
var cmp = collation.compareString(0, valA, valB);
|
||||
valB = b.title;
|
||||
}
|
||||
}
|
||||
else {
|
||||
var cmp = collation.compareString(0,
|
||||
a[sorts[index].field],
|
||||
b[sorts[index].field]
|
||||
);
|
||||
var valA = a[sorts[index].field];
|
||||
var valB = b[sorts[index].field];
|
||||
}
|
||||
|
||||
if (cmp == 0) {
|
||||
continue;
|
||||
// Put empty values last
|
||||
if (!valA && valB) {
|
||||
var cmp = 1;
|
||||
}
|
||||
else if (valA && !valB) {
|
||||
var cmp = -1;
|
||||
}
|
||||
else {
|
||||
var cmp = collation.compareString(0, valA, valB);
|
||||
}
|
||||
|
||||
var result = cmp * sorts[index].order;
|
||||
var result = 0;
|
||||
if (cmp != 0) {
|
||||
result = cmp * sorts[index].order;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
while (result == 0 && sorts[index]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user