1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import 'rxjs/add/observable/from'
4 import 'rxjs/add/operator/concatAll'
5 import { AuthService } from '../../core/auth'
6 import { ConfirmService } from '../../core/confirm'
7 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
8 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
9 import { User } from '@app/shared'
12 selector: 'my-account-video-channels',
13 templateUrl: './my-account-video-channels.component.html',
14 styleUrls: [ './my-account-video-channels.component.scss' ]
16 export class MyAccountVideoChannelsComponent implements OnInit {
17 videoChannels: VideoChannel[] = []
22 private authService: AuthService,
23 private notificationsService: NotificationsService,
24 private confirmService: ConfirmService,
25 private videoChannelService: VideoChannelService
29 this.user = this.authService.getUser()
31 this.loadVideoChannels()
34 async deleteVideoChannel (videoChannel: VideoChannel) {
35 const res = await this.confirmService.confirmWithInput(
36 `Do you really want to delete ${videoChannel.displayName}? It will delete all videos uploaded in this channel too.`,
37 'Please type the name of the video channel to confirm',
38 videoChannel.displayName,
41 if (res === false) return
43 this.videoChannelService.removeVideoChannel(videoChannel)
46 this.loadVideoChannels()
47 this.notificationsService.success('Success', `Video channel ${videoChannel.name} deleted.`)
50 error => this.notificationsService.error('Error', error.message)
54 private loadVideoChannels () {
55 this.authService.userInformationLoaded
56 .flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account.id))
57 .subscribe(res => this.videoChannels = res.data)