]>
Commit | Line | Data |
---|---|---|
26b7305a C |
1 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | |
3 | import { FormReactive, VideoBlacklistService, VideoBlacklistValidatorsService } 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 { NgbModal } from '@ng-bootstrap/ng-bootstrap' | |
8 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
9 | import { RedirectService } from '@app/core' | |
10 | ||
11 | @Component({ | |
12 | selector: 'my-video-blacklist', | |
13 | templateUrl: './video-blacklist.component.html', | |
14 | styleUrls: [ './video-blacklist.component.scss' ] | |
15 | }) | |
16 | export class VideoBlacklistComponent 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 videoBlacklistValidatorsService: VideoBlacklistValidatorsService, | |
29 | private videoBlacklistService: VideoBlacklistService, | |
30 | private notificationsService: NotificationsService, | |
31 | private redirectService: RedirectService, | |
32 | private i18n: I18n | |
33 | ) { | |
34 | super() | |
35 | } | |
36 | ||
37 | ngOnInit () { | |
38 | this.buildForm({ | |
39 | reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON | |
40 | }) | |
41 | } | |
42 | ||
43 | show () { | |
44 | this.openedModal = this.modalService.open(this.modal, { keyboard: false }) | |
45 | } | |
46 | ||
47 | hide () { | |
48 | this.openedModal.close() | |
49 | this.openedModal = null | |
50 | } | |
51 | ||
52 | blacklist () { | |
53 | const reason = this.form.value[ 'reason' ] || undefined | |
54 | ||
55 | this.videoBlacklistService.blacklistVideo(this.video.id, reason) | |
56 | .subscribe( | |
57 | () => { | |
58 | this.notificationsService.success(this.i18n('Success'), this.i18n('Video blacklisted.')) | |
59 | this.hide() | |
60 | this.redirectService.redirectToHomepage() | |
61 | }, | |
62 | ||
63 | err => this.notificationsService.error(this.i18n('Error'), err.message) | |
64 | ) | |
65 | } | |
66 | } |