open-vault/ui/app/mixins/list-controller.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

import { computed } from '@ember/object';
import Mixin from '@ember/object/mixin';
import escapeStringRegexp from 'escape-string-regexp';
2018-04-03 14:16:57 +00:00
export default Mixin.create({
2018-04-03 14:16:57 +00:00
queryParams: {
page: 'page',
pageFilter: 'pageFilter',
},
page: 1,
pageFilter: null,
filter: null,
filterFocused: false,
2018-04-03 14:16:57 +00:00
isLoading: false,
filterMatchesKey: computed('filter', 'model', 'model.[]', function() {
2018-04-03 14:16:57 +00:00
var filter = this.get('filter');
var content = this.get('model');
return !!(content.length && content.findBy('id', filter));
}),
firstPartialMatch: computed('filter', 'model', 'model.[]', 'filterMatchesKey', function() {
2018-04-03 14:16:57 +00:00
var filter = this.get('filter');
var content = this.get('model');
var filterMatchesKey = this.get('filterMatchesKey');
var re = new RegExp('^' + escapeStringRegexp(filter));
2018-04-03 14:16:57 +00:00
return filterMatchesKey
? null
: content.find(function(key) {
return re.test(key.get('id'));
});
}),
actions: {
setFilter(val) {
this.set('filter', val);
},
setFilterFocus(bool) {
this.set('filterFocused', bool);
},
},
});