aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-watch/video-report.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/+video-watch/video-report.component.ts')
-rw-r--r--client/src/app/videos/+video-watch/video-report.component.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/client/src/app/videos/+video-watch/video-report.component.ts b/client/src/app/videos/+video-watch/video-report.component.ts
new file mode 100644
index 000000000..d9c83a640
--- /dev/null
+++ b/client/src/app/videos/+video-watch/video-report.component.ts
@@ -0,0 +1,69 @@
1import { Component, Input, OnInit, ViewChild } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3
4import { ModalDirective } from 'ngx-bootstrap/modal'
5import { NotificationsService } from 'angular2-notifications'
6
7import { FormReactive, VideoAbuseService, VIDEO_ABUSE_REASON } from '../../shared'
8import { Video, VideoService } from '../shared'
9
10@Component({
11 selector: 'my-video-report',
12 templateUrl: './video-report.component.html'
13})
14export class VideoReportComponent extends FormReactive implements OnInit {
15 @Input() video: Video = null
16
17 @ViewChild('modal') modal: ModalDirective
18
19 error: string = null
20 form: FormGroup
21 formErrors = {
22 reason: ''
23 }
24 validationMessages = {
25 reason: VIDEO_ABUSE_REASON.MESSAGES
26 }
27
28 constructor (
29 private formBuilder: FormBuilder,
30 private videoAbuseService: VideoAbuseService,
31 private notificationsService: NotificationsService
32 ) {
33 super()
34 }
35
36 ngOnInit () {
37 this.buildForm()
38 }
39
40 buildForm () {
41 this.form = this.formBuilder.group({
42 reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ]
43 })
44
45 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
46 }
47
48 show () {
49 this.modal.show()
50 }
51
52 hide () {
53 this.modal.hide()
54 }
55
56 report () {
57 const reason = this.form.value['reason']
58
59 this.videoAbuseService.reportVideo(this.video.id, reason)
60 .subscribe(
61 () => {
62 this.notificationsService.success('Success', 'Video reported.')
63 this.hide()
64 },
65
66 err => this.notificationsService.error('Error', err.message)
67 )
68 }
69}