diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-03-24 01:12:30 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-03-31 10:29:24 +0200 |
commit | 747c562837e37f2fa455e8ef62165e9bb4e365f1 (patch) | |
tree | ae7628afb2865de93b195b064df1dace2e524dbe | |
parent | 8165d00ac6263cf3c0d61d450960ef36635084ff (diff) | |
download | PeerTube-747c562837e37f2fa455e8ef62165e9bb4e365f1.tar.gz PeerTube-747c562837e37f2fa455e8ef62165e9bb4e365f1.tar.zst PeerTube-747c562837e37f2fa455e8ef62165e9bb4e365f1.zip |
Put channel stats behind withStats flag
6 files changed, 31 insertions, 16 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 eeab3a8dd..27a157621 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 | |||
@@ -57,7 +57,7 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
57 | min: Math.max(0, this.videoChannelsMinimumDailyViews - (3 * this.videoChannelsMaximumDailyViews / 100)), | 57 | min: Math.max(0, this.videoChannelsMinimumDailyViews - (3 * this.videoChannelsMaximumDailyViews / 100)), |
58 | max: this.videoChannelsMaximumDailyViews | 58 | max: this.videoChannelsMaximumDailyViews |
59 | } | 59 | } |
60 | }], | 60 | }] |
61 | }, | 61 | }, |
62 | layout: { | 62 | layout: { |
63 | padding: { | 63 | padding: { |
@@ -68,7 +68,7 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
68 | } | 68 | } |
69 | }, | 69 | }, |
70 | elements: { | 70 | elements: { |
71 | point:{ | 71 | point: { |
72 | radius: 0 | 72 | radius: 0 |
73 | } | 73 | } |
74 | }, | 74 | }, |
@@ -76,14 +76,12 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
76 | mode: 'index', | 76 | mode: 'index', |
77 | intersect: false, | 77 | intersect: false, |
78 | custom: function (tooltip: any) { | 78 | custom: function (tooltip: any) { |
79 | if (!tooltip) return; | 79 | if (!tooltip) return |
80 | // disable displaying the color box; | 80 | // disable displaying the color box |
81 | tooltip.displayColors = false; | 81 | tooltip.displayColors = false |
82 | }, | 82 | }, |
83 | callbacks: { | 83 | callbacks: { |
84 | label: function (tooltip: any, data: any) { | 84 | label: (tooltip: any, data: any) => `${tooltip.value} views` |
85 | return `${tooltip.value} views`; | ||
86 | } | ||
87 | } | 85 | } |
88 | }, | 86 | }, |
89 | hover: { | 87 | hover: { |
@@ -124,7 +122,7 @@ export class MyAccountVideoChannelsComponent implements OnInit { | |||
124 | 122 | ||
125 | private loadVideoChannels () { | 123 | private loadVideoChannels () { |
126 | this.authService.userInformationLoaded | 124 | this.authService.userInformationLoaded |
127 | .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account))) | 125 | .pipe(flatMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account, null, true))) |
128 | .subscribe(res => { | 126 | .subscribe(res => { |
129 | this.videoChannels = res.data | 127 | this.videoChannels = res.data |
130 | this.videoChannelsData = this.videoChannels.map(v => ({ | 128 | this.videoChannelsData = this.videoChannels.map(v => ({ |
diff --git a/client/src/app/shared/video-channel/video-channel.model.ts b/client/src/app/shared/video-channel/video-channel.model.ts index ee3288d7a..c93af0ca5 100644 --- a/client/src/app/shared/video-channel/video-channel.model.ts +++ b/client/src/app/shared/video-channel/video-channel.model.ts | |||
@@ -25,7 +25,7 @@ export class VideoChannel extends Actor implements ServerVideoChannel { | |||
25 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) | 25 | this.nameWithHostForced = Actor.CREATE_BY_STRING(this.name, this.host, true) |
26 | 26 | ||
27 | if (hash.viewsPerDay) { | 27 | if (hash.viewsPerDay) { |
28 | this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date)})) | 28 | this.viewsPerDay = hash.viewsPerDay.map(v => ({ ...v, date: new Date(v.date) })) |
29 | } | 29 | } |
30 | 30 | ||
31 | if (hash.ownerAccount) { | 31 | if (hash.ownerAccount) { |
diff --git a/client/src/app/shared/video-channel/video-channel.service.ts b/client/src/app/shared/video-channel/video-channel.service.ts index adb4f4819..0e036bda7 100644 --- a/client/src/app/shared/video-channel/video-channel.service.ts +++ b/client/src/app/shared/video-channel/video-channel.service.ts | |||
@@ -44,13 +44,18 @@ export class VideoChannelService { | |||
44 | ) | 44 | ) |
45 | } | 45 | } |
46 | 46 | ||
47 | listAccountVideoChannels (account: Account, componentPagination?: ComponentPaginationLight): Observable<ResultList<VideoChannel>> { | 47 | listAccountVideoChannels ( |
48 | account: Account, | ||
49 | componentPagination?: ComponentPaginationLight, | ||
50 | withStats = false | ||
51 | ): Observable<ResultList<VideoChannel>> { | ||
48 | const pagination = componentPagination | 52 | const pagination = componentPagination |
49 | ? this.restService.componentPaginationToRestPagination(componentPagination) | 53 | ? this.restService.componentPaginationToRestPagination(componentPagination) |
50 | : { start: 0, count: 20 } | 54 | : { start: 0, count: 20 } |
51 | 55 | ||
52 | let params = new HttpParams() | 56 | let params = new HttpParams() |
53 | params = this.restService.addRestGetParams(params, pagination) | 57 | params = this.restService.addRestGetParams(params, pagination) |
58 | params = params.set('withStats', withStats + '') | ||
54 | 59 | ||
55 | const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channels' | 60 | const url = AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channels' |
56 | return this.authHttp.get<ResultList<VideoChannelServer>>(url, { params }) | 61 | return this.authHttp.get<ResultList<VideoChannelServer>>(url, { params }) |
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index f354ccf24..f8d2bad8b 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts | |||
@@ -17,7 +17,8 @@ import { | |||
17 | accountsSortValidator, | 17 | accountsSortValidator, |
18 | ensureAuthUserOwnsAccountValidator, | 18 | ensureAuthUserOwnsAccountValidator, |
19 | videoChannelsSortValidator, | 19 | videoChannelsSortValidator, |
20 | videosSortValidator | 20 | videosSortValidator, |
21 | videoChannelStatsValidator | ||
21 | } from '../../middlewares/validators' | 22 | } from '../../middlewares/validators' |
22 | import { AccountModel } from '../../models/account/account' | 23 | import { AccountModel } from '../../models/account/account' |
23 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | 24 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
@@ -56,6 +57,7 @@ accountsRouter.get('/:accountName/videos', | |||
56 | 57 | ||
57 | accountsRouter.get('/:accountName/video-channels', | 58 | accountsRouter.get('/:accountName/video-channels', |
58 | asyncMiddleware(accountNameWithHostGetValidator), | 59 | asyncMiddleware(accountNameWithHostGetValidator), |
60 | videoChannelStatsValidator, | ||
59 | paginationValidator, | 61 | paginationValidator, |
60 | videoChannelsSortValidator, | 62 | videoChannelsSortValidator, |
61 | setDefaultSort, | 63 | setDefaultSort, |
@@ -116,7 +118,8 @@ async function listAccountChannels (req: express.Request, res: express.Response) | |||
116 | accountId: res.locals.account.id, | 118 | accountId: res.locals.account.id, |
117 | start: req.query.start, | 119 | start: req.query.start, |
118 | count: req.query.count, | 120 | count: req.query.count, |
119 | sort: req.query.sort | 121 | sort: req.query.sort, |
122 | withStats: req.query.withStats | ||
120 | } | 123 | } |
121 | 124 | ||
122 | const resultList = await VideoChannelModel.listByAccount(options) | 125 | const resultList = await VideoChannelModel.listByAccount(options) |
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index ebce14714..882fb2b84 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { UserRight } from '../../../../shared' | 3 | import { UserRight } from '../../../../shared' |
4 | import { | 4 | import { |
5 | isVideoChannelDescriptionValid, | 5 | isVideoChannelDescriptionValid, |
@@ -128,6 +128,15 @@ const localVideoChannelValidator = [ | |||
128 | } | 128 | } |
129 | ] | 129 | ] |
130 | 130 | ||
131 | const videoChannelStatsValidator = [ | ||
132 | query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), | ||
133 | |||
134 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
135 | if (areValidationErrors(req, res)) return | ||
136 | return next() | ||
137 | } | ||
138 | ] | ||
139 | |||
131 | // --------------------------------------------------------------------------- | 140 | // --------------------------------------------------------------------------- |
132 | 141 | ||
133 | export { | 142 | export { |
@@ -135,7 +144,8 @@ export { | |||
135 | videoChannelsUpdateValidator, | 144 | videoChannelsUpdateValidator, |
136 | videoChannelsRemoveValidator, | 145 | videoChannelsRemoveValidator, |
137 | videoChannelsNameWithHostValidator, | 146 | videoChannelsNameWithHostValidator, |
138 | localVideoChannelValidator | 147 | localVideoChannelValidator, |
148 | videoChannelStatsValidator | ||
139 | } | 149 | } |
140 | 150 | ||
141 | // --------------------------------------------------------------------------- | 151 | // --------------------------------------------------------------------------- |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 128915af3..5e6541837 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -412,7 +412,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
412 | 412 | ||
413 | const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR ] | 413 | const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR ] |
414 | 414 | ||
415 | options.withStats = true // TODO: remove beyond after initial tests | ||
416 | if (options.withStats) { | 415 | if (options.withStats) { |
417 | scopes.push({ | 416 | scopes.push({ |
418 | method: [ ScopeNames.WITH_STATS, { daysPrior: 30 } as AvailableWithStatsOptions ] | 417 | method: [ ScopeNames.WITH_STATS, { daysPrior: 30 } as AvailableWithStatsOptions ] |