File tree Expand file tree Collapse file tree 10 files changed +76
-3
lines changed
components/question-editor Expand file tree Collapse file tree 10 files changed +76
-3
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ export default DS.Model.extend({
55 description : DS . attr ( ) ,
66 difficulty : DS . attr ( ) ,
77 user : DS . belongsTo ( 'user' ) ,
8- choices : DS . hasMany ( 'choice' )
8+ choices : DS . hasMany ( 'choice' ) ,
9+ tags : DS . hasMany ( 'tag' )
910} )
Original file line number Diff line number Diff line change 1+ import DS from "ember-data" ;
2+
3+ export default DS . Model . extend ( {
4+ title : DS . attr ( ) ,
5+ user : DS . belongsTo ( 'user' ) ,
6+ questions : DS . hasMany ( 'question' )
7+ } )
Original file line number Diff line number Diff line change 11import Component from '@ember/component' ;
22import { inject as service } from '@ember/service' ;
3+ import { task , timeout } from 'ember-concurrency' ;
34
45export default Component . extend ( {
56 store : service ( ) ,
67 api : service ( ) ,
78 notify : service ( ) ,
89 isEditing : false ,
10+ tagsFilterTask : task ( function * ( str ) {
11+ yield timeout ( 250 )
12+ const tags = yield this . get ( 'store' ) . query ( 'tag' , {
13+ filter : {
14+ title : {
15+ $iLike : `%${ str } %`
16+ }
17+ }
18+ } )
19+ return tags . toArray ( )
20+ } ) ,
921 actions : {
1022 toggleEditing ( ) {
1123 this . toggleProperty ( 'isEditing' )
Original file line number Diff line number Diff line change 5050 {{ /each }}
5151 </ul >
5252
53+ <div class =" row" >
54+ <div class =" col-2" >
55+ <label >Tags</label >
56+ </div >
57+ <div class =" col-6" >
58+ {{ #power-select-multiple
59+ search = (perform tagsFilterTask )
60+ selected =question.tags
61+ placeholder =" Add tags for this question"
62+ onchange = (action (mut question.tags ))
63+ as |tag |}}
64+ {{ tag.title }}
65+ {{ /power-select-multiple }}
66+ </div >
67+ </div >
68+
5369 Created By: <mark >{{ question.user.firstname }} </mark >
5470
5571 {{ /unless }}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export default Route.extend({
77 model ( params ) {
88 return RSVP . hash ( {
99 question : this . store . findRecord ( 'question' , params . id , {
10- include : 'user,choices'
10+ include : 'user,choices,tags '
1111 } ) ,
1212 answers : this . api . request ( `/questions/${ params . id } /answers` )
1313 } )
Original file line number Diff line number Diff line change 11import Controller from '@ember/controller' ;
2+ import { inject as service } from '@ember/service' ;
23import { task , timeout } from 'ember-concurrency' ;
34
45export default Controller . extend ( {
6+ store : service ( ) ,
57 queryParams : [ 'page' , 'limit' ] ,
68 page : 1 ,
79 limit : 10 ,
@@ -10,18 +12,36 @@ export default Controller.extend({
1012 yield timeout ( 250 )
1113
1214 let searchStr = this . get ( 'searchString' ) . trim ( )
15+ let selectedTags = [ ]
16+
17+ if ( this . get ( 'filterTags' ) ) {
18+ selectedTags = this . get ( 'filterTags' )
19+ selectedTags = selectedTags . map ( t => + t . id )
20+ }
1321
1422 const questions = yield this . get ( 'store' ) . query ( 'question' , {
1523 include : 'user' ,
1624 filter : {
1725 title : {
1826 $iLike : `%${ this . get ( 'searchString' ) } %`
19- }
27+ } ,
28+ tags : selectedTags
2029 }
2130 } )
2231 this . set ( 'page' , 1 )
2332 this . set ( 'questions' , questions )
2433 } ) . restartable ( ) ,
34+ tagsFilterTask : task ( function * ( str ) {
35+ yield timeout ( 250 )
36+ const tags = yield this . get ( 'store' ) . query ( 'tag' , {
37+ filter : {
38+ title : {
39+ $iLike : `%${ str } %`
40+ }
41+ }
42+ } )
43+ return tags . toArray ( )
44+ } ) ,
2545 actions : {
2646 deleteQuestion ( question ) {
2747 question . destroyRecord ( )
Original file line number Diff line number Diff line change @@ -21,5 +21,6 @@ export default Route.extend({
2121 } ,
2222 setupController ( controller , model ) {
2323 controller . set ( "questions" , model )
24+ controller . set ( "tags" , model . filterTags )
2425 }
2526} ) ;
Original file line number Diff line number Diff line change 1111 <img src =" http://online.codingblocks.com/images/searchicon-06d8faf96de7c883b5440b6594e39eda.png" alt =" search" >
1212 </div >
1313 </div >
14+ <div class =" row justify-content-center" >
15+ <div class =" col-8" >
16+ {{ #power-select-multiple
17+ search = (perform tagsFilterTask )
18+ selected =filterTags
19+ onchange = (action (pipe (action (mut filterTags )) (perform searchTask )))
20+ placeholder =" Filter by tags"
21+ as |tag |}}
22+ {{ tag.title }}
23+ {{ /power-select-multiple }}
24+ </div >
25+ </div >
1426 <div class =" row" >
1527 <div class =" col-5" ></div >
1628 <div class =" col-6" >
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app');
44
55module . exports = function ( defaults ) {
66 let app = new EmberApp ( defaults , {
7+ 'ember-composable-helpers' : {
8+ // Add conditions
9+ }
710 // Add options here
811 } ) ;
912
Original file line number Diff line number Diff line change 3636 "ember-cli-showdown" : " ^4.4.4" ,
3737 "ember-cli-sri" : " ^2.1.0" ,
3838 "ember-cli-uglify" : " ^2.0.0" ,
39+ "ember-composable-helpers" : " ^2.3.1" ,
3940 "ember-data" : " ~3.3.0" ,
4041 "ember-datetime-picker" : " ^0.2.1" ,
4142 "ember-decorators" : " ^2.2.0" ,
You can’t perform that action at this time.
0 commit comments