]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/modal/video-blacklist.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-blacklist.component.ts
1 import { Component, Input, OnInit, ViewChild } from '@angular/core'
2 import { Notifier, RedirectService } from '@app/core'
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
10 @Component({
11 selector: 'my-video-blacklist',
12 templateUrl: './video-blacklist.component.html',
13 styleUrls: [ './video-blacklist.component.scss' ]
14 })
15 export class VideoBlacklistComponent extends FormReactive implements OnInit {
16 @Input() video: VideoDetails = null
17
18 @ViewChild('modal') modal: NgbModal
19
20 error: string = null
21
22 private openedModal: NgbModalRef
23
24 constructor (
25 protected formValidatorService: FormValidatorService,
26 private modalService: NgbModal,
27 private videoBlacklistValidatorsService: VideoBlacklistValidatorsService,
28 private videoBlacklistService: VideoBlacklistService,
29 private notifier: Notifier,
30 private redirectService: RedirectService,
31 private i18n: I18n
32 ) {
33 super()
34 }
35
36 ngOnInit () {
37 this.buildForm({
38 reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON
39 })
40 }
41
42 show () {
43 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
44 }
45
46 hide () {
47 this.openedModal.close()
48 this.openedModal = null
49 }
50
51 blacklist () {
52 const reason = this.form.value[ 'reason' ] || undefined
53
54 this.videoBlacklistService.blacklistVideo(this.video.id, reason)
55 .subscribe(
56 () => {
57 this.notifier.success(this.i18n('Video blacklisted.'))
58 this.hide()
59 this.redirectService.redirectToHomepage()
60 },
61
62 err => this.notifier.error(err.message)
63 )
64 }
65 }