1
0
Fork 0
peertube/client/src/app/shared/shared-video-playlist/video-playlist-element-mini...

189 lines
6.2 KiB
TypeScript
Raw Normal View History

2019-12-18 14:31:54 +00:00
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2020-06-23 12:10:17 +00:00
import { AuthService, Notifier, ServerService } from '@app/core'
import { Video, VideoService } from '@app/shared/shared-main'
2019-03-13 13:18:58 +00:00
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'
import { secondsToTime } from '@peertube/peertube-core-utils'
import { HTMLServerConfig, VideoPlaylistElementType, VideoPlaylistElementUpdate, VideoPrivacy } from '@peertube/peertube-models'
2020-06-23 12:10:17 +00:00
import { VideoPlaylistElement } from './video-playlist-element.model'
import { VideoPlaylist } from './video-playlist.model'
import { VideoPlaylistService } from './video-playlist.service'
2019-03-13 13:18:58 +00:00
@Component({
selector: 'my-video-playlist-element-miniature',
styleUrls: [ './video-playlist-element-miniature.component.scss' ],
2019-03-14 13:05:36 +00:00
templateUrl: './video-playlist-element-miniature.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
2019-03-13 13:18:58 +00:00
})
2019-12-18 14:31:54 +00:00
export class VideoPlaylistElementMiniatureComponent implements OnInit {
2020-02-07 09:00:34 +00:00
@ViewChild('moreDropdown') moreDropdown: NgbDropdown
2019-03-13 13:18:58 +00:00
@Input() playlist: VideoPlaylist
2019-07-31 13:57:32 +00:00
@Input() playlistElement: VideoPlaylistElement
2019-03-13 13:18:58 +00:00
@Input() owned = false
@Input() playing = false
@Input() rowLink = false
@Input() accountLink = true
2019-07-31 13:57:32 +00:00
@Input() position: number // Keep this property because we're in the OnPush change detection strategy
@Input() touchScreenEditButton = false
2019-03-13 13:18:58 +00:00
2019-07-31 13:57:32 +00:00
@Output() elementRemoved = new EventEmitter<VideoPlaylistElement>()
2019-03-13 13:18:58 +00:00
displayTimestampOptions = false
timestampOptions: {
startTimestampEnabled: boolean
startTimestamp: number
stopTimestampEnabled: boolean
stopTimestamp: number
} = {} as any
2021-06-04 11:31:41 +00:00
private serverConfig: HTMLServerConfig
2019-12-18 14:31:54 +00:00
2019-03-13 13:18:58 +00:00
constructor (
private authService: AuthService,
private serverService: ServerService,
private notifier: Notifier,
2019-03-14 13:05:36 +00:00
private videoPlaylistService: VideoPlaylistService,
private videoService: VideoService,
2019-03-14 13:05:36 +00:00
private cdr: ChangeDetectorRef
2019-03-13 13:18:58 +00:00
) {}
2019-12-18 14:31:54 +00:00
ngOnInit (): void {
2021-06-04 11:31:41 +00:00
this.serverConfig = this.serverService.getHTMLConfig()
2019-12-18 14:31:54 +00:00
}
getVideoAriaLabel () {
return $localize`Watch video ${this.playlistElement.video.name}`
}
getVideoOwnerDisplayType (element: VideoPlaylistElement) {
return this.videoService.buildDefaultOwnerDisplayType(element.video)
}
isVideoPrivate () {
return this.playlistElement.video.privacy.id === VideoPrivacy.PRIVATE
}
isVideoPasswordProtected () {
return this.playlistElement.video.privacy.id === VideoPrivacy.PASSWORD_PROTECTED
}
2019-07-31 13:57:32 +00:00
isUnavailable (e: VideoPlaylistElement) {
return e.type === VideoPlaylistElementType.UNAVAILABLE
}
isPrivate (e: VideoPlaylistElement) {
return e.type === VideoPlaylistElementType.PRIVATE
}
isDeleted (e: VideoPlaylistElement) {
return e.type === VideoPlaylistElementType.DELETED
}
2019-03-13 13:18:58 +00:00
buildRouterLink () {
if (!this.playlist) return null
return VideoPlaylist.buildWatchUrl(this.playlist)
2019-03-13 13:18:58 +00:00
}
buildRouterQuery () {
2022-11-15 14:16:41 +00:00
if (!this.playlistElement?.video) return {}
2019-03-13 13:18:58 +00:00
return {
playlistPosition: this.playlistElement.position,
2019-07-31 13:57:32 +00:00
start: this.playlistElement.startTimestamp,
stop: this.playlistElement.stopTimestamp,
resume: true
2019-03-13 13:18:58 +00:00
}
}
isVideoBlur (video: Video) {
2019-12-18 14:31:54 +00:00
return video.isVideoNSFWForUser(this.authService.getUser(), this.serverConfig)
2019-03-13 13:18:58 +00:00
}
2019-07-31 13:57:32 +00:00
removeFromPlaylist (playlistElement: VideoPlaylistElement) {
2020-01-06 12:06:13 +00:00
const videoId = this.playlistElement.video ? this.playlistElement.video.id : undefined
this.videoPlaylistService.removeVideoFromPlaylist(this.playlist.id, playlistElement.id, videoId)
2021-08-17 09:27:47 +00:00
.subscribe({
next: () => {
this.notifier.success($localize`Video removed from ${this.playlist.displayName}`)
2019-07-31 13:57:32 +00:00
this.elementRemoved.emit(playlistElement)
2019-03-13 13:18:58 +00:00
},
2021-08-17 09:27:47 +00:00
error: err => this.notifier.error(err.message)
})
2019-03-13 13:18:58 +00:00
this.moreDropdown.close()
}
2019-07-31 13:57:32 +00:00
updateTimestamps (playlistElement: VideoPlaylistElement) {
2019-03-13 13:18:58 +00:00
const body: VideoPlaylistElementUpdate = {}
body.startTimestamp = this.timestampOptions.startTimestampEnabled ? this.timestampOptions.startTimestamp : null
body.stopTimestamp = this.timestampOptions.stopTimestampEnabled ? this.timestampOptions.stopTimestamp : null
2020-01-06 12:06:13 +00:00
this.videoPlaylistService.updateVideoOfPlaylist(this.playlist.id, playlistElement.id, body, this.playlistElement.video.id)
2021-08-17 09:27:47 +00:00
.subscribe({
next: () => {
this.notifier.success($localize`Timestamps updated`)
2019-03-13 13:18:58 +00:00
2019-07-31 13:57:32 +00:00
playlistElement.startTimestamp = body.startTimestamp
playlistElement.stopTimestamp = body.stopTimestamp
2019-03-14 13:05:36 +00:00
this.cdr.detectChanges()
2019-03-13 13:18:58 +00:00
},
2021-08-17 09:27:47 +00:00
error: err => this.notifier.error(err.message)
})
2019-03-13 13:18:58 +00:00
this.moreDropdown.close()
}
2019-07-31 13:57:32 +00:00
formatTimestamp (playlistElement: VideoPlaylistElement) {
const start = playlistElement.startTimestamp
const stop = playlistElement.stopTimestamp
2019-03-13 13:18:58 +00:00
2024-01-03 10:10:41 +00:00
const startFormatted = secondsToTime({ seconds: start, fullFormat: true, symbol: ':' })
const stopFormatted = secondsToTime({ seconds: stop, fullFormat: true, symbol: ':' })
2019-03-13 13:18:58 +00:00
if (start === null && stop === null) return ''
if (start !== null && stop === null) return $localize`Starts at ` + startFormatted
if (start === null && stop !== null) return $localize`Stops at ` + stopFormatted
2019-03-13 13:18:58 +00:00
return $localize`Starts at ` + startFormatted + $localize` and stops at ` + stopFormatted
2019-03-13 13:18:58 +00:00
}
onDropdownOpenChange () {
this.displayTimestampOptions = false
}
2019-07-31 13:57:32 +00:00
toggleDisplayTimestampsOptions (event: Event, playlistElement: VideoPlaylistElement) {
2019-03-13 13:18:58 +00:00
event.preventDefault()
this.displayTimestampOptions = !this.displayTimestampOptions
if (this.displayTimestampOptions === true) {
this.timestampOptions = {
startTimestampEnabled: false,
stopTimestampEnabled: false,
startTimestamp: 0,
2019-07-31 13:57:32 +00:00
stopTimestamp: playlistElement.video.duration
2019-03-13 13:18:58 +00:00
}
2019-07-31 13:57:32 +00:00
if (playlistElement.startTimestamp) {
2019-03-13 13:18:58 +00:00
this.timestampOptions.startTimestampEnabled = true
2019-07-31 13:57:32 +00:00
this.timestampOptions.startTimestamp = playlistElement.startTimestamp
2019-03-13 13:18:58 +00:00
}
2019-07-31 13:57:32 +00:00
if (playlistElement.stopTimestamp) {
2019-03-13 13:18:58 +00:00
this.timestampOptions.stopTimestampEnabled = true
2019-07-31 13:57:32 +00:00
this.timestampOptions.stopTimestamp = playlistElement.stopTimestamp
2019-03-13 13:18:58 +00:00
}
}
2019-03-14 13:05:36 +00:00
this.cdr.markForCheck()
2019-03-13 13:18:58 +00:00
}
}