aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/video-watch/video-report.component.ts
blob: d9c83a640bb45a154c37d9b48cd5294fe24fa398 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Component, Input, OnInit, ViewChild } from '@angular/core'
import { FormBuilder, FormGroup } from '@angular/forms'

import { ModalDirective } from 'ngx-bootstrap/modal'
import { NotificationsService } from 'angular2-notifications'

import { FormReactive, VideoAbuseService, VIDEO_ABUSE_REASON } from '../../shared'
import { Video, VideoService } from '../shared'

@Component({
  selector: 'my-video-report',
  templateUrl: './video-report.component.html'
})
export class VideoReportComponent extends FormReactive implements OnInit {
  @Input() video: Video = null

  @ViewChild('modal') modal: ModalDirective

  error: string = null
  form: FormGroup
  formErrors = {
    reason: ''
  }
  validationMessages = {
    reason: VIDEO_ABUSE_REASON.MESSAGES
  }

  constructor (
    private formBuilder: FormBuilder,
    private videoAbuseService: VideoAbuseService,
    private notificationsService: NotificationsService
   ) {
    super()
  }

  ngOnInit () {
    this.buildForm()
  }

  buildForm () {
    this.form = this.formBuilder.group({
      reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ]
    })

    this.form.valueChanges.subscribe(data => this.onValueChanged(data))
  }

  show () {
    this.modal.show()
  }

  hide () {
    this.modal.hide()
  }

  report () {
    const reason = this.form.value['reason']

    this.videoAbuseService.reportVideo(this.video.id, reason)
                          .subscribe(
                            () => {
                              this.notificationsService.success('Success', 'Video reported.')
                              this.hide()
                            },

                            err => this.notificationsService.error('Error', err.message)
                           )
  }
}