]>
Commit | Line | Data |
---|---|---|
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/index' | |
6 | import { VideoDetails } from '../../../shared/video/video-details.model' | |
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
8 | import { FormReactiveErrors, FormReactiveValidationMessages } from '@app/shared' | |
9 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | |
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: ModalDirective | |
20 | ||
21 | error: string = null | |
22 | ||
23 | constructor ( | |
24 | protected formValidatorService: FormValidatorService, | |
25 | private videoAbuseService: VideoAbuseService, | |
26 | private notificationsService: NotificationsService, | |
27 | private i18n: I18n | |
28 | ) { | |
29 | super() | |
30 | } | |
31 | ||
32 | ngOnInit () { | |
33 | this.buildForm({ | |
34 | reason: VIDEO_ABUSE_REASON | |
35 | }) | |
36 | } | |
37 | ||
38 | show () { | |
39 | this.modal.show() | |
40 | } | |
41 | ||
42 | hide () { | |
43 | this.modal.hide() | |
44 | } | |
45 | ||
46 | report () { | |
47 | const reason = this.form.value['reason'] | |
48 | ||
49 | this.videoAbuseService.reportVideo(this.video.id, reason) | |
50 | .subscribe( | |
51 | () => { | |
52 | this.notificationsService.success(this.i18n('Success'), this.i18n('Video reported.')) | |
53 | this.hide() | |
54 | }, | |
55 | ||
56 | err => this.notificationsService.error(this.i18n('Error'), err.message) | |
57 | ) | |
58 | } | |
59 | } |