]>
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' |
b1d40cff | 9 | import { I18n } from '@ngx-translate/i18n-polyfill' |
08c1efbe C |
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, | |
b1d40cff C |
25 | private videoChannelService: VideoChannelService, |
26 | private i18n: I18n | |
08c1efbe C |
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( | |
b1d40cff | 37 | this.i18n( |
25acef90 | 38 | 'Do you really want to delete {{videoChannelName}}? It will delete all videos uploaded in this channel too.', |
b1d40cff C |
39 | { videoChannelName: videoChannel.displayName } |
40 | ), | |
41 | this.i18n('Please type the name of the video channel to confirm'), | |
08c1efbe | 42 | videoChannel.displayName, |
b1d40cff | 43 | this.i18n('Delete') |
08c1efbe C |
44 | ) |
45 | if (res === false) return | |
46 | ||
47 | this.videoChannelService.removeVideoChannel(videoChannel) | |
48 | .subscribe( | |
49 | status => { | |
50 | this.loadVideoChannels() | |
b1d40cff C |
51 | this.notificationsService.success( |
52 | this.i18n('Success'), | |
25acef90 | 53 | this.i18n('Video channel {{videoChannelName}} deleted.', { videoChannelName: videoChannel.displayName }) |
b1d40cff | 54 | ) |
08c1efbe C |
55 | }, |
56 | ||
b1d40cff | 57 | error => this.notificationsService.error(this.i18n('Error'), error.message) |
08c1efbe C |
58 | ) |
59 | } | |
60 | ||
61 | private loadVideoChannels () { | |
62 | this.authService.userInformationLoaded | |
ad9e39fb | 63 | .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account))) |
08c1efbe C |
64 | .subscribe(res => this.videoChannels = res.data) |
65 | } | |
66 | } |