diff options
Diffstat (limited to 'client/src/app/+my-account/+my-account-video-channels/my-account-video-channels.component.ts')
-rw-r--r-- | client/src/app/+my-account/+my-account-video-channels/my-account-video-channels.component.ts | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/client/src/app/+my-account/+my-account-video-channels/my-account-video-channels.component.ts b/client/src/app/+my-account/+my-account-video-channels/my-account-video-channels.component.ts index ad9368794..2aff09cd9 100644 --- a/client/src/app/+my-account/+my-account-video-channels/my-account-video-channels.component.ts +++ b/client/src/app/+my-account/+my-account-video-channels/my-account-video-channels.component.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import { ChartData } from 'chart.js' | 1 | import { ChartData } from 'chart.js' |
2 | import { max, maxBy, min, minBy } from 'lodash-es' | 2 | import { max, maxBy, min, minBy } from 'lodash-es' |
3 | import { flatMap, debounceTime } from 'rxjs/operators' | 3 | import { Subject } from 'rxjs' |
4 | import { debounceTime, mergeMap } from 'rxjs/operators' | ||
4 | import { Component, OnInit } from '@angular/core' | 5 | import { Component, OnInit } from '@angular/core' |
5 | import { AuthService, ConfirmService, Notifier, ScreenService, User } from '@app/core' | 6 | import { AuthService, ConfirmService, Notifier, ScreenService, User } from '@app/core' |
6 | import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' | 7 | import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' |
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
8 | import { Subject } from 'rxjs' | ||
9 | 8 | ||
10 | @Component({ | 9 | @Component({ |
11 | selector: 'my-account-video-channels', | 10 | selector: 'my-account-video-channels', |
@@ -30,9 +29,8 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
30 | private notifier: Notifier, | 29 | private notifier: Notifier, |
31 | private confirmService: ConfirmService, | 30 | private confirmService: ConfirmService, |
32 | private videoChannelService: VideoChannelService, | 31 | private videoChannelService: VideoChannelService, |
33 | private screenService: ScreenService, | 32 | private screenService: ScreenService |
34 | private i18n: I18n | 33 | ) {} |
35 | ) {} | ||
36 | 34 | ||
37 | ngOnInit () { | 35 | ngOnInit () { |
38 | this.user = this.authService.getUser() | 36 | this.user = this.authService.getUser() |
@@ -110,17 +108,13 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
110 | 108 | ||
111 | async deleteVideoChannel (videoChannel: VideoChannel) { | 109 | async deleteVideoChannel (videoChannel: VideoChannel) { |
112 | const res = await this.confirmService.confirmWithInput( | 110 | const res = await this.confirmService.confirmWithInput( |
113 | this.i18n( | 111 | $localize`Do you really want to delete ${videoChannel.displayName}? |
114 | // tslint:disable | 112 | It will delete ${videoChannel.videosCount} videos uploaded in this channel, and you will not be able to create another |
115 | 'Do you really want to delete {{channelDisplayName}}? It will delete {{videosCount}} videos uploaded in this channel, and you will not be able to create another channel with the same name ({{channelName}})!', | 113 | channel with the same name (${videoChannel.name})!`, |
116 | { channelDisplayName: videoChannel.displayName, videosCount: videoChannel.videosCount, channelName: videoChannel.name } | 114 | |
117 | ), | 115 | $localize`Please type the display name of the video channel (${videoChannel.displayName}) to confirm`, |
118 | this.i18n( | 116 | |
119 | 'Please type the display name of the video channel ({{displayName}}) to confirm', | 117 | $localize`Delete` |
120 | { displayName: videoChannel.displayName } | ||
121 | ), | ||
122 | videoChannel.displayName, | ||
123 | this.i18n('Delete') | ||
124 | ) | 118 | ) |
125 | if (res === false) return | 119 | if (res === false) return |
126 | 120 | ||
@@ -128,9 +122,7 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
128 | .subscribe( | 122 | .subscribe( |
129 | () => { | 123 | () => { |
130 | this.loadVideoChannels() | 124 | this.loadVideoChannels() |
131 | this.notifier.success( | 125 | this.notifier.success($localize`Video channel ${videoChannel.displayName} deleted.`) |
132 | this.i18n('Video channel {{videoChannelName}} deleted.', { videoChannelName: videoChannel.displayName }) | ||
133 | ) | ||
134 | }, | 126 | }, |
135 | 127 | ||
136 | error => this.notifier.error(error.message) | 128 | error => this.notifier.error(error.message) |
@@ -139,7 +131,7 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
139 | 131 | ||
140 | private loadVideoChannels () { | 132 | private loadVideoChannels () { |
141 | this.authService.userInformationLoaded | 133 | this.authService.userInformationLoaded |
142 | .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account, null, true, this.channelsSearch))) | 134 | .pipe(mergeMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account, null, true, this.channelsSearch))) |
143 | .subscribe(res => { | 135 | .subscribe(res => { |
144 | this.videoChannels = res.data | 136 | this.videoChannels = res.data |
145 | this.totalItems = res.total | 137 | this.totalItems = res.total |
@@ -149,10 +141,10 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
149 | labels: v.viewsPerDay.map(day => day.date.toLocaleDateString()), | 141 | labels: v.viewsPerDay.map(day => day.date.toLocaleDateString()), |
150 | datasets: [ | 142 | datasets: [ |
151 | { | 143 | { |
152 | label: this.i18n('Views for the day'), | 144 | label: $localize`Views for the day`, |
153 | data: v.viewsPerDay.map(day => day.views), | 145 | data: v.viewsPerDay.map(day => day.views), |
154 | fill: false, | 146 | fill: false, |
155 | borderColor: "#c6c6c6" | 147 | borderColor: '#c6c6c6' |
156 | } | 148 | } |
157 | ] | 149 | ] |
158 | } as ChartData)) | 150 | } as ChartData)) |
@@ -160,13 +152,15 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
160 | // chart options that depend on chart data: | 152 | // chart options that depend on chart data: |
161 | // we don't want to skew values and have min at 0, so we define what the floor/ceiling is here | 153 | // we don't want to skew values and have min at 0, so we define what the floor/ceiling is here |
162 | this.videoChannelsMinimumDailyViews = min( | 154 | this.videoChannelsMinimumDailyViews = min( |
163 | this.videoChannels.map(v => minBy( // compute local minimum daily views for each channel, by their "views" attribute | 155 | // compute local minimum daily views for each channel, by their "views" attribute |
156 | this.videoChannels.map(v => minBy( | ||
164 | v.viewsPerDay, | 157 | v.viewsPerDay, |
165 | day => day.views | 158 | day => day.views |
166 | ).views) // the object returned is a ViewPerDate, so we still need to get the views attribute | 159 | ).views) // the object returned is a ViewPerDate, so we still need to get the views attribute |
167 | ) | 160 | ) |
168 | this.videoChannelsMaximumDailyViews = max( | 161 | this.videoChannelsMaximumDailyViews = max( |
169 | this.videoChannels.map(v => maxBy( // compute local maximum daily views for each channel, by their "views" attribute | 162 | // compute local maximum daily views for each channel, by their "views" attribute |
163 | this.videoChannels.map(v => maxBy( | ||
170 | v.viewsPerDay, | 164 | v.viewsPerDay, |
171 | day => day.views | 165 | day => day.views |
172 | ).views) // the object returned is a ViewPerDate, so we still need to get the views attribute | 166 | ).views) // the object returned is a ViewPerDate, so we still need to get the views attribute |