]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.ts
Add ListOverflow component to prevent sub-menu overflow
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-ownership / my-account-accept-ownership / my-account-accept-ownership.component.ts
CommitLineData
74d63469 1import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
f8b2c1b4 2import { AuthService, Notifier } from '@app/core'
74d63469
GR
3import { FormReactive } from '@app/shared'
4import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5import { VideoOwnershipService } from '@app/shared/video-ownership'
6import { VideoChangeOwnership } from '../../../../../../shared/models/videos'
7import { VideoAcceptOwnershipValidatorsService } from '@app/shared/forms/form-validators'
8import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
10import { I18n } from '@ngx-translate/i18n-polyfill'
74d63469
GR
11import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
12
13@Component({
14 selector: 'my-account-accept-ownership',
15 templateUrl: './my-account-accept-ownership.component.html',
16 styleUrls: [ './my-account-accept-ownership.component.scss' ]
17})
18export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
19 @Output() accepted = new EventEmitter<void>()
20
f36da21e 21 @ViewChild('modal', { static: true }) modal: ElementRef
74d63469
GR
22
23 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
24
25 videoChannels: VideoChannel[]
26
27 error: string = null
28
29 constructor (
30 protected formValidatorService: FormValidatorService,
31 private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService,
32 private videoOwnershipService: VideoOwnershipService,
f8b2c1b4 33 private notifier: Notifier,
74d63469
GR
34 private authService: AuthService,
35 private videoChannelService: VideoChannelService,
36 private modalService: NgbModal,
37 private i18n: I18n
38 ) {
39 super()
40 }
41
42 ngOnInit () {
43 this.videoChannels = []
44
45 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
46 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
47
48 this.buildForm({
49 channel: this.videoChangeOwnershipValidatorsService.CHANNEL
50 })
51 }
52
53 show (videoChangeOwnership: VideoChangeOwnership) {
54 this.videoChangeOwnership = videoChangeOwnership
55 this.modalService
24e7916c 56 .open(this.modal, { centered: true })
74d63469
GR
57 .result
58 .then(() => this.acceptOwnership())
59 .catch(() => this.videoChangeOwnership = undefined)
60 }
61
62 acceptOwnership () {
63 const channel = this.form.value['channel']
64
65 const videoChangeOwnership = this.videoChangeOwnership
66 this.videoOwnershipService
67 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
68 .subscribe(
69 () => {
f8b2c1b4 70 this.notifier.success(this.i18n('Ownership accepted'))
74d63469
GR
71 if (this.accepted) this.accepted.emit()
72 this.videoChangeOwnership = undefined
73 },
74
f8b2c1b4 75 err => this.notifier.error(err.message)
74d63469
GR
76 )
77 }
78}