From a452af6c3a3a2f007510fbb8bd507ccc65c1177f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 21 Jul 2015 00:44:38 -0400 Subject: [PATCH] Sort descendant collections alphabetically in advanced search window https://forums.zotero.org/discussion/50679/ --- .../content/zotero/bindings/zoterosearch.xml | 240 +++++++++--------- .../content/zotero/xpcom/data/collection.js | 8 +- test/tests/collectionsTest.js | 30 ++- 3 files changed, 149 insertions(+), 129 deletions(-) diff --git a/chrome/content/zotero/bindings/zoterosearch.xml b/chrome/content/zotero/bindings/zoterosearch.xml index 4b34ca102..f6d0e57cb 100644 --- a/chrome/content/zotero/bindings/zoterosearch.xml +++ b/chrome/content/zotero/bindings/zoterosearch.xml @@ -405,130 +405,130 @@ ]]> - - - + // Textbox + else { + // If switching from menu to textbox, clear value + if (this.id('valuefield').hidden){ + this.id('valuefield').value = ''; + } + // If switching between textbox conditions, get loaded value for new one + else { + this.id('valuefield').value = this.value; + } + + // Update field drop-down if applicable + this.id('valuefield').update(conditionsMenu.value, this.mode); + } + } + + this.onOperatorSelected(); + }.bind(this)); + ]]> @@ -597,8 +597,8 @@ - - - + }.bind(this)); + ]]> diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 9bc59477d..61e38fe31 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -690,17 +690,21 @@ Zotero.Collection.prototype.getChildren = Zotero.Promise.coroutine(function* (re // 0 == collection // 1 == item - var sql = 'SELECT collectionID AS id, ' + var sql = 'SELECT collectionID AS id, collectionName AS name, ' + "0 AS type, collectionName AS collectionName, key " + 'FROM collections WHERE parentCollectionID=?1'; if (!type || type == 'item') { - sql += ' UNION SELECT itemID AS id, 1 AS type, NULL AS collectionName, key ' + sql += ' UNION SELECT itemID AS id, NULL AS name, 1 AS type, NULL AS collectionName, key ' + 'FROM collectionItems JOIN items USING (itemID) WHERE collectionID=?1'; if (!includeDeletedItems) { sql += " AND itemID NOT IN (SELECT itemID FROM deletedItems)"; } } var children = yield Zotero.DB.queryAsync(sql, this.id); + children.sort(function (a, b) { + if (a.name === null || b.name === null) return 0; + return Zotero.localeCompare(a.name, b.name) + }); for(var i=0, len=children.length; i col.id), [col1.id, col2.id, col3.id]); - assert.ok(cols.every(col => col.libraryID == Zotero.Libraries.userLibraryID)); + yield createDataObject('collection', { libraryID: (yield getGroup()).libraryID }); + + var libraryID = Zotero.Libraries.userLibraryID; + var col1 = yield createDataObject('collection', { name: "C" }); + var col2 = yield createDataObject('collection', { name: "A" }); + var col3 = yield createDataObject('collection', { name: "D", parentID: col2.id }); + var col4 = yield createDataObject('collection', { name: "B", parentID: col2.id }); + var col5 = yield createDataObject('collection', { name: "E", parentID: col2.id }); + var col6 = yield createDataObject('collection', { name: "G", parentID: col3.id }); + var col7 = yield createDataObject('collection', { name: "F", parentID: col3.id }); + var cols = yield Zotero.Collections.getByLibrary(libraryID, true); + assert.isAbove(cols.length, 6); + var ids = cols.map(col => col.id); + assert.includeMembers( + ids, [col1.id, col2.id, col3.id, col4.id, col5.id, col6.id, col7.id] + ); + assert.isBelow(ids.indexOf(col2.id), ids.indexOf(col4.id), "A before child B"); + assert.isBelow(ids.indexOf(col4.id), ids.indexOf(col3.id), "B before D"); + assert.isBelow(ids.indexOf(col3.id), ids.indexOf(col7.id), "D before child F"); + assert.isBelow(ids.indexOf(col7.id), ids.indexOf(col6.id), "F before G"); + assert.isBelow(ids.indexOf(col6.id), ids.indexOf(col5.id), "G before D sibling E"); + assert.isBelow(ids.indexOf(col5.id), ids.indexOf(col1.id), "E before A sibling C"); + assert.ok(cols.every(col => col.libraryID == libraryID)); }) })