Fix syncing of search conditions
This commit is contained in:
parent
2225f459b7
commit
8e0e69332e
2 changed files with 21 additions and 6 deletions
|
@ -836,7 +836,7 @@ Zotero.Search.prototype.fromJSON = function (json) {
|
|||
}
|
||||
}
|
||||
|
||||
Zotero.Collection.prototype.toResponseJSON = function (options = {}) {
|
||||
Zotero.Search.prototype.toResponseJSON = function (options = {}) {
|
||||
var json = this.constructor._super.prototype.toResponseJSON.apply(this, options);
|
||||
return json;
|
||||
};
|
||||
|
@ -851,8 +851,14 @@ Zotero.Search.prototype.toJSON = function (options = {}) {
|
|||
obj.version = this.version;
|
||||
obj.name = this.name;
|
||||
var conditions = this.getConditions();
|
||||
obj.conditions = Object.keys(conditions).map(x => conditions[x]);
|
||||
|
||||
obj.conditions = Object.keys(conditions)
|
||||
.map(x => ({
|
||||
condition: conditions[x].condition
|
||||
+ (conditions[x].mode !== false ? "/" + conditions[x].mode : ""),
|
||||
operator: conditions[x].operator,
|
||||
// TODO: Change joinMode to use 'is' + 'any' instead of operator 'any'?
|
||||
value: conditions[x].value ? conditions[x].value : ""
|
||||
}));
|
||||
return this._postToJSON(env);
|
||||
}
|
||||
|
||||
|
|
|
@ -195,15 +195,24 @@ describe("Zotero.Search", function() {
|
|||
let s = new Zotero.Search();
|
||||
s.name = "Test";
|
||||
s.addCondition('joinMode', 'any');
|
||||
s.addCondition('fulltextWord', 'contains', 'afsgagsdg');
|
||||
s.addCondition('fulltextContent/regexp', 'contains', 's.+');
|
||||
let json = s.toJSON();
|
||||
assert.equal(json.name, "Test");
|
||||
|
||||
assert.lengthOf(json.conditions, 2);
|
||||
|
||||
assert.equal(json.conditions[0].condition, 'joinMode');
|
||||
assert.equal(json.conditions[0].operator, 'any');
|
||||
assert.equal(json.conditions[1].condition, 'fulltextWord');
|
||||
// TODO: Change to 'is' + 'any'?
|
||||
assert.strictEqual(json.conditions[0].value, '');
|
||||
assert.notProperty(json.conditions[0], 'id');
|
||||
assert.notProperty(json.conditions[0], 'required');
|
||||
assert.notProperty(json.conditions[0], 'mode');
|
||||
|
||||
assert.equal(json.conditions[1].condition, 'fulltextContent/regexp');
|
||||
assert.equal(json.conditions[1].operator, 'contains');
|
||||
assert.equal(json.conditions[1].value, 'afsgagsdg');
|
||||
assert.equal(json.conditions[1].value, 's.+');
|
||||
assert.notProperty(json.conditions[1], 'mode');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue