]>
Commit | Line | Data |
---|---|---|
3a0fb65c | 1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier, RedirectService } from '@app/core' |
3a0fb65c | 3 | import { VideoBlacklistService } from '../../../shared/video-blacklist' |
26b7305a C |
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' | |
3a0fb65c | 9 | import { FormReactive, VideoBlacklistValidatorsService } from '@app/shared/forms' |
26b7305a C |
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 | ||
f36da21e | 19 | @ViewChild('modal', { static: true }) modal: NgbModal |
26b7305a | 20 | |
3a0fb65c C |
21 | @Output() videoBlacklisted = new EventEmitter() |
22 | ||
26b7305a C |
23 | error: string = null |
24 | ||
25 | private openedModal: NgbModalRef | |
26 | ||
27 | constructor ( | |
28 | protected formValidatorService: FormValidatorService, | |
29 | private modalService: NgbModal, | |
30 | private videoBlacklistValidatorsService: VideoBlacklistValidatorsService, | |
31 | private videoBlacklistService: VideoBlacklistService, | |
f8b2c1b4 | 32 | private notifier: Notifier, |
26b7305a C |
33 | private redirectService: RedirectService, |
34 | private i18n: I18n | |
35 | ) { | |
36 | super() | |
37 | } | |
38 | ||
39 | ngOnInit () { | |
5abb9fbb C |
40 | const defaultValues = { unfederate: 'true' } |
41 | ||
26b7305a | 42 | this.buildForm({ |
5abb9fbb C |
43 | reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON, |
44 | unfederate: null | |
45 | }, defaultValues) | |
26b7305a C |
46 | } |
47 | ||
48 | show () { | |
49 | this.openedModal = this.modalService.open(this.modal, { keyboard: false }) | |
50 | } | |
51 | ||
52 | hide () { | |
53 | this.openedModal.close() | |
54 | this.openedModal = null | |
55 | } | |
56 | ||
57 | blacklist () { | |
58 | const reason = this.form.value[ 'reason' ] || undefined | |
5abb9fbb | 59 | const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined |
26b7305a | 60 | |
5abb9fbb | 61 | this.videoBlacklistService.blacklistVideo(this.video.id, reason, unfederate) |
26b7305a C |
62 | .subscribe( |
63 | () => { | |
f8b2c1b4 | 64 | this.notifier.success(this.i18n('Video blacklisted.')) |
26b7305a | 65 | this.hide() |
3a0fb65c C |
66 | |
67 | this.video.blacklisted = true | |
68 | this.video.blacklistedReason = reason | |
69 | ||
70 | this.videoBlacklisted.emit() | |
26b7305a C |
71 | }, |
72 | ||
f8b2c1b4 | 73 | err => this.notifier.error(err.message) |
26b7305a C |
74 | ) |
75 | } | |
76 | } |