Fix syncing of saved search changes

Condition changes were only uploaded after every other change + sync
This commit is contained in:
Dan Stillman 2018-04-22 17:27:33 -04:00
parent 7c093b4fb0
commit 33f8fcfafb
3 changed files with 47 additions and 8 deletions

View File

@ -234,14 +234,9 @@ Zotero.DataObjectUtilities = {
},
_conditionsChanged: function (data1, data2) {
if (!data2) return true;
var pred1 = Object.keys(data1);
pred1.sort();
var pred2 = Object.keys(data2);
pred2.sort();
if (!Zotero.Utilities.arrayEquals(pred1, pred2)) return false;
for (let i in pred1) {
if (!Zotero.Utilities.arrayEquals(pred1[i], pred2[i])) {
if (!data2 || data1.length != data2.length) return true;
for (let i = 0; i < data1.length; i++) {
if (!Zotero.Searches.conditionEquals(data1[i], data2[i])) {
return true;
}
}

View File

@ -96,6 +96,13 @@ Zotero.Searches = function() {
}
this.conditionEquals = function (data1, data2) {
return data1.condition === data2.condition
&& data1.operator === data2.operator
&& data1.value === data2.value;
},
this._loadConditions = Zotero.Promise.coroutine(function* (libraryID, ids, idSQL) {
var sql = "SELECT savedSearchID, searchConditionID, condition, operator, value, required "
+ "FROM savedSearches LEFT JOIN savedSearchConditions USING (savedSearchID) "

View File

@ -10,6 +10,43 @@ describe("Zotero.DataObjectUtilities", function() {
obj = Zotero.DataObjectUtilities.patch(patchBase, obj);
assert.notProperty(obj, 'collections');
})
it("should include modified 'conditions'", function* () {
var patchBase = {
name: "Search",
conditions: [
{
condition: 'title',
operator: 'is',
value: 'A'
},
{
condition: 'language',
operator: 'is',
value: 'en'
}
]
};
var obj = {
name: "Search",
conditions: [
{
condition: 'title',
operator: 'is',
value: 'B'
},
{
condition: 'language',
operator: 'is',
value: 'en'
}
]
};
obj = Zotero.DataObjectUtilities.patch(patchBase, obj);
assert.property(obj, 'conditions');
assert.equal(obj.conditions[0].value, 'B');
assert.equal(obj.conditions[1].value, 'en');
})
})
describe("#diff()", function () {