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 { ScreenService } from '@app/shared/misc/screen.service'
8 import { User } from '@app/shared'
9 import { flatMap } from 'rxjs/operators'
10 import { I18n } from '@ngx-translate/i18n-polyfill'
11 import { minBy, maxBy } from 'lodash-es'
14 selector: 'my-account-video-channels',
15 templateUrl: './my-account-video-channels.component.html',
16 styleUrls: [ './my-account-video-channels.component.scss' ]
18 export class MyAccountVideoChannelsComponent implements OnInit {
19 videoChannels: VideoChannel[] = []
20 videoChannelsData: any[]
21 videoChannelsMinimumDailyViews = 0
22 videoChannelsMaximumDailyViews: number
27 private authService: AuthService,
28 private notifier: Notifier,
29 private confirmService: ConfirmService,
30 private videoChannelService: VideoChannelService,
31 private screenService: ScreenService,
36 this.user = this.authService.getUser()
38 this.loadVideoChannels()
41 get isInSmallView () {
42 return this.screenService.isInSmallView()
57 min: Math.max(0, this.videoChannelsMinimumDailyViews - (3 * this.videoChannelsMaximumDailyViews / 100)),
58 max: this.videoChannelsMaximumDailyViews
78 custom: function (tooltip: any) {
80 // disable displaying the color box;
81 tooltip.displayColors = false;
84 label: function (tooltip: any, data: any) {
85 return `${tooltip.value} views`;
96 async deleteVideoChannel (videoChannel: VideoChannel) {
97 const res = await this.confirmService.confirmWithInput(
100 'Do you really want to delete {{channelDisplayName}}? It will delete all videos uploaded in this channel, and you will not be able to create another channel with the same name ({{channelName}})!',
101 { channelDisplayName: videoChannel.displayName, channelName: videoChannel.name }
104 'Please type the display name of the video channel ({{displayName}}) to confirm',
105 { displayName: videoChannel.displayName }
107 videoChannel.displayName,
110 if (res === false) return
112 this.videoChannelService.removeVideoChannel(videoChannel)
115 this.loadVideoChannels()
116 this.notifier.success(
117 this.i18n('Video channel {{videoChannelName}} deleted.', { videoChannelName: videoChannel.displayName })
121 error => this.notifier.error(error.message)
125 private loadVideoChannels () {
126 this.authService.userInformationLoaded
127 .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account)))
129 this.videoChannels = res.data
130 this.videoChannelsData = this.videoChannels.map(v => ({
131 labels: v.viewsPerDay.map(day => day.date.toLocaleDateString()),
134 label: this.i18n('Views for the day'),
135 data: v.viewsPerDay.map(day => day.views),
137 borderColor: "#c6c6c6"
141 this.videoChannelsMinimumDailyViews = minBy(this.videoChannels.map(v => minBy(v.viewsPerDay, day => day.views)), day => day.views).views
142 this.videoChannelsMaximumDailyViews = maxBy(this.videoChannels.map(v => maxBy(v.viewsPerDay, day => day.views)), day => day.views).views