]> 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
Migrate to $localize
[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'
67ed6552
C
3import { FormReactive, FormValidatorService, VideoAcceptOwnershipValidatorsService } from '@app/shared/shared-forms'
4import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main'
74d63469 5import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
67ed6552 6import { VideoChangeOwnership, VideoChannel } from '@shared/models'
74d63469
GR
7
8@Component({
9 selector: 'my-account-accept-ownership',
10 templateUrl: './my-account-accept-ownership.component.html',
11 styleUrls: [ './my-account-accept-ownership.component.scss' ]
12})
13export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
14 @Output() accepted = new EventEmitter<void>()
15
f36da21e 16 @ViewChild('modal', { static: true }) modal: ElementRef
74d63469
GR
17
18 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
19
20 videoChannels: VideoChannel[]
21
22 error: string = null
23
24 constructor (
25 protected formValidatorService: FormValidatorService,
26 private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService,
27 private videoOwnershipService: VideoOwnershipService,
f8b2c1b4 28 private notifier: Notifier,
74d63469
GR
29 private authService: AuthService,
30 private videoChannelService: VideoChannelService,
66357162
C
31 private modalService: NgbModal
32 ) {
74d63469
GR
33 super()
34 }
35
36 ngOnInit () {
37 this.videoChannels = []
38
39 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
40 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
41
42 this.buildForm({
43 channel: this.videoChangeOwnershipValidatorsService.CHANNEL
44 })
45 }
46
47 show (videoChangeOwnership: VideoChangeOwnership) {
48 this.videoChangeOwnership = videoChangeOwnership
49 this.modalService
24e7916c 50 .open(this.modal, { centered: true })
74d63469
GR
51 .result
52 .then(() => this.acceptOwnership())
53 .catch(() => this.videoChangeOwnership = undefined)
54 }
55
56 acceptOwnership () {
57 const channel = this.form.value['channel']
58
59 const videoChangeOwnership = this.videoChangeOwnership
60 this.videoOwnershipService
61 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
62 .subscribe(
63 () => {
66357162 64 this.notifier.success($localize`Ownership accepted`)
74d63469
GR
65 if (this.accepted) this.accepted.emit()
66 this.videoChangeOwnership = undefined
67 },
68
f8b2c1b4 69 err => this.notifier.error(err.message)
74d63469
GR
70 )
71 }
72}