]>
Commit | Line | Data |
---|---|---|
08c1efbe C |
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' | |
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 | }) | |
6a478b11 | 16 | export class MyAccountVideoChannelsComponent implements OnInit { |
08c1efbe C |
17 | videoChannels: VideoChannel[] = [] |
18 | ||
19 | private user: User | |
20 | ||
21 | constructor ( | |
22 | private authService: AuthService, | |
23 | private notificationsService: NotificationsService, | |
24 | private confirmService: ConfirmService, | |
25 | private videoChannelService: VideoChannelService | |
26 | ) {} | |
27 | ||
28 | ngOnInit () { | |
29 | this.user = this.authService.getUser() | |
30 | ||
31 | this.loadVideoChannels() | |
32 | } | |
33 | ||
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, | |
39 | 'Delete' | |
40 | ) | |
41 | if (res === false) return | |
42 | ||
43 | this.videoChannelService.removeVideoChannel(videoChannel) | |
44 | .subscribe( | |
45 | status => { | |
46 | this.loadVideoChannels() | |
47 | this.notificationsService.success('Success', `Video channel ${videoChannel.name} deleted.`) | |
48 | }, | |
49 | ||
50 | error => this.notificationsService.error('Error', error.message) | |
51 | ) | |
52 | } | |
53 | ||
54 | private loadVideoChannels () { | |
55 | this.authService.userInformationLoaded | |
56 | .flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account.id)) | |
57 | .subscribe(res => this.videoChannels = res.data) | |
58 | } | |
59 | } |