@@ -5,36 +5,13 @@ import { computed } from '@ember/object';
55
66export default Controller . extend ( {
77 store : service ( ) ,
8- queryParams : [ 'page' , 'limit' ] ,
8+ queryParams : [ 'page' , 'limit' , 'filter' , 'filterTagsParam' ] ,
99 page : 1 ,
1010 limit : 10 ,
11- searchString : '' ,
11+ filter : '' ,
1212 pageCount : computed ( 'limit' , 'questions' , function ( ) {
1313 return Math . ceil ( this . questions . meta . pagination . count / this . limit )
1414 } ) ,
15- searchTask : task ( function * ( ) {
16- yield timeout ( 250 )
17-
18- let searchStr = this . get ( 'searchString' ) . trim ( )
19- let selectedTags = [ ]
20-
21- if ( this . get ( 'filterTags' ) ) {
22- selectedTags = this . get ( 'filterTags' )
23- selectedTags = selectedTags . map ( t => + t . id )
24- }
25-
26- const questions = yield this . get ( 'store' ) . query ( 'question' , {
27- include : 'user' ,
28- filter : {
29- title : {
30- $iLike : `%${ this . get ( 'searchString' ) } %`
31- } ,
32- tags : selectedTags
33- }
34- } )
35- this . set ( 'page' , 1 )
36- this . set ( 'questions' , questions )
37- } ) . restartable ( ) ,
3815 tagsFilterTask : task ( function * ( str ) {
3916 yield timeout ( 250 )
4017 const tags = yield this . get ( 'store' ) . query ( 'tag' , {
@@ -47,6 +24,10 @@ export default Controller.extend({
4724 return tags . toArray ( )
4825 } ) ,
4926 actions : {
27+ selectTags ( tags ) {
28+ this . set ( 'filterTagsParam' , tags . length ? tags . mapBy ( 'id' ) . reduce ( ( acc , val ) => acc + ',' + val ) : '' )
29+ this . set ( 'filterTags' , tags )
30+ } ,
5031 deleteQuestion ( question ) {
5132 question . destroyRecord ( )
5233 }
0 commit comments