aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-27 16:11:53 +0100
committerChocobozzz <me@florianbigard.com>2017-12-27 16:11:53 +0100
commit4635f59d7c3fea4b97029f10886c62fdf38b2084 (patch)
treed97357a00042bbfb33c4177ee24c01171d28dfce /client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
parentea44f375f5d3da06ca0aebfe871b9f924a26ec29 (diff)
downloadPeerTube-4635f59d7c3fea4b97029f10886c62fdf38b2084.tar.gz
PeerTube-4635f59d7c3fea4b97029f10886c62fdf38b2084.tar.zst
PeerTube-4635f59d7c3fea4b97029f10886c62fdf38b2084.zip
Add video comment components
Diffstat (limited to 'client/src/app/videos/+video-watch/comment/video-comment-add.component.ts')
-rw-r--r--client/src/app/videos/+video-watch/comment/video-comment-add.component.ts84
1 files changed, 84 insertions, 0 deletions
diff --git a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
new file mode 100644
index 000000000..5ad83fc47
--- /dev/null
+++ b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
@@ -0,0 +1,84 @@
1import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { NotificationsService } from 'angular2-notifications'
4import { Observable } from 'rxjs/Observable'
5import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model'
6import { FormReactive } from '../../../shared'
7import { VIDEO_COMMENT_TEXT } from '../../../shared/forms/form-validators/video-comment'
8import { Video } from '../../../shared/video/video.model'
9import { VideoComment } from './video-comment.model'
10import { VideoCommentService } from './video-comment.service'
11
12@Component({
13 selector: 'my-video-comment-add',
14 templateUrl: './video-comment-add.component.html',
15 styleUrls: ['./video-comment-add.component.scss']
16})
17export class VideoCommentAddComponent extends FormReactive implements OnInit {
18 @Input() video: Video
19 @Input() parentComment: VideoComment
20
21 @Output() commentCreated = new EventEmitter<VideoCommentCreate>()
22
23 form: FormGroup
24 formErrors = {
25 'text': ''
26 }
27 validationMessages = {
28 'text': VIDEO_COMMENT_TEXT.MESSAGES
29 }
30
31 constructor (
32 private formBuilder: FormBuilder,
33 private notificationsService: NotificationsService,
34 private videoCommentService: VideoCommentService
35 ) {
36 super()
37 }
38
39 buildForm () {
40 this.form = this.formBuilder.group({
41 text: [ '', VIDEO_COMMENT_TEXT.VALIDATORS ]
42 })
43
44 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
45 }
46
47 ngOnInit () {
48 this.buildForm()
49 }
50
51 formValidated () {
52 const commentCreate: VideoCommentCreate = this.form.value
53 let obs: Observable<any>
54
55 if (this.parentComment) {
56 obs = this.addCommentReply(commentCreate)
57 } else {
58 obs = this.addCommentThread(commentCreate)
59 }
60
61 obs.subscribe(
62 comment => {
63 this.commentCreated.emit(comment)
64 this.form.reset()
65 },
66
67 err => this.notificationsService.error('Error', err.text)
68 )
69}
70
71 isAddButtonDisplayed () {
72 return this.form.value['text']
73 }
74
75 private addCommentReply (commentCreate: VideoCommentCreate) {
76 return this.videoCommentService
77 .addCommentReply(this.video.id, this.parentComment.id, commentCreate)
78 }
79
80 private addCommentThread (commentCreate: VideoCommentCreate) {
81 return this.videoCommentService
82 .addCommentThread(this.video.id, commentCreate)
83 }
84}