diff options
Diffstat (limited to 'client/src/app/shared/video/modals/video-blacklist.component.ts')
-rw-r--r-- | client/src/app/shared/video/modals/video-blacklist.component.ts | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/client/src/app/shared/video/modals/video-blacklist.component.ts b/client/src/app/shared/video/modals/video-blacklist.component.ts new file mode 100644 index 000000000..4e4e8dc50 --- /dev/null +++ b/client/src/app/shared/video/modals/video-blacklist.component.ts | |||
@@ -0,0 +1,76 @@ | |||
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 { 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 { FormReactive, VideoBlacklistValidatorsService } from '@app/shared/forms' | ||
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 | @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, { 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 | } | ||