]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-playlist / video-playlist-element-miniature.component.ts
CommitLineData
ba430d75 1import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
67ed6552 2import { AuthService, Notifier, ServerService } from '@app/core'
343d1395 3import { Video, VideoService } from '@app/shared/shared-main'
e2f01c47 4import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'
15a7eafb 5import { secondsToTime } from '@shared/core-utils'
af6b45e5 6import { HTMLServerConfig, VideoPlaylistElementType, VideoPlaylistElementUpdate, VideoPrivacy } from '@shared/models'
67ed6552
C
7import { VideoPlaylistElement } from './video-playlist-element.model'
8import { VideoPlaylist } from './video-playlist.model'
9import { VideoPlaylistService } from './video-playlist.service'
e2f01c47
C
10
11@Component({
12 selector: 'my-video-playlist-element-miniature',
13 styleUrls: [ './video-playlist-element-miniature.component.scss' ],
bce47964
C
14 templateUrl: './video-playlist-element-miniature.component.html',
15 changeDetection: ChangeDetectionStrategy.OnPush
e2f01c47 16})
ba430d75 17export class VideoPlaylistElementMiniatureComponent implements OnInit {
2f5d2ec5 18 @ViewChild('moreDropdown') moreDropdown: NgbDropdown
e2f01c47
C
19
20 @Input() playlist: VideoPlaylist
bfbd9128 21 @Input() playlistElement: VideoPlaylistElement
e2f01c47
C
22 @Input() owned = false
23 @Input() playing = false
24 @Input() rowLink = false
25 @Input() accountLink = true
bfbd9128 26 @Input() position: number // Keep this property because we're in the OnPush change detection strategy
bedf0e60 27 @Input() touchScreenEditButton = false
e2f01c47 28
bfbd9128 29 @Output() elementRemoved = new EventEmitter<VideoPlaylistElement>()
e2f01c47
C
30
31 displayTimestampOptions = false
32
33 timestampOptions: {
34 startTimestampEnabled: boolean
35 startTimestamp: number
36 stopTimestampEnabled: boolean
37 stopTimestamp: number
38 } = {} as any
39
2989628b 40 private serverConfig: HTMLServerConfig
ba430d75 41
e2f01c47
C
42 constructor (
43 private authService: AuthService,
44 private serverService: ServerService,
45 private notifier: Notifier,
bce47964 46 private videoPlaylistService: VideoPlaylistService,
343d1395 47 private videoService: VideoService,
bce47964 48 private cdr: ChangeDetectorRef
e2f01c47
C
49 ) {}
50
ba430d75 51 ngOnInit (): void {
2989628b 52 this.serverConfig = this.serverService.getHTMLConfig()
ba430d75
C
53 }
54
343d1395
C
55 getVideoOwnerDisplayType (element: VideoPlaylistElement) {
56 return this.videoService.buildDefaultOwnerDisplayType(element.video)
57 }
58
af6b45e5 59 isVideoPrivate () {
60 return this.playlistElement.video.privacy.id === VideoPrivacy.PRIVATE
61 }
62
bfbd9128
C
63 isUnavailable (e: VideoPlaylistElement) {
64 return e.type === VideoPlaylistElementType.UNAVAILABLE
65 }
66
67 isPrivate (e: VideoPlaylistElement) {
68 return e.type === VideoPlaylistElementType.PRIVATE
69 }
70
71 isDeleted (e: VideoPlaylistElement) {
72 return e.type === VideoPlaylistElementType.DELETED
73 }
74
e2f01c47
C
75 buildRouterLink () {
76 if (!this.playlist) return null
77
d4a8e7a6 78 return VideoPlaylist.buildWatchUrl(this.playlist)
e2f01c47
C
79 }
80
81 buildRouterQuery () {
7dcd7d81 82 if (!this.playlistElement?.video) return {}
e2f01c47
C
83
84 return {
d142c7b9 85 playlistPosition: this.playlistElement.position,
bfbd9128 86 start: this.playlistElement.startTimestamp,
96f6278f
RK
87 stop: this.playlistElement.stopTimestamp,
88 resume: true
e2f01c47
C
89 }
90 }
91
92 isVideoBlur (video: Video) {
ba430d75 93 return video.isVideoNSFWForUser(this.authService.getUser(), this.serverConfig)
e2f01c47
C
94 }
95
bfbd9128 96 removeFromPlaylist (playlistElement: VideoPlaylistElement) {
51b34a11
C
97 const videoId = this.playlistElement.video ? this.playlistElement.video.id : undefined
98
99 this.videoPlaylistService.removeVideoFromPlaylist(this.playlist.id, playlistElement.id, videoId)
1378c0d3
C
100 .subscribe({
101 next: () => {
66357162 102 this.notifier.success($localize`Video removed from ${this.playlist.displayName}`)
bfbd9128 103 this.elementRemoved.emit(playlistElement)
e2f01c47
C
104 },
105
1378c0d3
C
106 error: err => this.notifier.error(err.message)
107 })
e2f01c47
C
108
109 this.moreDropdown.close()
110 }
111
bfbd9128 112 updateTimestamps (playlistElement: VideoPlaylistElement) {
e2f01c47
C
113 const body: VideoPlaylistElementUpdate = {}
114
115 body.startTimestamp = this.timestampOptions.startTimestampEnabled ? this.timestampOptions.startTimestamp : null
116 body.stopTimestamp = this.timestampOptions.stopTimestampEnabled ? this.timestampOptions.stopTimestamp : null
117
51b34a11 118 this.videoPlaylistService.updateVideoOfPlaylist(this.playlist.id, playlistElement.id, body, this.playlistElement.video.id)
1378c0d3
C
119 .subscribe({
120 next: () => {
66357162 121 this.notifier.success($localize`Timestamps updated`)
e2f01c47 122
bfbd9128
C
123 playlistElement.startTimestamp = body.startTimestamp
124 playlistElement.stopTimestamp = body.stopTimestamp
bce47964
C
125
126 this.cdr.detectChanges()
e2f01c47
C
127 },
128
1378c0d3
C
129 error: err => this.notifier.error(err.message)
130 })
e2f01c47
C
131
132 this.moreDropdown.close()
133 }
134
bfbd9128
C
135 formatTimestamp (playlistElement: VideoPlaylistElement) {
136 const start = playlistElement.startTimestamp
137 const stop = playlistElement.stopTimestamp
e2f01c47
C
138
139 const startFormatted = secondsToTime(start, true, ':')
140 const stopFormatted = secondsToTime(stop, true, ':')
141
142 if (start === null && stop === null) return ''
143
66357162
C
144 if (start !== null && stop === null) return $localize`Starts at ` + startFormatted
145 if (start === null && stop !== null) return $localize`Stops at ` + stopFormatted
e2f01c47 146
66357162 147 return $localize`Starts at ` + startFormatted + $localize` and stops at ` + stopFormatted
e2f01c47
C
148 }
149
150 onDropdownOpenChange () {
151 this.displayTimestampOptions = false
152 }
153
bfbd9128 154 toggleDisplayTimestampsOptions (event: Event, playlistElement: VideoPlaylistElement) {
e2f01c47
C
155 event.preventDefault()
156
157 this.displayTimestampOptions = !this.displayTimestampOptions
158
159 if (this.displayTimestampOptions === true) {
160 this.timestampOptions = {
161 startTimestampEnabled: false,
162 stopTimestampEnabled: false,
163 startTimestamp: 0,
bfbd9128 164 stopTimestamp: playlistElement.video.duration
e2f01c47
C
165 }
166
bfbd9128 167 if (playlistElement.startTimestamp) {
e2f01c47 168 this.timestampOptions.startTimestampEnabled = true
bfbd9128 169 this.timestampOptions.startTimestamp = playlistElement.startTimestamp
e2f01c47
C
170 }
171
bfbd9128 172 if (playlistElement.stopTimestamp) {
e2f01c47 173 this.timestampOptions.stopTimestampEnabled = true
bfbd9128 174 this.timestampOptions.stopTimestamp = playlistElement.stopTimestamp
e2f01c47
C
175 }
176 }
bce47964 177
60dd77c6 178 this.cdr.markForCheck()
e2f01c47
C
179 }
180}