]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-ownership/my-accept-ownership/my-accept-ownership.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-ownership / my-accept-ownership / my-accept-ownership.component.ts
CommitLineData
dc2b2938 1import { SelectChannelItem } from 'src/types/select-options-item.model'
74d63469 2import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
f8b2c1b4 3import { AuthService, Notifier } from '@app/core'
d0800f76 4import { listUserChannelsForSelect } from '@app/helpers'
7ed1edbb 5import { OWNERSHIP_CHANGE_CHANNEL_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
5c5bcea2 6import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
dc2b2938 7import { VideoOwnershipService } from '@app/shared/shared-main'
74d63469 8import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
dc2b2938 9import { VideoChangeOwnership } from '@shared/models'
74d63469
GR
10
11@Component({
17119e4a
C
12 selector: 'my-accept-ownership',
13 templateUrl: './my-accept-ownership.component.html',
14 styleUrls: [ './my-accept-ownership.component.scss' ]
74d63469 15})
17119e4a 16export class MyAcceptOwnershipComponent extends FormReactive implements OnInit {
74d63469
GR
17 @Output() accepted = new EventEmitter<void>()
18
f36da21e 19 @ViewChild('modal', { static: true }) modal: ElementRef
74d63469
GR
20
21 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
dc2b2938 22 videoChannels: SelectChannelItem[]
74d63469
GR
23
24 error: string = null
25
26 constructor (
5c5bcea2 27 protected formReactiveService: FormReactiveService,
74d63469 28 private videoOwnershipService: VideoOwnershipService,
f8b2c1b4 29 private notifier: Notifier,
74d63469 30 private authService: AuthService,
66357162 31 private modalService: NgbModal
9df52d66 32 ) {
74d63469
GR
33 super()
34 }
35
36 ngOnInit () {
37 this.videoChannels = []
38
d0800f76 39 listUserChannelsForSelect(this.authService)
dc2b2938 40 .subscribe(channels => this.videoChannels = channels)
74d63469
GR
41
42 this.buildForm({
7ed1edbb 43 channel: OWNERSHIP_CHANGE_CHANNEL_VALIDATOR
74d63469
GR
44 })
45 }
46
47 show (videoChangeOwnership: VideoChangeOwnership) {
a3f1595f
FC
48 // Select the first available channel by default
49 this.form.patchValue({
50 channel: this.videoChannels[0].id
51 })
52
74d63469
GR
53 this.videoChangeOwnership = videoChangeOwnership
54 this.modalService
24e7916c 55 .open(this.modal, { centered: true })
74d63469
GR
56 .result
57 .then(() => this.acceptOwnership())
58 .catch(() => this.videoChangeOwnership = undefined)
59 }
60
61 acceptOwnership () {
62 const channel = this.form.value['channel']
63
64 const videoChangeOwnership = this.videoChangeOwnership
65 this.videoOwnershipService
66 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
1378c0d3
C
67 .subscribe({
68 next: () => {
66357162 69 this.notifier.success($localize`Ownership accepted`)
74d63469
GR
70 if (this.accepted) this.accepted.emit()
71 this.videoChangeOwnership = undefined
72 },
73
1378c0d3
C
74 error: err => this.notifier.error(err.message)
75 })
74d63469
GR
76 }
77}