]> 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
Users can change ownership of their video [#510] (#888)
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-ownership / my-account-accept-ownership / my-account-accept-ownership.component.ts
CommitLineData
74d63469
GR
1import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2import { NotificationsService } from 'angular2-notifications'
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'
11import { AuthService } from '@app/core'
12import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
13
14@Component({
15 selector: 'my-account-accept-ownership',
16 templateUrl: './my-account-accept-ownership.component.html',
17 styleUrls: [ './my-account-accept-ownership.component.scss' ]
18})
19export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
20 @Output() accepted = new EventEmitter<void>()
21
22 @ViewChild('modal') modal: ElementRef
23
24 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
25
26 videoChannels: VideoChannel[]
27
28 error: string = null
29
30 constructor (
31 protected formValidatorService: FormValidatorService,
32 private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService,
33 private videoOwnershipService: VideoOwnershipService,
34 private notificationsService: NotificationsService,
35 private authService: AuthService,
36 private videoChannelService: VideoChannelService,
37 private modalService: NgbModal,
38 private i18n: I18n
39 ) {
40 super()
41 }
42
43 ngOnInit () {
44 this.videoChannels = []
45
46 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
47 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
48
49 this.buildForm({
50 channel: this.videoChangeOwnershipValidatorsService.CHANNEL
51 })
52 }
53
54 show (videoChangeOwnership: VideoChangeOwnership) {
55 this.videoChangeOwnership = videoChangeOwnership
56 this.modalService
57 .open(this.modal)
58 .result
59 .then(() => this.acceptOwnership())
60 .catch(() => this.videoChangeOwnership = undefined)
61 }
62
63 acceptOwnership () {
64 const channel = this.form.value['channel']
65
66 const videoChangeOwnership = this.videoChangeOwnership
67 this.videoOwnershipService
68 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
69 .subscribe(
70 () => {
71 this.notificationsService.success(this.i18n('Success'), this.i18n('Ownership accepted'))
72 if (this.accepted) this.accepted.emit()
73 this.videoChangeOwnership = undefined
74 },
75
76 err => this.notificationsService.error(this.i18n('Error'), err.message)
77 )
78 }
79}