]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/modal/video-report.component.ts
Update client according to new model paths
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-report.component.ts
1 import { Component, Input, OnInit, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { FormReactive, VideoAbuseService } from '../../../shared/index'
4 import { VideoDetails } from '../../../shared/video/video-details.model'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7 import { VideoAbuseValidatorsService } from '@app/shared/forms/form-validators/video-abuse-validators.service'
8 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
9 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
10
11 @Component({
12 selector: 'my-video-report',
13 templateUrl: './video-report.component.html',
14 styleUrls: [ './video-report.component.scss' ]
15 })
16 export class VideoReportComponent extends FormReactive implements OnInit {
17 @Input() video: VideoDetails = null
18
19 @ViewChild('modal') modal: NgbModal
20
21 error: string = null
22
23 private openedModal: NgbModalRef
24
25 constructor (
26 protected formValidatorService: FormValidatorService,
27 private modalService: NgbModal,
28 private videoAbuseValidatorsService: VideoAbuseValidatorsService,
29 private videoAbuseService: VideoAbuseService,
30 private notificationsService: NotificationsService,
31 private i18n: I18n
32 ) {
33 super()
34 }
35
36 ngOnInit () {
37 this.buildForm({
38 reason: this.videoAbuseValidatorsService.VIDEO_ABUSE_REASON
39 })
40 }
41
42 show () {
43 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
44 }
45
46 hide () {
47 this.openedModal.close()
48 this.openedModal = null
49 }
50
51 report () {
52 const reason = this.form.value['reason']
53
54 this.videoAbuseService.reportVideo(this.video.id, reason)
55 .subscribe(
56 () => {
57 this.notificationsService.success(this.i18n('Success'), this.i18n('Video reported.'))
58 this.hide()
59 },
60
61 err => this.notificationsService.error(this.i18n('Error'), err.message)
62 )
63 }
64 }