2020-01-03 15:01:17 +01:00
|
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core'
|
2017-12-01 18:56:26 +01:00
|
|
|
import { Video } from './video.model'
|
2018-06-15 16:52:15 +02:00
|
|
|
import { ScreenService } from '@app/shared/misc/screen.service'
|
2020-01-03 15:01:17 +01:00
|
|
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
2017-12-01 18:56:26 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-video-thumbnail',
|
|
|
|
styleUrls: [ './video-thumbnail.component.scss' ],
|
|
|
|
templateUrl: './video-thumbnail.component.html'
|
|
|
|
})
|
|
|
|
export class VideoThumbnailComponent {
|
|
|
|
@Input() video: Video
|
|
|
|
@Input() nsfw = false
|
2019-03-13 14:18:58 +01:00
|
|
|
@Input() routerLink: any[]
|
2020-02-10 14:25:38 +01:00
|
|
|
@Input() queryParams: { [ p: string ]: any }
|
2018-02-09 09:30:37 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
@Input() displayWatchLaterPlaylist: boolean
|
|
|
|
@Input() inWatchLaterPlaylist: boolean
|
2020-01-02 13:07:18 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
@Output() watchLaterClick = new EventEmitter<boolean>()
|
|
|
|
|
|
|
|
addToWatchLaterText: string
|
|
|
|
addedToWatchLaterText: string
|
2020-01-02 13:07:18 +01:00
|
|
|
|
|
|
|
constructor (
|
|
|
|
private screenService: ScreenService,
|
2020-01-03 15:01:17 +01:00
|
|
|
private i18n: I18n
|
|
|
|
) {
|
|
|
|
this.addToWatchLaterText = this.i18n('Add to watch later')
|
|
|
|
this.addedToWatchLaterText = this.i18n('Remove from watch later')
|
2019-03-13 14:18:58 +01:00
|
|
|
}
|
2018-06-15 16:52:15 +02:00
|
|
|
|
2018-02-09 09:30:37 +01:00
|
|
|
getImageUrl () {
|
|
|
|
if (!this.video) return ''
|
|
|
|
|
2018-06-15 16:52:15 +02:00
|
|
|
if (this.screenService.isInMobileView()) {
|
2018-02-09 09:30:37 +01:00
|
|
|
return this.video.previewUrl
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.video.thumbnailUrl
|
|
|
|
}
|
2018-10-05 11:15:06 +02:00
|
|
|
|
|
|
|
getProgressPercent () {
|
|
|
|
if (!this.video.userHistory) return 0
|
|
|
|
|
|
|
|
const currentTime = this.video.userHistory.currentTime
|
|
|
|
|
|
|
|
return (currentTime / this.video.duration) * 100
|
|
|
|
}
|
2019-03-13 14:18:58 +01:00
|
|
|
|
|
|
|
getVideoRouterLink () {
|
|
|
|
if (this.routerLink) return this.routerLink
|
|
|
|
|
|
|
|
return [ '/videos/watch', this.video.uuid ]
|
|
|
|
}
|
2020-01-02 13:07:18 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
onWatchLaterClick (event: Event) {
|
|
|
|
this.watchLaterClick.emit(this.inWatchLaterPlaylist)
|
2020-01-02 13:07:18 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
event.stopPropagation()
|
|
|
|
return false
|
2020-01-02 13:07:18 +01:00
|
|
|
}
|
2017-12-01 18:56:26 +01:00
|
|
|
}
|