]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/video-report.component.ts
Merge branch 'feature/design' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / video-report.component.ts
1 import { Component, Input, OnInit, ViewChild } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { NotificationsService } from 'angular2-notifications'
4 import { ModalDirective } from 'ngx-bootstrap/modal'
5 import { FormReactive, VIDEO_ABUSE_REASON, VideoAbuseService } from '../../shared'
6 import { VideoDetails } from '../../shared/video/video-details.model'
7
8 @Component({
9 selector: 'my-video-report',
10 templateUrl: './video-report.component.html'
11 })
12 export class VideoReportComponent extends FormReactive implements OnInit {
13 @Input() video: VideoDetails = null
14
15 @ViewChild('modal') modal: ModalDirective
16
17 error: string = null
18 form: FormGroup
19 formErrors = {
20 reason: ''
21 }
22 validationMessages = {
23 reason: VIDEO_ABUSE_REASON.MESSAGES
24 }
25
26 constructor (
27 private formBuilder: FormBuilder,
28 private videoAbuseService: VideoAbuseService,
29 private notificationsService: NotificationsService
30 ) {
31 super()
32 }
33
34 ngOnInit () {
35 this.buildForm()
36 }
37
38 buildForm () {
39 this.form = this.formBuilder.group({
40 reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ]
41 })
42
43 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
44 }
45
46 show () {
47 this.modal.show()
48 }
49
50 hide () {
51 this.modal.hide()
52 }
53
54 report () {
55 const reason = this.form.value['reason']
56
57 this.videoAbuseService.reportVideo(this.video.id, reason)
58 .subscribe(
59 () => {
60 this.notificationsService.success('Success', 'Video reported.')
61 this.hide()
62 },
63
64 err => this.notificationsService.error('Error', err.message)
65 )
66 }
67 }