Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add quick filters to stats

Chocobozzzb1ca14a8bad7
diff --git a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
index 96a3f6034f..26f988f1bb 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/common/video-edit.model.ts
@@ -127,6 +127,7 @@ type UpdateFromAPIOptions = {
| 'downloadEnabled'
| 'pluginData'
| 'scheduledUpdate'
+ | 'publishedAt'
| 'originallyPublishedAt'
| 'duration'
| 'likes'
@@ -192,6 +193,7 @@ export class VideoEdit {
likes: number
blacklisted: boolean
blacklistedReason: string
+ publishedAt: Date
ownerAccountId: number
ownerAccountDisplayName: string
@@ -208,6 +210,7 @@ export class VideoEdit {
state: VideoStateType
privacy: VideoEditPrivacyType
isLive: boolean
+ publishedAt: Date
aspectRatio: number
duration: number
views: number
@@ -441,6 +444,7 @@ export class VideoEdit {
// ---------------------------------------------------------------------------
this.metadata.id = video.id
+ this.metadata.publishedAt = new Date(video.publishedAt.toString())
this.metadata.uuid = video.uuid
this.metadata.shortUUID = video.shortUUID
@@ -1154,6 +1158,7 @@ export class VideoEdit {
state: this.metadata.state,
privacy: this.common.privacy,
isLive: this.metadata.isLive,
+ publishedAt: this.metadata.publishedAt,
aspectRatio: this.metadata.aspectRatio,
views: this.metadata.views,
downloads: this.metadata.downloads,
diff --git a/client/src/app/+videos-publish-manage/shared-manage/stats/video-stats.component.ts b/client/src/app/+videos-publish-manage/shared-manage/stats/video-stats.component.ts
index 2355e89bcd..f53853f3c8 100644
--- a/client/src/app/+videos-publish-manage/shared-manage/stats/video-stats.component.ts
+++ b/client/src/app/+videos-publish-manage/shared-manage/stats/video-stats.component.ts
@@ -233,7 +233,8 @@ export class VideoStatsComponent implements OnInit {
resetZoom () {
this.peertubeRouter.silentNavigate([], {})
- this.removeAndResetCustomDateFilter()
+ this.removeCustomDateFilter()
+ this.currentDateFilter = 'all'
}
hasZoom () {
@@ -249,6 +250,8 @@ export class VideoStatsComponent implements OnInit {
}
onDateFilterChange () {
+ this.removeCustomDateFilter()
+
if (this.currentDateFilter === 'all') {
return this.resetZoom()
}
@@ -303,6 +306,8 @@ export class VideoStatsComponent implements OnInit {
}
private loadVODDateFilters () {
+ this.addQuickDateFilters()
+
this.liveService.findLiveSessionFromVOD(this.videoEdit.getVideoAttributes().id)
.subscribe({
next: session => {
@@ -317,6 +322,26 @@ export class VideoStatsComponent implements OnInit {
})
}
+ private addQuickDateFilters () {
+ const now = new Date()
+ const publishedAt = this.videoEdit.getVideoAttributes().publishedAt
+
+ const addFilter = (label: string, hoursAgo: number) => {
+ const start = new Date(now.getTime() - hoursAgo * 60 * 60 * 1000)
+
+ if (publishedAt && start < publishedAt) return
+
+ this.dateFilters = this.dateFilters.concat([ {
+ id: start.toISOString() + '|' + now.toISOString(),
+ label
+ } ])
+ }
+
+ addFilter($localize`Last 24 hours`, 24)
+ addFilter($localize`Last 7 days`, 24 * 7)
+ addFilter($localize`Last 30 days`, 24 * 30)
+ }
+
private buildLiveFilter (session: LiveVideoSession) {
return {
id: session.startDate + '|' + session.endDate,
@@ -339,10 +364,8 @@ export class VideoStatsComponent implements OnInit {
this.currentDateFilter = 'custom'
}
- private removeAndResetCustomDateFilter () {
+ private removeCustomDateFilter () {
this.dateFilters = this.dateFilters.filter(d => d.id !== 'custom')
-
- this.currentDateFilter = 'all'
}
private buildOverallStatCard (overallStats: VideoStatsOverall) {