aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/+admin/overview/videos/video-list.component.ts4
-rw-r--r--client/src/app/+my-library/my-videos/my-videos.component.html6
-rw-r--r--client/src/app/+my-library/my-videos/my-videos.component.ts77
-rw-r--r--client/src/app/+stats/index.ts1
-rw-r--r--client/src/app/+stats/stats-routing.module.ts25
-rw-r--r--client/src/app/+stats/stats.module.ts27
-rw-r--r--client/src/app/+stats/video/index.ts2
-rw-r--r--client/src/app/+stats/video/video-stats.component.html38
-rw-r--r--client/src/app/+stats/video/video-stats.component.scss54
-rw-r--r--client/src/app/+stats/video/video-stats.component.ts295
-rw-r--r--client/src/app/+stats/video/video-stats.service.ts34
-rw-r--r--client/src/app/+video-studio/edit/index.ts1
-rw-r--r--client/src/app/+video-studio/video-studio-routing.module.ts5
-rw-r--r--client/src/app/+video-studio/video-studio.module.ts5
-rw-r--r--client/src/app/+videos/+video-edit/video-add.component.scss31
-rw-r--r--client/src/app/+videos/+video-watch/shared/action-buttons/action-buttons.component.ts3
-rw-r--r--client/src/app/+videos/+video-watch/video-watch.component.ts13
-rw-r--r--client/src/app/app-routing.module.ts6
-rw-r--r--client/src/app/shared/shared-icons/global-icon.component.ts3
-rw-r--r--client/src/app/shared/shared-main/angular/number-formatter.pipe.ts1
-rw-r--r--client/src/app/shared/shared-main/shared-main.module.ts3
-rw-r--r--client/src/app/shared/shared-main/video/index.ts1
-rw-r--r--client/src/app/shared/shared-main/video/video.model.ts11
-rw-r--r--client/src/app/shared/shared-main/video/video.resolver.ts (renamed from client/src/app/+video-studio/edit/video-studio-edit.resolver.ts)5
-rw-r--r--client/src/app/shared/shared-main/video/video.service.ts4
-rw-r--r--client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts17
-rw-r--r--client/src/app/shared/shared-video-miniature/video-miniature.component.ts23
27 files changed, 578 insertions, 117 deletions
diff --git a/client/src/app/+admin/overview/videos/video-list.component.ts b/client/src/app/+admin/overview/videos/video-list.component.ts
index 4aed5221b..82ff372aa 100644
--- a/client/src/app/+admin/overview/videos/video-list.component.ts
+++ b/client/src/app/+admin/overview/videos/video-list.component.ts
@@ -41,7 +41,9 @@ export class VideoListComponent extends RestTable implements OnInit {
41 mute: true, 41 mute: true,
42 liveInfo: false, 42 liveInfo: false,
43 removeFiles: true, 43 removeFiles: true,
44 transcoding: true 44 transcoding: true,
45 studio: true,
46 stats: true
45 } 47 }
46 48
47 loading = true 49 loading = true
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.html b/client/src/app/+my-library/my-videos/my-videos.component.html
index 9f81f0ad7..7f12e2c71 100644
--- a/client/src/app/+my-library/my-videos/my-videos.component.html
+++ b/client/src/app/+my-library/my-videos/my-videos.component.html
@@ -55,10 +55,12 @@
55 <div class="action-button"> 55 <div class="action-button">
56 <my-edit-button label [routerLink]="[ '/videos', 'update', video.uuid ]"></my-edit-button> 56 <my-edit-button label [routerLink]="[ '/videos', 'update', video.uuid ]"></my-edit-button>
57 57
58 <my-action-dropdown [actions]="videoActions" [entry]="{ video: video }"></my-action-dropdown> 58 <my-video-actions-dropdown
59 [video]="video" [displayOptions]="videoDropdownDisplayOptions" [moreActions]="moreVideoActions"
60 [buttonStyled]="true" buttonDirection="horizontal" (videoRemoved)="onVideoRemoved(video)"
61 ></my-video-actions-dropdown>
59 </div> 62 </div>
60 </ng-template> 63 </ng-template>
61</my-videos-selection> 64</my-videos-selection>
62 65
63<my-video-change-ownership #videoChangeOwnershipModal></my-video-change-ownership> 66<my-video-change-ownership #videoChangeOwnershipModal></my-video-change-ownership>
64<my-live-stream-information #liveStreamInformationModal></my-live-stream-information>
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.ts b/client/src/app/+my-library/my-videos/my-videos.component.ts
index a364b9b6a..8da2bc890 100644
--- a/client/src/app/+my-library/my-videos/my-videos.component.ts
+++ b/client/src/app/+my-library/my-videos/my-videos.component.ts
@@ -8,7 +8,12 @@ import { immutableAssign } from '@app/helpers'
8import { AdvancedInputFilter } from '@app/shared/shared-forms' 8import { AdvancedInputFilter } from '@app/shared/shared-forms'
9import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' 9import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
10import { LiveStreamInformationComponent } from '@app/shared/shared-video-live' 10import { LiveStreamInformationComponent } from '@app/shared/shared-video-live'
11import { MiniatureDisplayOptions, SelectionType, VideosSelectionComponent } from '@app/shared/shared-video-miniature' 11import {
12 MiniatureDisplayOptions,
13 SelectionType,
14 VideoActionsDisplayType,
15 VideosSelectionComponent
16} from '@app/shared/shared-video-miniature'
12import { VideoChannel, VideoSortField } from '@shared/models' 17import { VideoChannel, VideoSortField } from '@shared/models'
13import { VideoChangeOwnershipComponent } from './modals/video-change-ownership.component' 18import { VideoChangeOwnershipComponent } from './modals/video-change-ownership.component'
14 19
@@ -37,8 +42,23 @@ export class MyVideosComponent implements OnInit, DisableForReuseHook {
37 state: true, 42 state: true,
38 blacklistInfo: true 43 blacklistInfo: true
39 } 44 }
45 videoDropdownDisplayOptions: VideoActionsDisplayType = {
46 playlist: false,
47 download: false,
48 update: false,
49 blacklist: false,
50 delete: true,
51 report: false,
52 duplicate: false,
53 mute: false,
54 liveInfo: false,
55 removeFiles: false,
56 transcoding: false,
57 studio: true,
58 stats: true
59 }
40 60
41 videoActions: DropdownAction<{ video: Video }>[] = [] 61 moreVideoActions: DropdownAction<{ video: Video }>[][] = []
42 62
43 videos: Video[] = [] 63 videos: Video[] = []
44 getVideosObservableFunction = this.getVideosObservable.bind(this) 64 getVideosObservableFunction = this.getVideosObservable.bind(this)
@@ -172,60 +192,27 @@ export class MyVideosComponent implements OnInit, DisableForReuseHook {
172 }) 192 })
173 } 193 }
174 194
175 async deleteVideo (video: Video) { 195 onVideoRemoved (video: Video) {
176 const res = await this.confirmService.confirm( 196 this.removeVideoFromArray(video.id)
177 $localize`Do you really want to delete ${video.name}?`,
178 $localize`Delete`
179 )
180 if (res === false) return
181
182 this.videoService.removeVideo(video.id)
183 .subscribe({
184 next: () => {
185 this.notifier.success($localize`Video ${video.name} deleted.`)
186 this.removeVideoFromArray(video.id)
187 },
188
189 error: err => this.notifier.error(err.message)
190 })
191 } 197 }
192 198
193 changeOwnership (video: Video) { 199 changeOwnership (video: Video) {
194 this.videoChangeOwnershipModal.show(video) 200 this.videoChangeOwnershipModal.show(video)
195 } 201 }
196 202
197 displayLiveInformation (video: Video) {
198 this.liveStreamInformationModal.show(video)
199 }
200
201 private removeVideoFromArray (id: number) { 203 private removeVideoFromArray (id: number) {
202 this.videos = this.videos.filter(v => v.id !== id) 204 this.videos = this.videos.filter(v => v.id !== id)
203 } 205 }
204 206
205 private buildActions () { 207 private buildActions () {
206 this.videoActions = [ 208 this.moreVideoActions = [
207 { 209 [
208 label: $localize`Studio`, 210 {
209 linkBuilder: ({ video }) => [ '/studio/edit', video.uuid ], 211 label: $localize`Change ownership`,
210 isDisplayed: ({ video }) => video.isEditableBy(this.authService.getUser(), this.serverService.getHTMLConfig().videoStudio.enabled), 212 handler: ({ video }) => this.changeOwnership(video),
211 iconName: 'film' 213 iconName: 'ownership-change'
212 }, 214 }
213 { 215 ]
214 label: $localize`Display live information`,
215 handler: ({ video }) => this.displayLiveInformation(video),
216 isDisplayed: ({ video }) => video.isLive,
217 iconName: 'live'
218 },
219 {
220 label: $localize`Change ownership`,
221 handler: ({ video }) => this.changeOwnership(video),
222 iconName: 'ownership-change'
223 },
224 {
225 label: $localize`Delete`,
226 handler: ({ video }) => this.deleteVideo(video),
227 iconName: 'delete'
228 }
229 ] 216 ]
230 } 217 }
231} 218}
diff --git a/client/src/app/+stats/index.ts b/client/src/app/+stats/index.ts
new file mode 100644
index 000000000..d880024a5
--- /dev/null
+++ b/client/src/app/+stats/index.ts
@@ -0,0 +1 @@
export * from './stats.module'
diff --git a/client/src/app/+stats/stats-routing.module.ts b/client/src/app/+stats/stats-routing.module.ts
new file mode 100644
index 000000000..59519a703
--- /dev/null
+++ b/client/src/app/+stats/stats-routing.module.ts
@@ -0,0 +1,25 @@
1import { NgModule } from '@angular/core'
2import { RouterModule, Routes } from '@angular/router'
3import { VideoResolver } from '@app/shared/shared-main'
4import { VideoStatsComponent } from './video'
5
6const statsRoutes: Routes = [
7 {
8 path: 'videos/:videoId',
9 component: VideoStatsComponent,
10 data: {
11 meta: {
12 title: $localize`Video stats`
13 }
14 },
15 resolve: {
16 video: VideoResolver
17 }
18 }
19]
20
21@NgModule({
22 imports: [ RouterModule.forChild(statsRoutes) ],
23 exports: [ RouterModule ]
24})
25export class StatsRoutingModule {}
diff --git a/client/src/app/+stats/stats.module.ts b/client/src/app/+stats/stats.module.ts
new file mode 100644
index 000000000..0497576e7
--- /dev/null
+++ b/client/src/app/+stats/stats.module.ts
@@ -0,0 +1,27 @@
1import { ChartModule } from 'primeng/chart'
2import { NgModule } from '@angular/core'
3import { SharedGlobalIconModule } from '@app/shared/shared-icons'
4import { SharedMainModule } from '@app/shared/shared-main'
5import { StatsRoutingModule } from './stats-routing.module'
6import { VideoStatsComponent, VideoStatsService } from './video'
7
8@NgModule({
9 imports: [
10 StatsRoutingModule,
11
12 SharedMainModule,
13 SharedGlobalIconModule,
14
15 ChartModule
16 ],
17
18 declarations: [
19 VideoStatsComponent
20 ],
21
22 exports: [],
23 providers: [
24 VideoStatsService
25 ]
26})
27export class StatsModule { }
diff --git a/client/src/app/+stats/video/index.ts b/client/src/app/+stats/video/index.ts
new file mode 100644
index 000000000..e948d4f4e
--- /dev/null
+++ b/client/src/app/+stats/video/index.ts
@@ -0,0 +1,2 @@
1export * from './video-stats.component'
2export * from './video-stats.service'
diff --git a/client/src/app/+stats/video/video-stats.component.html b/client/src/app/+stats/video/video-stats.component.html
new file mode 100644
index 000000000..ef43c9fba
--- /dev/null
+++ b/client/src/app/+stats/video/video-stats.component.html
@@ -0,0 +1,38 @@
1<div class="margin-content">
2 <h1 class="title-page title-page-single" i18n>Stats for {{ video.name }}</h1>
3
4 <div class="overall-stats-embed">
5 <div class="overall-stats">
6 <div *ngFor="let card of overallStatCards" class="card overall-stats-card">
7 <div class="label">{{ card.label }}</div>
8 <div class="value">{{ card.value }}</div>
9 <div *ngIf="card.moreInfo" class="more-info">{{ card.moreInfo }}</div>
10 </div>
11 </div>
12
13 <my-embed [video]="video"></my-embed>
14 </div>
15
16 <div class="timeserie">
17 <div ngbNav #nav="ngbNav" [activeId]="activeGraphId" (activeIdChange)="onChartChange($event)" class="nav-tabs">
18
19 <ng-container *ngFor="let availableChart of availableCharts" [ngbNavItem]="availableChart.id">
20 <a ngbNavLink i18n>
21 <span>{{ availableChart.label }}</span>
22 </a>
23
24 <ng-template ngbNavContent>
25 <div [ngStyle]="{ 'min-height': chartHeight }">
26 <p-chart
27 *ngIf="chartOptions[availableChart.id]"
28 [height]="chartHeight" [width]="chartWidth"
29 [type]="chartOptions[availableChart.id].type" [options]="chartOptions[availableChart.id].options" [data]="chartOptions[availableChart.id].data"
30 ></p-chart>
31 </div>
32 </ng-template>
33 </ng-container>
34 </div>
35
36 <div [ngbNavOutlet]="nav"></div>
37 </div>
38</div>
diff --git a/client/src/app/+stats/video/video-stats.component.scss b/client/src/app/+stats/video/video-stats.component.scss
new file mode 100644
index 000000000..190499b5c
--- /dev/null
+++ b/client/src/app/+stats/video/video-stats.component.scss
@@ -0,0 +1,54 @@
1@use '_variables' as *;
2@use '_mixins' as *;
3@use '_nav' as *;
4
5.overall-stats-embed {
6 display: flex;
7 justify-content: space-between;
8}
9
10.overall-stats {
11 display: flex;
12 flex-wrap: wrap;
13}
14
15.overall-stats-card {
16 display: flex;
17 justify-content: center;
18 align-items: center;
19 height: fit-content;
20 min-height: 100px;
21 min-width: 200px;
22 margin-right: 15px;
23 background-color: pvar(--submenuBackgroundColor);
24
25 .label,
26 .more-info {
27 font-size: 14px;
28 }
29
30 .label {
31 color: pvar(--greyForegroundColor);
32 font-weight: $font-semibold;
33 opacity: 0.8;
34 }
35
36 .value {
37 font-size: 24px;
38 font-weight: $font-semibold;
39 }
40}
41
42my-embed {
43 display: block;
44 max-width: 500px;
45 width: 100%;
46}
47
48.tab-content {
49 margin-top: 15px;
50}
51
52.nav-tabs {
53 @include peertube-nav-tabs($border-width: 2px);
54}
diff --git a/client/src/app/+stats/video/video-stats.component.ts b/client/src/app/+stats/video/video-stats.component.ts
new file mode 100644
index 000000000..05319539b
--- /dev/null
+++ b/client/src/app/+stats/video/video-stats.component.ts
@@ -0,0 +1,295 @@
1import { ChartConfiguration, ChartData } from 'chart.js'
2import { Observable, of } from 'rxjs'
3import { Component, OnInit } from '@angular/core'
4import { ActivatedRoute } from '@angular/router'
5import { Notifier } from '@app/core'
6import { NumberFormatterPipe, VideoDetails } from '@app/shared/shared-main'
7import { secondsToTime } from '@shared/core-utils'
8import { VideoStatsOverall, VideoStatsRetention, VideoStatsTimeserie, VideoStatsTimeserieMetric } from '@shared/models/videos'
9import { VideoStatsService } from './video-stats.service'
10
11type ActiveGraphId = VideoStatsTimeserieMetric | 'retention' | 'countries'
12
13type CountryData = { name: string, viewers: number }[]
14
15type ChartIngestData = VideoStatsTimeserie | VideoStatsRetention | CountryData
16type ChartBuilderResult = {
17 type: 'line' | 'bar'
18 data: ChartData<'line' | 'bar'>
19 displayLegend: boolean
20}
21
22@Component({
23 templateUrl: './video-stats.component.html',
24 styleUrls: [ './video-stats.component.scss' ],
25 providers: [ NumberFormatterPipe ]
26})
27export class VideoStatsComponent implements OnInit {
28 overallStatCards: { label: string, value: string | number, moreInfo?: string }[] = []
29
30 chartOptions: { [ id in ActiveGraphId ]?: ChartConfiguration<'line' | 'bar'> } = {}
31 chartHeight = '300px'
32 chartWidth: string = null
33
34 availableCharts = [
35 {
36 id: 'viewers',
37 label: $localize`Viewers`
38 },
39 {
40 id: 'aggregateWatchTime',
41 label: $localize`Watch time`
42 },
43 {
44 id: 'retention',
45 label: $localize`Retention`
46 },
47 {
48 id: 'countries',
49 label: $localize`Countries`
50 }
51 ]
52
53 activeGraphId: ActiveGraphId = 'viewers'
54
55 video: VideoDetails
56
57 countries: CountryData = []
58
59 constructor (
60 private route: ActivatedRoute,
61 private notifier: Notifier,
62 private statsService: VideoStatsService,
63 private numberFormatter: NumberFormatterPipe
64 ) {}
65
66 ngOnInit () {
67 this.video = this.route.snapshot.data.video
68
69 this.loadOverallStats()
70 this.loadChart()
71 }
72
73 hasCountries () {
74 return this.countries.length !== 0
75 }
76
77 onChartChange (newActive: ActiveGraphId) {
78 this.activeGraphId = newActive
79
80 this.loadChart()
81 }
82
83 private loadOverallStats () {
84 this.statsService.getOverallStats(this.video.uuid)
85 .subscribe({
86 next: res => {
87 this.countries = res.countries.slice(0, 10).map(c => ({
88 name: this.countryCodeToName(c.isoCode),
89 viewers: c.viewers
90 }))
91
92 this.buildOverallStatCard(res)
93 },
94
95 error: err => this.notifier.error(err.message)
96 })
97 }
98
99 private buildOverallStatCard (overallStats: VideoStatsOverall) {
100 this.overallStatCards = [
101 {
102 label: $localize`Views`,
103 value: this.numberFormatter.transform(overallStats.views)
104 },
105 {
106 label: $localize`Comments`,
107 value: this.numberFormatter.transform(overallStats.comments)
108 },
109 {
110 label: $localize`Likes`,
111 value: this.numberFormatter.transform(overallStats.likes)
112 },
113 {
114 label: $localize`Average watch time`,
115 value: secondsToTime(overallStats.averageWatchTime)
116 },
117 {
118 label: $localize`Peak viewers`,
119 value: this.numberFormatter.transform(overallStats.viewersPeak),
120 moreInfo: $localize`at ${new Date(overallStats.viewersPeakDate).toLocaleString()}`
121 }
122 ]
123 }
124
125 private loadChart () {
126 const obsBuilders: { [ id in ActiveGraphId ]: Observable<ChartIngestData> } = {
127 retention: this.statsService.getRetentionStats(this.video.uuid),
128 aggregateWatchTime: this.statsService.getTimeserieStats(this.video.uuid, 'aggregateWatchTime'),
129 viewers: this.statsService.getTimeserieStats(this.video.uuid, 'viewers'),
130 countries: of(this.countries)
131 }
132
133 obsBuilders[this.activeGraphId].subscribe({
134 next: res => {
135 this.chartOptions[this.activeGraphId] = this.buildChartOptions(this.activeGraphId, res)
136 },
137
138 error: err => this.notifier.error(err.message)
139 })
140 }
141
142 private buildChartOptions (
143 graphId: ActiveGraphId,
144 rawData: ChartIngestData
145 ): ChartConfiguration<'line' | 'bar'> {
146 const dataBuilders: {
147 [ id in ActiveGraphId ]: (rawData: ChartIngestData) => ChartBuilderResult
148 } = {
149 retention: (rawData: VideoStatsRetention) => this.buildRetentionChartOptions(rawData),
150 aggregateWatchTime: (rawData: VideoStatsTimeserie) => this.buildTimeserieChartOptions(rawData),
151 viewers: (rawData: VideoStatsTimeserie) => this.buildTimeserieChartOptions(rawData),
152 countries: (rawData: CountryData) => this.buildCountryChartOptions(rawData)
153 }
154
155 const { type, data, displayLegend } = dataBuilders[graphId](rawData)
156
157 return {
158 type,
159 data,
160
161 options: {
162 responsive: true,
163
164 scales: {
165 y: {
166 beginAtZero: true,
167
168 max: this.activeGraphId === 'retention'
169 ? 100
170 : undefined,
171
172 ticks: {
173 callback: value => this.formatTick(graphId, value)
174 }
175 }
176 },
177
178 plugins: {
179 legend: {
180 display: displayLegend
181 },
182 tooltip: {
183 callbacks: {
184 label: value => this.formatTick(graphId, value.raw as number | string)
185 }
186 }
187 }
188 }
189 }
190 }
191
192 private buildRetentionChartOptions (rawData: VideoStatsRetention) {
193 const labels: string[] = []
194 const data: number[] = []
195
196 for (const d of rawData.data) {
197 labels.push(secondsToTime(d.second))
198 data.push(d.retentionPercent)
199 }
200
201 return {
202 type: 'line' as 'line',
203
204 displayLegend: false,
205
206 data: {
207 labels,
208 datasets: [
209 {
210 data,
211 borderColor: this.buildChartColor()
212 }
213 ]
214 }
215 }
216 }
217
218 private buildTimeserieChartOptions (rawData: VideoStatsTimeserie) {
219 const labels: string[] = []
220 const data: number[] = []
221
222 for (const d of rawData.data) {
223 labels.push(new Date(d.date).toLocaleDateString())
224 data.push(d.value)
225 }
226
227 return {
228 type: 'line' as 'line',
229
230 displayLegend: false,
231
232 data: {
233 labels,
234 datasets: [
235 {
236 data,
237 borderColor: this.buildChartColor()
238 }
239 ]
240 }
241 }
242 }
243
244 private buildCountryChartOptions (rawData: CountryData) {
245 const labels: string[] = []
246 const data: number[] = []
247
248 for (const d of rawData) {
249 labels.push(d.name)
250 data.push(d.viewers)
251 }
252
253 return {
254 type: 'bar' as 'bar',
255
256 displayLegend: true,
257
258 options: {
259 indexAxis: 'y'
260 },
261
262 data: {
263 labels,
264 datasets: [
265 {
266 label: $localize`Viewers`,
267 backgroundColor: this.buildChartColor(),
268 maxBarThickness: 20,
269 data
270 }
271 ]
272 }
273 }
274 }
275
276 private buildChartColor () {
277 return getComputedStyle(document.body).getPropertyValue('--mainColorLighter')
278 }
279
280 private formatTick (graphId: ActiveGraphId, value: number | string) {
281 if (graphId === 'retention') return value + ' %'
282 if (graphId === 'aggregateWatchTime') return secondsToTime(+value)
283
284 return value.toLocaleString()
285 }
286
287 private countryCodeToName (code: string) {
288 const intl: any = Intl
289 if (!intl.DisplayNames) return code
290
291 const regionNames = new intl.DisplayNames([], { type: 'region' })
292
293 return regionNames.of(code)
294 }
295}
diff --git a/client/src/app/+stats/video/video-stats.service.ts b/client/src/app/+stats/video/video-stats.service.ts
new file mode 100644
index 000000000..8f9d48f60
--- /dev/null
+++ b/client/src/app/+stats/video/video-stats.service.ts
@@ -0,0 +1,34 @@
1import { catchError } from 'rxjs'
2import { environment } from 'src/environments/environment'
3import { HttpClient } from '@angular/common/http'
4import { Injectable } from '@angular/core'
5import { RestExtractor } from '@app/core'
6import { VideoService } from '@app/shared/shared-main'
7import { VideoStatsOverall, VideoStatsRetention, VideoStatsTimeserie, VideoStatsTimeserieMetric } from '@shared/models/videos'
8
9@Injectable({
10 providedIn: 'root'
11})
12export class VideoStatsService {
13 static BASE_VIDEO_STATS_URL = environment.apiUrl + '/api/v1/videos/'
14
15 constructor (
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor
18 ) { }
19
20 getOverallStats (videoId: string) {
21 return this.authHttp.get<VideoStatsOverall>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/overall')
22 .pipe(catchError(err => this.restExtractor.handleError(err)))
23 }
24
25 getTimeserieStats (videoId: string, metric: VideoStatsTimeserieMetric) {
26 return this.authHttp.get<VideoStatsTimeserie>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/timeseries/' + metric)
27 .pipe(catchError(err => this.restExtractor.handleError(err)))
28 }
29
30 getRetentionStats (videoId: string) {
31 return this.authHttp.get<VideoStatsRetention>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/stats/retention')
32 .pipe(catchError(err => this.restExtractor.handleError(err)))
33 }
34}
diff --git a/client/src/app/+video-studio/edit/index.ts b/client/src/app/+video-studio/edit/index.ts
index ff1d77fc0..15b57e1c8 100644
--- a/client/src/app/+video-studio/edit/index.ts
+++ b/client/src/app/+video-studio/edit/index.ts
@@ -1,2 +1 @@
1export * from './video-studio-edit.component' export * from './video-studio-edit.component'
2export * from './video-studio-edit.resolver'
diff --git a/client/src/app/+video-studio/video-studio-routing.module.ts b/client/src/app/+video-studio/video-studio-routing.module.ts
index bcd9b79a5..4c08631a1 100644
--- a/client/src/app/+video-studio/video-studio-routing.module.ts
+++ b/client/src/app/+video-studio/video-studio-routing.module.ts
@@ -1,6 +1,7 @@
1import { NgModule } from '@angular/core' 1import { NgModule } from '@angular/core'
2import { RouterModule, Routes } from '@angular/router' 2import { RouterModule, Routes } from '@angular/router'
3import { VideoStudioEditComponent, VideoStudioEditResolver } from './edit' 3import { VideoResolver } from '@app/shared/shared-main'
4import { VideoStudioEditComponent } from './edit'
4 5
5const videoStudioRoutes: Routes = [ 6const videoStudioRoutes: Routes = [
6 { 7 {
@@ -15,7 +16,7 @@ const videoStudioRoutes: Routes = [
15 } 16 }
16 }, 17 },
17 resolve: { 18 resolve: {
18 video: VideoStudioEditResolver 19 video: VideoResolver
19 } 20 }
20 } 21 }
21 ] 22 ]
diff --git a/client/src/app/+video-studio/video-studio.module.ts b/client/src/app/+video-studio/video-studio.module.ts
index 1a8763539..7c1dc02ea 100644
--- a/client/src/app/+video-studio/video-studio.module.ts
+++ b/client/src/app/+video-studio/video-studio.module.ts
@@ -1,7 +1,7 @@
1import { NgModule } from '@angular/core' 1import { NgModule } from '@angular/core'
2import { SharedFormModule } from '@app/shared/shared-forms' 2import { SharedFormModule } from '@app/shared/shared-forms'
3import { SharedMainModule } from '@app/shared/shared-main' 3import { SharedMainModule } from '@app/shared/shared-main'
4import { VideoStudioEditComponent, VideoStudioEditResolver } from './edit' 4import { VideoStudioEditComponent } from './edit'
5import { VideoStudioService } from './shared' 5import { VideoStudioService } from './shared'
6import { VideoStudioRoutingModule } from './video-studio-routing.module' 6import { VideoStudioRoutingModule } from './video-studio-routing.module'
7 7
@@ -20,8 +20,7 @@ import { VideoStudioRoutingModule } from './video-studio-routing.module'
20 exports: [], 20 exports: [],
21 21
22 providers: [ 22 providers: [
23 VideoStudioService, 23 VideoStudioService
24 VideoStudioEditResolver
25 ] 24 ]
26}) 25})
27export class VideoStudioModule { } 26export class VideoStudioModule { }
diff --git a/client/src/app/+videos/+video-edit/video-add.component.scss b/client/src/app/+videos/+video-edit/video-add.component.scss
index 0f0cc406c..dda868789 100644
--- a/client/src/app/+videos/+video-edit/video-add.component.scss
+++ b/client/src/app/+videos/+video-edit/video-add.component.scss
@@ -1,5 +1,6 @@
1@use '_variables' as *; 1@use '_variables' as *;
2@use '_mixins' as *; 2@use '_mixins' as *;
3@use '_nav' as *;
3 4
4$border-width: 3px; 5$border-width: 3px;
5$border-type: solid; 6$border-type: solid;
@@ -51,39 +52,11 @@ $nav-link-height: 40px;
51} 52}
52 53
53::ng-deep .video-add-nav { 54::ng-deep .video-add-nav {
54 border-bottom: $border-width $border-type $border-color; 55 @include peertube-nav-tabs($border-width, $border-type, $border-color, $nav-link-height);
55 margin: 20px 0 0 !important;
56
57 &.hide-nav {
58 display: none !important;
59 }
60 56
61 a.nav-link { 57 a.nav-link {
62 @include disable-default-a-behaviour;
63
64 margin-bottom: -$border-width;
65 height: $nav-link-height !important;
66 padding: 0 30px !important;
67 font-size: 15px;
68
69 border: $border-width $border-type transparent;
70
71 span {
72 border-bottom: 2px solid transparent;
73 }
74
75 &.active { 58 &.active {
76 border-color: $border-color;
77 border-bottom-color: transparent;
78 background-color: pvar(--submenuBackgroundColor) !important; 59 background-color: pvar(--submenuBackgroundColor) !important;
79
80 span {
81 border-bottom-color: pvar(--mainColor);
82 }
83 }
84
85 &:hover:not(.active) {
86 border-color: transparent;
87 } 60 }
88 } 61 }
89} 62}
diff --git a/client/src/app/+videos/+video-watch/shared/action-buttons/action-buttons.component.ts b/client/src/app/+videos/+video-watch/shared/action-buttons/action-buttons.component.ts
index af26ea04d..51718827d 100644
--- a/client/src/app/+videos/+video-watch/shared/action-buttons/action-buttons.component.ts
+++ b/client/src/app/+videos/+video-watch/shared/action-buttons/action-buttons.component.ts
@@ -41,7 +41,8 @@ export class ActionButtonsComponent implements OnInit, OnChanges {
41 report: true, 41 report: true,
42 duplicate: true, 42 duplicate: true,
43 mute: true, 43 mute: true,
44 liveInfo: true 44 liveInfo: true,
45 stats: true
45 } 46 }
46 47
47 userRating: UserVideoRateType 48 userRating: UserVideoRateType
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index f13c885f2..61b440859 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -553,9 +553,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
553 videoCaptions: VideoCaption[] 553 videoCaptions: VideoCaption[]
554 urlOptions: CustomizationOptions & { playerMode: PlayerMode } 554 urlOptions: CustomizationOptions & { playerMode: PlayerMode }
555 loggedInOrAnonymousUser: User 555 loggedInOrAnonymousUser: User
556 user?: AuthUser 556 user?: AuthUser // Keep for plugins
557 }) { 557 }) {
558 const { video, liveVideo, videoCaptions, urlOptions, loggedInOrAnonymousUser, user } = params 558 const { video, liveVideo, videoCaptions, urlOptions, loggedInOrAnonymousUser } = params
559 559
560 const getStartTime = () => { 560 const getStartTime = () => {
561 const byUrl = urlOptions.startTime !== undefined 561 const byUrl = urlOptions.startTime !== undefined
@@ -615,6 +615,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
615 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE 615 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
616 ? this.videoService.getVideoViewUrl(video.uuid) 616 ? this.videoService.getVideoViewUrl(video.uuid)
617 : null, 617 : null,
618 authorizationHeader: this.authService.getRequestHeaderValue(),
619
618 embedUrl: video.embedUrl, 620 embedUrl: video.embedUrl,
619 embedTitle: video.name, 621 embedTitle: video.name,
620 622
@@ -623,13 +625,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
623 625
624 language: this.localeId, 626 language: this.localeId,
625 627
626 userWatching: user && user.videosHistoryEnabled === true
627 ? {
628 url: this.videoService.getUserWatchingVideoUrl(video.uuid),
629 authorizationHeader: this.authService.getRequestHeaderValue()
630 }
631 : undefined,
632
633 serverUrl: environment.apiUrl, 628 serverUrl: environment.apiUrl,
634 629
635 videoCaptions: playerCaptions, 630 videoCaptions: playerCaptions,
diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts
index db48b2eea..a9d9c723a 100644
--- a/client/src/app/app-routing.module.ts
+++ b/client/src/app/app-routing.module.ts
@@ -151,6 +151,12 @@ const routes: Routes = [
151 canActivateChild: [ MetaGuard ] 151 canActivateChild: [ MetaGuard ]
152 }, 152 },
153 153
154 {
155 path: 'stats',
156 loadChildren: () => import('./+stats/stats.module').then(m => m.StatsModule),
157 canActivateChild: [ MetaGuard ]
158 },
159
154 // Matches /@:actorName 160 // Matches /@:actorName
155 { 161 {
156 matcher: (url): UrlMatchResult => { 162 matcher: (url): UrlMatchResult => {
diff --git a/client/src/app/shared/shared-icons/global-icon.component.ts b/client/src/app/shared/shared-icons/global-icon.component.ts
index a4c62c234..ba23edde0 100644
--- a/client/src/app/shared/shared-icons/global-icon.component.ts
+++ b/client/src/app/shared/shared-icons/global-icon.component.ts
@@ -75,7 +75,8 @@ const icons = {
75 'chevrons-up': require('!!raw-loader?!../../../assets/images/feather/chevrons-up.svg').default, 75 'chevrons-up': require('!!raw-loader?!../../../assets/images/feather/chevrons-up.svg').default,
76 'message-circle': require('!!raw-loader?!../../../assets/images/feather/message-circle.svg').default, 76 'message-circle': require('!!raw-loader?!../../../assets/images/feather/message-circle.svg').default,
77 codesandbox: require('!!raw-loader?!../../../assets/images/feather/codesandbox.svg').default, 77 codesandbox: require('!!raw-loader?!../../../assets/images/feather/codesandbox.svg').default,
78 award: require('!!raw-loader?!../../../assets/images/feather/award.svg').default 78 award: require('!!raw-loader?!../../../assets/images/feather/award.svg').default,
79 stats: require('!!raw-loader?!../../../assets/images/feather/stats.svg').default
79} 80}
80 81
81export type GlobalIconName = keyof typeof icons 82export type GlobalIconName = keyof typeof icons
diff --git a/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts b/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts
index 8badb1573..7c18b7f67 100644
--- a/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts
+++ b/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts
@@ -22,6 +22,7 @@ export class NumberFormatterPipe implements PipeTransform {
22 { max: 1000000, type: 'K' }, 22 { max: 1000000, type: 'K' },
23 { max: 1000000000, type: 'M' } 23 { max: 1000000000, type: 'M' }
24 ] 24 ]
25
25 constructor (@Inject(LOCALE_ID) private localeId: string) {} 26 constructor (@Inject(LOCALE_ID) private localeId: string) {}
26 27
27 transform (value: number) { 28 transform (value: number) {
diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts
index d83af9a66..5629640bc 100644
--- a/client/src/app/shared/shared-main/shared-main.module.ts
+++ b/client/src/app/shared/shared-main/shared-main.module.ts
@@ -45,7 +45,7 @@ import {
45import { PluginPlaceholderComponent, PluginSelectorDirective } from './plugins' 45import { PluginPlaceholderComponent, PluginSelectorDirective } from './plugins'
46import { ActorRedirectGuard } from './router' 46import { ActorRedirectGuard } from './router'
47import { UserHistoryService, UserNotificationsComponent, UserNotificationService, UserQuotaComponent } from './users' 47import { UserHistoryService, UserNotificationsComponent, UserNotificationService, UserQuotaComponent } from './users'
48import { EmbedComponent, RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video' 48import { EmbedComponent, RedundancyService, VideoImportService, VideoOwnershipService, VideoResolver, VideoService } from './video'
49import { VideoCaptionService } from './video-caption' 49import { VideoCaptionService } from './video-caption'
50import { VideoChannelService } from './video-channel' 50import { VideoChannelService } from './video-channel'
51 51
@@ -190,6 +190,7 @@ import { VideoChannelService } from './video-channel'
190 VideoImportService, 190 VideoImportService,
191 VideoOwnershipService, 191 VideoOwnershipService,
192 VideoService, 192 VideoService,
193 VideoResolver,
193 194
194 VideoCaptionService, 195 VideoCaptionService,
195 196
diff --git a/client/src/app/shared/shared-main/video/index.ts b/client/src/app/shared/shared-main/video/index.ts
index e72c0c3d6..361601456 100644
--- a/client/src/app/shared/shared-main/video/index.ts
+++ b/client/src/app/shared/shared-main/video/index.ts
@@ -5,4 +5,5 @@ export * from './video-edit.model'
5export * from './video-import.service' 5export * from './video-import.service'
6export * from './video-ownership.service' 6export * from './video-ownership.service'
7export * from './video.model' 7export * from './video.model'
8export * from './video.resolver'
8export * from './video.service' 9export * from './video.service'
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts
index 2d4db9a28..022bb95ad 100644
--- a/client/src/app/shared/shared-main/video/video.model.ts
+++ b/client/src/app/shared/shared-main/video/video.model.ts
@@ -58,8 +58,7 @@ export class Video implements VideoServerModel {
58 url: string 58 url: string
59 59
60 views: number 60 views: number
61 // If live 61 viewers: number
62 viewers?: number
63 62
64 likes: number 63 likes: number
65 dislikes: number 64 dislikes: number
@@ -234,9 +233,13 @@ export class Video implements VideoServerModel {
234 this.isUpdatableBy(user) 233 this.isUpdatableBy(user)
235 } 234 }
236 235
236 canSeeStats (user: AuthUser) {
237 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.SEE_ALL_VIDEOS))
238 }
239
237 canRemoveFiles (user: AuthUser) { 240 canRemoveFiles (user: AuthUser) {
238 return this.isLocal && 241 return this.isLocal &&
239 user.hasRight(UserRight.MANAGE_VIDEO_FILES) && 242 user && user.hasRight(UserRight.MANAGE_VIDEO_FILES) &&
240 this.state.id !== VideoState.TO_TRANSCODE && 243 this.state.id !== VideoState.TO_TRANSCODE &&
241 this.hasHLS() && 244 this.hasHLS() &&
242 this.hasWebTorrent() 245 this.hasWebTorrent()
@@ -244,7 +247,7 @@ export class Video implements VideoServerModel {
244 247
245 canRunTranscoding (user: AuthUser) { 248 canRunTranscoding (user: AuthUser) {
246 return this.isLocal && 249 return this.isLocal &&
247 user.hasRight(UserRight.RUN_VIDEO_TRANSCODING) && 250 user && user.hasRight(UserRight.RUN_VIDEO_TRANSCODING) &&
248 this.state.id !== VideoState.TO_TRANSCODE 251 this.state.id !== VideoState.TO_TRANSCODE
249 } 252 }
250 253
diff --git a/client/src/app/+video-studio/edit/video-studio-edit.resolver.ts b/client/src/app/shared/shared-main/video/video.resolver.ts
index c658be50b..65b7230ce 100644
--- a/client/src/app/+video-studio/edit/video-studio-edit.resolver.ts
+++ b/client/src/app/shared/shared-main/video/video.resolver.ts
@@ -1,10 +1,9 @@
1
2import { Injectable } from '@angular/core' 1import { Injectable } from '@angular/core'
3import { ActivatedRouteSnapshot, Resolve } from '@angular/router' 2import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
4import { VideoService } from '@app/shared/shared-main' 3import { VideoService } from './video.service'
5 4
6@Injectable() 5@Injectable()
7export class VideoStudioEditResolver implements Resolve<any> { 6export class VideoResolver implements Resolve<any> {
8 constructor ( 7 constructor (
9 private videoService: VideoService 8 private videoService: VideoService
10 ) { 9 ) {
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts
index 94af9cd38..bc15c326f 100644
--- a/client/src/app/shared/shared-main/video/video.service.ts
+++ b/client/src/app/shared/shared-main/video/video.service.ts
@@ -65,10 +65,6 @@ export class VideoService {
65 return `${VideoService.BASE_VIDEO_URL}/${uuid}/views` 65 return `${VideoService.BASE_VIDEO_URL}/${uuid}/views`
66 } 66 }
67 67
68 getUserWatchingVideoUrl (uuid: string) {
69 return `${VideoService.BASE_VIDEO_URL}/${uuid}/watching`
70 }
71
72 getVideo (options: { videoId: string }): Observable<VideoDetails> { 68 getVideo (options: { videoId: string }): Observable<VideoDetails> {
73 return this.serverService.getServerLocale() 69 return this.serverService.getServerLocale()
74 .pipe( 70 .pipe(
diff --git a/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts b/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts
index 5eef96145..ed6a4afc0 100644
--- a/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts
+++ b/client/src/app/shared/shared-video-miniature/video-actions-dropdown.component.ts
@@ -30,6 +30,7 @@ export type VideoActionsDisplayType = {
30 removeFiles?: boolean 30 removeFiles?: boolean
31 transcoding?: boolean 31 transcoding?: boolean
32 studio?: boolean 32 studio?: boolean
33 stats?: boolean
33} 34}
34 35
35@Component({ 36@Component({
@@ -61,9 +62,11 @@ export class VideoActionsDropdownComponent implements OnChanges {
61 liveInfo: false, 62 liveInfo: false,
62 removeFiles: false, 63 removeFiles: false,
63 transcoding: false, 64 transcoding: false,
64 studio: true 65 studio: true,
66 stats: true
65 } 67 }
66 @Input() placement = 'left' 68 @Input() placement = 'left'
69 @Input() moreActions: DropdownAction<{ video: Video }>[][] = []
67 70
68 @Input() label: string 71 @Input() label: string
69 72
@@ -156,6 +159,10 @@ export class VideoActionsDropdownComponent implements OnChanges {
156 return this.video.isEditableBy(this.user, this.serverService.getHTMLConfig().videoStudio.enabled) 159 return this.video.isEditableBy(this.user, this.serverService.getHTMLConfig().videoStudio.enabled)
157 } 160 }
158 161
162 isVideoStatsAvailable () {
163 return this.video.canSeeStats(this.user)
164 }
165
159 isVideoRemovable () { 166 isVideoRemovable () {
160 return this.video.isRemovableBy(this.user) 167 return this.video.isRemovableBy(this.user)
161 } 168 }
@@ -343,6 +350,12 @@ export class VideoActionsDropdownComponent implements OnChanges {
343 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.studio && this.isVideoEditable() 350 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.studio && this.isVideoEditable()
344 }, 351 },
345 { 352 {
353 label: $localize`Stats`,
354 linkBuilder: ({ video }) => [ '/stats/videos', video.uuid ],
355 iconName: 'stats',
356 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.stats && this.isVideoStatsAvailable()
357 },
358 {
346 label: $localize`Block`, 359 label: $localize`Block`,
347 handler: () => this.showBlockModal(), 360 handler: () => this.showBlockModal(),
348 iconName: 'no', 361 iconName: 'no',
@@ -408,5 +421,7 @@ export class VideoActionsDropdownComponent implements OnChanges {
408 } 421 }
409 ] 422 ]
410 ] 423 ]
424
425 this.videoActions = this.videoActions.concat(this.moreActions)
411 } 426 }
412} 427}
diff --git a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
index 7de9fc8e2..42c472579 100644
--- a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
+++ b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
@@ -49,7 +49,20 @@ export class VideoMiniatureComponent implements OnInit {
49 state: false, 49 state: false,
50 blacklistInfo: false 50 blacklistInfo: false
51 } 51 }
52
52 @Input() displayVideoActions = true 53 @Input() displayVideoActions = true
54 @Input() videoActionsDisplayOptions: VideoActionsDisplayType = {
55 playlist: true,
56 download: false,
57 update: true,
58 blacklist: true,
59 delete: true,
60 report: true,
61 duplicate: true,
62 mute: true,
63 studio: false,
64 stats: false
65 }
53 66
54 @Input() actorImageSize: ActorAvatarSize = '40' 67 @Input() actorImageSize: ActorAvatarSize = '40'
55 68
@@ -62,16 +75,6 @@ export class VideoMiniatureComponent implements OnInit {
62 @Output() videoRemoved = new EventEmitter() 75 @Output() videoRemoved = new EventEmitter()
63 @Output() videoAccountMuted = new EventEmitter() 76 @Output() videoAccountMuted = new EventEmitter()
64 77
65 videoActionsDisplayOptions: VideoActionsDisplayType = {
66 playlist: true,
67 download: false,
68 update: true,
69 blacklist: true,
70 delete: true,
71 report: true,
72 duplicate: true,
73 mute: true
74 }
75 showActions = false 78 showActions = false
76 serverConfig: HTMLServerConfig 79 serverConfig: HTMLServerConfig
77 80