]>
Commit | Line | Data |
---|---|---|
08c1efbe C |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | |
08c1efbe C |
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' | |
db400f44 | 8 | import { flatMap } from 'rxjs/operators' |
08c1efbe C |
9 | |
10 | @Component({ | |
11 | selector: 'my-account-video-channels', | |
12 | templateUrl: './my-account-video-channels.component.html', | |
13 | styleUrls: [ './my-account-video-channels.component.scss' ] | |
14 | }) | |
6a478b11 | 15 | export class MyAccountVideoChannelsComponent implements OnInit { |
08c1efbe C |
16 | videoChannels: VideoChannel[] = [] |
17 | ||
18 | private user: User | |
19 | ||
20 | constructor ( | |
21 | private authService: AuthService, | |
22 | private notificationsService: NotificationsService, | |
23 | private confirmService: ConfirmService, | |
24 | private videoChannelService: VideoChannelService | |
25 | ) {} | |
26 | ||
27 | ngOnInit () { | |
28 | this.user = this.authService.getUser() | |
29 | ||
30 | this.loadVideoChannels() | |
31 | } | |
32 | ||
33 | async deleteVideoChannel (videoChannel: VideoChannel) { | |
34 | const res = await this.confirmService.confirmWithInput( | |
35 | `Do you really want to delete ${videoChannel.displayName}? It will delete all videos uploaded in this channel too.`, | |
36 | 'Please type the name of the video channel to confirm', | |
37 | videoChannel.displayName, | |
38 | 'Delete' | |
39 | ) | |
40 | if (res === false) return | |
41 | ||
42 | this.videoChannelService.removeVideoChannel(videoChannel) | |
43 | .subscribe( | |
44 | status => { | |
45 | this.loadVideoChannels() | |
46 | this.notificationsService.success('Success', `Video channel ${videoChannel.name} deleted.`) | |
47 | }, | |
48 | ||
49 | error => this.notificationsService.error('Error', error.message) | |
50 | ) | |
51 | } | |
52 | ||
53 | private loadVideoChannels () { | |
54 | this.authService.userInformationLoaded | |
ad9e39fb | 55 | .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account))) |
08c1efbe C |
56 | .subscribe(res => this.videoChannels = res.data) |
57 | } | |
58 | } |