3
3
*/
4
4
import Component from '../../decorators' ;
5
5
import './comment-list.scss' ;
6
+ import { IComment } from "../../interfaces" ;
6
7
7
8
@Component ( 'app.components' , 'comments' , {
8
9
template : `
9
10
<div class="container-fluid">
10
11
<div class="discussion-timeline">
11
- <comment ng-repeat="comment in $ctrl.comments" comment="comment"></comment>
12
- <!--<comment></comment>-->
12
+ <tags-input ng-model="$ctrl.tagFilter">
13
+ <auto-complete source="$ctrl.tags"></auto-complete>
14
+ </tags-input>
15
+ <comment ng-repeat="comment in $ctrl.comments | filterByTags:$ctrl.tagFilter" comment="comment" tags="$ctrl.tags"></comment>
16
+ <comment comment="$ctrl.emptyComment" on-add="$ctrl.addComment()" tags="$ctrl.tags"></comment>
13
17
</div>
14
18
</div>`
15
19
} )
16
20
class CommentsController {
17
- comments ;
21
+ comments : IComment [ ] ;
22
+ emptyComment : IComment ;
23
+ tags : string [ ] ;
24
+ tagFilter : any [ ] ;
18
25
19
26
static $inject = [ 'Comments' ] ;
20
27
constructor ( private Comments ) {
28
+ this . emptyComment = { } ;
29
+ this . tagFilter = [ ] ;
21
30
Comments . getComments ( ) . then ( ( comments ) => {
22
- this . comments = comments
31
+ this . comments = comments ;
32
+ this . tags = this . comments
33
+ . map ( ( el ) => el . tags )
34
+ . reduce ( ( prev , curr ) => [ ...prev , ...curr ] )
35
+ . filter ( ( elem , pos , arr ) => arr . indexOf ( elem ) == pos ) ;
23
36
} ) ;
24
37
}
38
+
39
+ private getCommentId ( ) {
40
+ let arr = this . comments . map ( ( el ) => el . id ) ;
41
+ return Math . max ( ...arr ) + 1 ;
42
+ }
43
+
44
+ addComment ( ) {
45
+ this . emptyComment . id = this . getCommentId ( ) ;
46
+ this . comments . push ( this . emptyComment ) ;
47
+ this . emptyComment = { } ;
48
+ }
25
49
}
0 commit comments