From 0dbf98ccf4869e689588a473b8e9b8337d900658 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 16 Apr 2007 04:35:56 +0000 Subject: [PATCH] Fixes #616, Tags don't appear in tag selector for child items Also, child items in search results now always display in context, with the non-matching rows in gray. May later implement Elena's idea to show an ellipsis to toggle non-matching items. New method Search.setScope(searchObj) to pass one search as the scope for another -- used to make quicksearch and tag selector properly search within the current view. Note: These changes need testing -- I may not have gotten all the various conditions (view mode, quicksearch, tag selector, advanced search, drag-and-drop) exactly right. --- chrome/content/zotero/advancedSearch.js | 1 + .../zotero/xpcom/collectionTreeView.js | 70 ++++++++------- chrome/content/zotero/xpcom/data_access.js | 16 +++- chrome/content/zotero/xpcom/itemTreeView.js | 68 +++++++++++++-- chrome/content/zotero/xpcom/search.js | 87 ++++++++++++++++--- chrome/skin/default/zotero/overlay.css | 14 ++- 6 files changed, 199 insertions(+), 57 deletions(-) diff --git a/chrome/content/zotero/advancedSearch.js b/chrome/content/zotero/advancedSearch.js index 123bde53f2..b63b3f3198 100644 --- a/chrome/content/zotero/advancedSearch.js +++ b/chrome/content/zotero/advancedSearch.js @@ -27,6 +27,7 @@ var ZoteroAdvancedSearch = new function() { // A minimal implementation of Zotero.CollectionTreeView var itemGroup = { + isSearchMode: function() { return true; }, getChildItems: function () { var ids = _searchBox.search.search(); return Zotero.Items.get(ids); diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index a918ef161b..9a8df5cb1c 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -834,51 +834,42 @@ Zotero.ItemGroup.prototype.getChildItems = function() * This accounts for the collection, saved search, quicksearch, tags, etc. */ Zotero.ItemGroup.prototype.getSearchObject = function() { + // Create/load the inner search var s = new Zotero.Search(); - - if (this.searchText){ - if (this.isCollection()) - { - s.addCondition('collectionID', 'is', this.ref.getID()); - if (Zotero.Prefs.get('recursiveCollections')) { - s.addCondition('recursive', 'true'); - } - } - else if (this.isSearch()) - { - s.addCondition('savedSearchID', 'is', this.ref['id']); - } - s.addCondition('quicksearch', 'contains', this.searchText); + if (this.isLibrary()) { + s.addCondition('noChildren', true); } - else - { - if (this.isLibrary()){ - s.addCondition('noChildren', 'true'); - } - else if (this.isCollection()){ - s.addCondition('noChildren', 'true'); - s.addCondition('collectionID', 'is', this.ref.getID()); - if (Zotero.Prefs.get('recursiveCollections')) { - s.addCondition('recursive', 'true'); - } - } - else if (this.isSearch()){ - s.load(this.ref['id']); - } - else { - return null; + else if (this.isCollection()) { + s.addCondition('noChildren', true); + s.addCondition('collectionID', 'is', this.ref.getID()); + if (Zotero.Prefs.get('recursiveCollections')) { + s.addCondition('recursive', 'true'); } } + else if (this.isSearch()){ + s.load(this.ref['id']); + } + else { + throw ('Invalid search mode in Zotero.ItemGroup.getSearchObject()'); + } + + // Create the outer (filter) search + var s2 = new Zotero.Search(); + s2.setScope(s); + + if (this.searchText) { + s2.addCondition('quicksearch', 'contains', this.searchText); + } if (this.tags){ for (var tag in this.tags){ if (this.tags[tag]){ - s.addCondition('tag', 'is', tag); + s2.addCondition('tag', 'is', tag); } } } - return s; + return s2; } @@ -899,4 +890,17 @@ Zotero.ItemGroup.prototype.setSearch = function(searchText) Zotero.ItemGroup.prototype.setTags = function(tags) { this.tags = tags; +} + +/* + * Returns TRUE if using quicksearch or tag filter + */ +Zotero.ItemGroup.prototype.isSearchMode = function() { + if (this.tags) { + for (var i in this.tags) { + var hasTags = true; + break; + } + } + return this.searchText != '' || hasTags; } \ No newline at end of file diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index b446ecdb69..eed16f7365 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -3671,13 +3671,25 @@ Zotero.Tags = new function(){ var tags = Zotero.DB.query(sql); } else { + var sql = "CREATE TEMPORARY TABLE tmpSearchResults AS " + search.getSQL(); + Zotero.DB.query(sql, search.getSQLParams()); + sql = "CREATE INDEX tmpSearchResults_itemID ON tmpSearchResults(itemID)"; + Zotero.DB.query(sql); + var sql = "SELECT DISTINCT tagID, tag, tagType FROM itemTags " - + "NATURAL JOIN tags WHERE itemID IN (" + search.getSQL() + ") "; + + "NATURAL JOIN tags WHERE (" + + "itemID IN (SELECT itemID FROM tmpSearchResults) OR " + + "itemID IN (SELECT itemID FROM itemNotes WHERE sourceItemID IN (SELECT itemID FROM tmpSearchResults)) OR " + + "itemID IN (SELECT itemID FROM itemAttachments WHERE sourceItemID IN (SELECT itemID FROM tmpSearchResults))" + + ") "; if (types) { sql += "AND tagType IN (" + types.join() + ") "; } sql += "ORDER BY tag COLLATE NOCASE"; - var tags = Zotero.DB.query(sql, search.getSQLParams()); + var tags = Zotero.DB.query(sql); + + sql = "DROP TABLE tmpSearchResults"; + Zotero.DB.query(sql); } var indexed = {}; diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index c5d5ae10bc..b029e9c7e6 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -117,6 +117,7 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox) }, false); obj.sort(); + obj.expandMatchParents(); //Zotero.debug('Running callbacks in itemTreeView.setTree()', 4); obj._runCallbacks(); @@ -143,8 +144,12 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox) */ Zotero.ItemTreeView.prototype.refresh = function() { + this._searchMode = this._itemGroup.isSearchMode(); + var oldRows = this.rowCount; this._dataItems = []; + this._searchItemIDs = {}; // items matching the search + this._searchParentIDs = {}; this.rowCount = 0; var cacheFields = ['title', 'date']; @@ -156,7 +161,8 @@ Zotero.ItemTreeView.prototype.refresh = function() catch (e) { return; } - for each(var field in visibleFields) { + for (var i=0; i