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