2017-06-29 04:56:44 +08:00
|
|
|
import debounce from 'discourse/lib/debounce';
|
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
|
|
|
filter: null,
|
|
|
|
filtered: false,
|
|
|
|
showWords: false,
|
|
|
|
disableShowWords: Ember.computed.alias('filtered'),
|
2017-09-28 03:48:57 +08:00
|
|
|
regularExpressions: null,
|
2017-06-29 04:56:44 +08:00
|
|
|
|
|
|
|
filterContentNow() {
|
|
|
|
|
|
|
|
if (!!Ember.isEmpty(this.get('allWatchedWords'))) return;
|
|
|
|
|
|
|
|
let filter;
|
|
|
|
if (this.get('filter')) {
|
|
|
|
filter = this.get('filter').toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter === undefined || filter.length < 1) {
|
|
|
|
this.set('model', this.get('allWatchedWords'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const matchesByAction = [];
|
|
|
|
|
|
|
|
this.get('allWatchedWords').forEach(wordsForAction => {
|
|
|
|
const wordRecords = wordsForAction.words.filter(wordRecord => {
|
|
|
|
return (wordRecord.word.indexOf(filter) > -1);
|
|
|
|
});
|
|
|
|
matchesByAction.pushObject( Ember.Object.create({
|
|
|
|
nameKey: wordsForAction.nameKey,
|
|
|
|
name: wordsForAction.name,
|
|
|
|
words: wordRecords,
|
|
|
|
count: wordRecords.length
|
|
|
|
}) );
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('model', matchesByAction);
|
|
|
|
},
|
|
|
|
|
|
|
|
filterContent: debounce(function() {
|
|
|
|
this.filterContentNow();
|
|
|
|
this.set('filtered', !Ember.isEmpty(this.get('filter')));
|
|
|
|
}, 250).observes('filter'),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
clearFilter() {
|
|
|
|
this.setProperties({ filter: '' });
|
2018-05-25 23:13:34 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleMenu() {
|
|
|
|
$('.admin-detail').toggleClass('mobile-closed mobile-open');
|
2017-06-29 04:56:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|