Skip to content

Commit

Permalink
Merge branch 'filtering' into 'master'
Browse files Browse the repository at this point in the history
Filtering

See merge request mistio/mist-list!23
  • Loading branch information
d-mo committed Jun 10, 2018
2 parents 00626e2 + 62d6b73 commit 736a1f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mist-list",
"version": "1.4.8",
"version": "1.4.9",
"authors": [
"Dimitris Moraitis <[email protected]>",
"Christina Papakonstantinou <[email protected]>"
Expand Down
55 changes: 38 additions & 17 deletions mist-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ <h2>Download list data in CSV</h2>
Polymer({
is: 'mist-list',
properties: {
user: String,
members: Array,
apiurl: {
type: String
},
Expand Down Expand Up @@ -527,6 +529,13 @@ <h2>Download list data in CSV</h2>
type: Array
},

filterMethod: {
type: Object,
value: function () {
return {}
}
},

renderers: {
type: Object,
value: function () {
Expand Down Expand Up @@ -689,7 +698,7 @@ <h2>Download list data in CSV</h2>

observers: [
'_itemsUpdated(items)',
'_filterItems(items, items.length, combinedFilter)',
'_filterItems(items, items.length, combinedFilter, filterMethod)',
'windowResize(filteredItems.length, route.path)',
'selectedItemsChanged(selectedItems.length)',
'toggleSelectAll(selectAll)',
Expand Down Expand Up @@ -798,7 +807,7 @@ <h2>Download list data in CSV</h2>
localStorage.setItem('mist-list#' + this.id + '/col/' + column + '/width', e.target.style.width);
},

_filterItems: function (items, length, filter) {
_filterItems: function (items, length, filter, filterMethod) {
console.warn('filterItems', filter);
this.set('filteredItems', this.items.filter(this.applyFilter.bind(this)));
this.fire('mist-list-filtered-items-length-changed', {
Expand Down Expand Up @@ -833,22 +842,34 @@ <h2>Download list data in CSV</h2>
},

applyFilter: function (item, index) {
// TODO: properly filter parenthesis
var queryTerms = this.combinedFilter.replace(/\(/g, '').replace(/\)/g, '').replace(/ AND /g,
' ').replace(/ OR /g, ' ').split(' ');

// Check if all terms exist in item
for (var i = 0; i < queryTerms.length; i++) {
if (queryTerms[i] && queryTerms[i].length)
if (queryTerms[i].indexOf(':') > -1) {
var kv = queryTerms[i].split(':'),
k = kv[0],
v = kv[1];
if (item[k] != v)
return false;
} else if (this._getRenderedItem(item).toLowerCase().indexOf(queryTerms[i].toLowerCase()) <
0) {
var q = this.combinedFilter ? this.combinedFilter.slice(0) : '',
queryTerms;
if (this.filterMethod.apply) {
var response = this.filterMethod.apply(item,q);
// response can be false or a query stripped of owner filter
if (response === false)
return false;
else
q = this.filterMethod.apply(item,q);
}
if (q.length) {
// TODO: properly filter parenthesis
queryTerms = q.replace(/\(/g, '').replace(/\)/g, '').replace(/ AND /g,
' ').replace(/ OR /g, ' ').split(' ');

// Check if all terms exist in item
for (var i = 0; i < queryTerms.length; i++) {
if (queryTerms[i] && queryTerms[i].length)
if (queryTerms[i].indexOf(':') > -1) {
var kv = queryTerms[i].split(':'),
k = kv[0],
v = kv[1];
if (item[k] != v)
return false;
} else if (this._getRenderedItem(item).toLowerCase().indexOf(queryTerms[i].toLowerCase()) <
0) {
return false;
}
}
}
return true;
Expand Down

0 comments on commit 736a1f9

Please sign in to comment.