]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-video-channels/my-account-video-channels.component.ts
Merge branch 'develop' into pr/1285
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-channels / my-account-video-channels.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { AuthService } from '../../core/auth'
4 import { ConfirmService } from '../../core/confirm'
5 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
6 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
7 import { User } from '@app/shared'
8 import { flatMap } from 'rxjs/operators'
9 import { I18n } from '@ngx-translate/i18n-polyfill'
10
11 @Component({
12 selector: 'my-account-video-channels',
13 templateUrl: './my-account-video-channels.component.html',
14 styleUrls: [ './my-account-video-channels.component.scss' ]
15 })
16 export class MyAccountVideoChannelsComponent implements OnInit {
17 videoChannels: VideoChannel[] = []
18
19 private user: User
20
21 constructor (
22 private authService: AuthService,
23 private notifier: Notifier,
24 private confirmService: ConfirmService,
25 private videoChannelService: VideoChannelService,
26 private i18n: I18n
27 ) {}
28
29 ngOnInit () {
30 this.user = this.authService.getUser()
31
32 this.loadVideoChannels()
33 }
34
35 async deleteVideoChannel (videoChannel: VideoChannel) {
36 const res = await this.confirmService.confirmWithInput(
37 this.i18n(
38 'Do you really want to delete {{channelDisplayName}}? It will delete all videos uploaded in this channel, ' +
39 'and you will not be able to create another channel with the same name ({{channelName}})!',
40 { channelDisplayName: videoChannel.displayName, channelName: videoChannel.name }
41 ),
42 this.i18n(
43 'Please type the display name of the video channel ({{displayName}}) to confirm',
44 { displayName: videoChannel.displayName }
45 ),
46 videoChannel.displayName,
47 this.i18n('Delete')
48 )
49 if (res === false) return
50
51 this.videoChannelService.removeVideoChannel(videoChannel)
52 .subscribe(
53 () => {
54 this.loadVideoChannels()
55 this.notifier.success(
56 this.i18n('Video channel {{videoChannelName}} deleted.', { videoChannelName: videoChannel.displayName })
57 )
58 },
59
60 error => this.notifier.error(error.message)
61 )
62 }
63
64 private loadVideoChannels () {
65 this.authService.userInformationLoaded
66 .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account)))
67 .subscribe(res => this.videoChannels = res.data)
68 }
69 }