Skip to content

Commit

Permalink
Merge pull request #326 from owncloud/fix-search-in-adr
Browse files Browse the repository at this point in the history
Fix search in address field - fixes #325
  • Loading branch information
jancborchardt committed Mar 31, 2016
2 parents 9a73f34 + 753172e commit babdcb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js/models/contact_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,17 @@ angular.module('contactsApp')
var matchingProps = ['fn', 'title', 'org', 'email', 'nickname', 'note', 'url', 'cloud', 'adr', 'impp', 'tel'].filter(function (propName) {
if (model.props[propName]) {
return model.props[propName].filter(function (property) {
if (property.value && _.isString(property.value)) {
if (!property.value) {
return false;
}
if (_.isString(property.value)) {
return property.value.toLowerCase().indexOf(pattern.toLowerCase()) !== -1;
}
if (_.isArray(property.value)) {
return property.value.filter(function(v) {
return v.toLowerCase().indexOf(pattern.toLowerCase()) !== -1;
}).length > 0;
}
return false;
}).length > 0;
}
Expand Down
7 changes: 7 additions & 0 deletions js/tests/models/contact_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ describe('contactModel', function() {
expect(contact.matches('the')).to.equal(true);
expect(contact.matches('OSS')).to.equal(true);
});

it('should match a search pattern in address', function() {
var contact = new $Contact({displayName: 'test'});
contact.setProperty('adr', {value: ["12", "", "", "Kenya", "", "", ""]});
expect(contact.matches('12')).to.equal(true);
expect(contact.matches('kenya')).to.equal(true);
});
});

0 comments on commit babdcb4

Please sign in to comment.