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