Saved search fixes

- Fix saved search editing
- Refresh items list on search change
- Generate correct conditions array for search JSON
This commit is contained in:
Dan Stillman 2016-03-26 02:59:54 -04:00
parent 62f3177d36
commit b7b246e741
10 changed files with 157 additions and 20 deletions

View file

@ -222,15 +222,6 @@
</body>
</method>
<method name="save">
<body>
<![CDATA[
this.updateSearch();
return this.search.save();
]]>
</body>
</method>
<method name="handleKeyPress">
<parameter name="event"/>
<body>

View file

@ -23,6 +23,8 @@
***** END LICENSE BLOCK *****
*/
"use strict";
var itemsView;
var collectionsView;
var io;
@ -50,7 +52,11 @@ function doAccept()
{
document.getElementById('search-box').search.name = document.getElementById('search-name').value;
try {
io.dataOut = document.getElementById('search-box').save();
let searchBox = document.getElementById('search-box');
searchBox.updateSearch();
io.dataOut = {
json: searchBox.search.toJSON()
};
}
catch (e) {
Zotero.debug(e, 1);

View file

@ -55,7 +55,7 @@ Zotero.ItemTreeView = function (collectionTreeRow, sourcesOnly) {
this._unregisterID = Zotero.Notifier.registerObserver(
this,
['item', 'collection-item', 'item-tag', 'share-items', 'bucket', 'feedItem'],
['item', 'collection-item', 'item-tag', 'share-items', 'bucket', 'feedItem', 'search'],
'itemTreeView',
50
);
@ -348,8 +348,8 @@ Zotero.ItemTreeView.prototype.refresh = Zotero.serial(Zotero.Promise.coroutine(f
});
try {
var newItems = yield this.collectionTreeRow.getItems();
Zotero.CollectionTreeCache.clear();
var newItems = yield this.collectionTreeRow.getItems();
if (!this.selection.selectEventsSuppressed) {
var unsuppress = this.selection.selectEventsSuppressed = true;
@ -464,6 +464,14 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
return;
}
if (type == 'search' && action == 'modify') {
// TODO: Only refresh on condition change (not currently available in extraData)
yield this.refresh();
this.sort();
this._treebox.invalidate();
return;
}
// Clear item type icon and tag colors when a tag is added to or removed from an item
if (type == 'item-tag') {
// TODO: Only update if colored tag changed?
@ -757,7 +765,7 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
}
else if(type == 'item' && action == 'add')
{
let items = yield Zotero.Items.getAsync(ids);
let items = Zotero.Items.get(ids);
// In some modes, just re-run search
if (collectionTreeRow.isSearch() || collectionTreeRow.isTrash() || collectionTreeRow.isUnfiled()) {

View file

@ -447,6 +447,7 @@ Zotero.Search.prototype.removeCondition = function (searchConditionID) {
}
delete this._conditions[searchConditionID];
this._maxSearchConditionID--;
this._markFieldChange('conditions', this._conditions);
this._changed.conditions = true;
}
@ -827,6 +828,7 @@ Zotero.Search.prototype.fromJSON = function (json) {
}
this.name = json.name;
Object.keys(this.getConditions()).forEach(id => this.removeCondition(0));
for (let i = 0; i < json.conditions.length; i++) {
let condition = json.conditions[i];
this.addCondition(
@ -851,7 +853,8 @@ Zotero.Search.prototype.toJSON = function (options = {}) {
obj.key = this.key;
obj.version = this.version;
obj.name = this.name;
obj.conditions = this.getConditions();
var conditions = this.getConditions();
obj.conditions = Object.keys(conditions).map(x => conditions[x]);
return this._postToJSON(env);
}

View file

@ -1899,10 +1899,7 @@ var ZoteroPane = new function()
}
}
else {
let s = new Zotero.Search();
s.id = row.ref.id;
yield s.loadPrimaryData();
yield s.loadConditions();
let s = row.ref.clone();
let groups = [];
// Promises don't work in the modal dialog, so get the group name here, if
// applicable, and pass it in. We only need the group that this search belongs
@ -1920,7 +1917,8 @@ var ZoteroPane = new function()
};
window.openDialog('chrome://zotero/content/searchDialog.xul','','chrome,modal',io);
if (io.dataOut) {
this.onCollectionSelected(); //reload itemsView
row.ref.fromJSON(io.dataOut.json);
yield row.ref.saveTx();
}
}
}