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