]>
Commit | Line | Data |
---|---|---|
1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' | |
2 | import { Notifier, RedirectService } from '@app/core' | |
3 | import { VideoBlacklistService } from '../../../shared/video-blacklist' | |
4 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
5 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | |
6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | |
7 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
8 | import { FormReactive, VideoBlacklistValidatorsService } from '@app/shared/forms' | |
9 | import { Video } from '@app/shared/video/video.model' | |
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: Video = null | |
18 | ||
19 | @ViewChild('modal', { static: true }) modal: NgbModal | |
20 | ||
21 | @Output() videoBlacklisted = new EventEmitter() | |
22 | ||
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, | |
32 | private notifier: Notifier, | |
33 | private redirectService: RedirectService, | |
34 | private i18n: I18n | |
35 | ) { | |
36 | super() | |
37 | } | |
38 | ||
39 | ngOnInit () { | |
40 | const defaultValues = { unfederate: 'true' } | |
41 | ||
42 | this.buildForm({ | |
43 | reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON, | |
44 | unfederate: null | |
45 | }, defaultValues) | |
46 | } | |
47 | ||
48 | show () { | |
49 | this.openedModal = this.modalService.open(this.modal, { centered: true, 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 | |
59 | const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined | |
60 | ||
61 | this.videoBlacklistService.blacklistVideo(this.video.id, reason, unfederate) | |
62 | .subscribe( | |
63 | () => { | |
64 | this.notifier.success(this.i18n('Video blacklisted.')) | |
65 | this.hide() | |
66 | ||
67 | this.video.blacklisted = true | |
68 | this.video.blacklistedReason = reason | |
69 | ||
70 | this.videoBlacklisted.emit() | |
71 | }, | |
72 | ||
73 | err => this.notifier.error(err.message) | |
74 | ) | |
75 | } | |
76 | } |