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