Fix sorting by editor in Creator column (since 5.0.78)
This commit is contained in:
parent
851af7f45b
commit
eec0f00784
1 changed files with 52 additions and 61 deletions
|
@ -1359,11 +1359,14 @@ Zotero.Items = function() {
|
||||||
return _sortCreatorSQL;
|
return _sortCreatorSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var editorCreatorTypeID = Zotero.CreatorTypes.getID('editor');
|
||||||
|
var contributorCreatorTypeID = Zotero.CreatorTypes.getID('contributor');
|
||||||
|
|
||||||
var nameSQL = "lastName || ' ' || firstName ";
|
var nameSQL = "lastName || ' ' || firstName ";
|
||||||
|
|
||||||
var sql = "COALESCE(" +
|
var sql = "COALESCE("
|
||||||
// First try for primary creator types
|
// First try for primary creator types
|
||||||
"CASE (" +
|
+ "CASE (" +
|
||||||
"SELECT COUNT(*) FROM itemCreators IC " +
|
"SELECT COUNT(*) FROM itemCreators IC " +
|
||||||
"LEFT JOIN itemTypeCreatorTypes ITCT " +
|
"LEFT JOIN itemTypeCreatorTypes ITCT " +
|
||||||
"ON (IC.creatorTypeID=ITCT.creatorTypeID AND ITCT.itemTypeID=O.itemTypeID) " +
|
"ON (IC.creatorTypeID=ITCT.creatorTypeID AND ITCT.itemTypeID=O.itemTypeID) " +
|
||||||
|
@ -1404,69 +1407,57 @@ Zotero.Items = function() {
|
||||||
"LEFT JOIN itemTypeCreatorTypes ITCT " +
|
"LEFT JOIN itemTypeCreatorTypes ITCT " +
|
||||||
"ON (IC.creatorTypeID=ITCT.creatorTypeID AND ITCT.itemTypeID=O.itemTypeID) " +
|
"ON (IC.creatorTypeID=ITCT.creatorTypeID AND ITCT.itemTypeID=O.itemTypeID) " +
|
||||||
"WHERE itemID=O.itemID AND primaryField=1 ORDER BY orderIndex LIMIT 2,1)" +
|
"WHERE itemID=O.itemID AND primaryField=1 ORDER BY orderIndex LIMIT 2,1)" +
|
||||||
") " +
|
") "
|
||||||
"END, " +
|
+ "END, "
|
||||||
|
|
||||||
// Then try editors
|
// Then try editors
|
||||||
"CASE (" +
|
+ "CASE ("
|
||||||
"SELECT COUNT(*) FROM itemCreators WHERE itemID=O.itemID AND creatorTypeID IN (3)" +
|
+ "SELECT COUNT(*) FROM itemCreators "
|
||||||
") " +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${editorCreatorTypeID}`
|
||||||
"WHEN 0 THEN NULL " +
|
+ ") "
|
||||||
"WHEN 1 THEN (" +
|
+ "WHEN 0 THEN NULL "
|
||||||
"SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
+ "WHEN 1 THEN ("
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (3)" +
|
+ "SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators "
|
||||||
") " +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${editorCreatorTypeID}`
|
||||||
"WHEN 2 THEN (" +
|
+ ") "
|
||||||
"SELECT " +
|
+ "END, "
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (3) ORDER BY orderIndex LIMIT 1)" +
|
|
||||||
" || ' ' || " +
|
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (3) ORDER BY orderIndex LIMIT 1,1) " +
|
|
||||||
") " +
|
|
||||||
"ELSE (" +
|
|
||||||
"SELECT " +
|
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (3) ORDER BY orderIndex LIMIT 1)" +
|
|
||||||
" || ' ' || " +
|
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (3) ORDER BY orderIndex LIMIT 1,1)" +
|
|
||||||
" || ' ' || " +
|
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (3) ORDER BY orderIndex LIMIT 2,1)" +
|
|
||||||
") " +
|
|
||||||
"END, " +
|
|
||||||
|
|
||||||
// Then try contributors
|
// Then try contributors
|
||||||
"CASE (" +
|
+ "CASE ("
|
||||||
"SELECT COUNT(*) FROM itemCreators WHERE itemID=O.itemID AND creatorTypeID IN (2)" +
|
+ "SELECT COUNT(*) FROM itemCreators "
|
||||||
") " +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${contributorCreatorTypeID}`
|
||||||
"WHEN 0 THEN NULL " +
|
+ ") "
|
||||||
"WHEN 1 THEN (" +
|
+ "WHEN 0 THEN NULL "
|
||||||
"SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
+ "WHEN 1 THEN ("
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (2)" +
|
+ "SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators "
|
||||||
") " +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${contributorCreatorTypeID}`
|
||||||
"WHEN 2 THEN (" +
|
+ ") "
|
||||||
"SELECT " +
|
+ "WHEN 2 THEN ("
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
+ "SELECT "
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (2) ORDER BY orderIndex LIMIT 1)" +
|
+ "(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators "
|
||||||
" || ' ' || " +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${contributorCreatorTypeID} `
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
+ "ORDER BY orderIndex LIMIT 1)"
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (2) ORDER BY orderIndex LIMIT 1,1) " +
|
+ " || ' ' || "
|
||||||
") " +
|
+ "(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators "
|
||||||
"ELSE (" +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${contributorCreatorTypeID} `
|
||||||
"SELECT " +
|
+ "ORDER BY orderIndex LIMIT 1,1) "
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
+ ") "
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (2) ORDER BY orderIndex LIMIT 1)" +
|
+ "ELSE ("
|
||||||
" || ' ' || " +
|
+ "SELECT "
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
+ "(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators "
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (2) ORDER BY orderIndex LIMIT 1,1)" +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${contributorCreatorTypeID} `
|
||||||
" || ' ' || " +
|
+ "ORDER BY orderIndex LIMIT 1)"
|
||||||
"(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators " +
|
+ " || ' ' || "
|
||||||
"WHERE itemID=O.itemID AND creatorTypeID IN (2) ORDER BY orderIndex LIMIT 2,1)" +
|
+ "(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators "
|
||||||
") " +
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${contributorCreatorTypeID} `
|
||||||
"END" +
|
+ "ORDER BY orderIndex LIMIT 1,1)"
|
||||||
") AS sortCreator";
|
+ " || ' ' || "
|
||||||
|
+ "(SELECT " + nameSQL + " FROM itemCreators NATURAL JOIN creators "
|
||||||
|
+ `WHERE itemID=O.itemID AND creatorTypeID=${contributorCreatorTypeID} `
|
||||||
|
+ "ORDER BY orderIndex LIMIT 2,1)"
|
||||||
|
+ ") "
|
||||||
|
+ "END"
|
||||||
|
+ ") AS sortCreator";
|
||||||
|
|
||||||
_sortCreatorSQL = sql;
|
_sortCreatorSQL = sql;
|
||||||
return sql;
|
return sql;
|
||||||
|
|
Loading…
Add table
Reference in a new issue