]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video-thumbnail.component.ts
`fitWidth` for `video-miniature`, fluid grid (#2830)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-thumbnail.component.ts
1 import { Component, EventEmitter, Input, Output } from '@angular/core'
2 import { Video } from './video.model'
3 import { ScreenService } from '@app/shared/misc/screen.service'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5
6 @Component({
7 selector: 'my-video-thumbnail',
8 styleUrls: [ './video-thumbnail.component.scss' ],
9 templateUrl: './video-thumbnail.component.html'
10 })
11 export class VideoThumbnailComponent {
12 @Input() video: Video
13 @Input() nsfw = false
14 @Input() routerLink: any[]
15 @Input() queryParams: { [ p: string ]: any }
16
17 @Input() displayWatchLaterPlaylist: boolean
18 @Input() inWatchLaterPlaylist: boolean
19
20 @Output() watchLaterClick = new EventEmitter<boolean>()
21
22 addToWatchLaterText: string
23 addedToWatchLaterText: string
24
25 constructor (
26 private screenService: ScreenService,
27 private i18n: I18n
28 ) {
29 this.addToWatchLaterText = this.i18n('Add to watch later')
30 this.addedToWatchLaterText = this.i18n('Remove from watch later')
31 }
32
33 getImageUrl () {
34 if (!this.video) return ''
35
36 if (this.screenService.isInMobileView()) {
37 return this.video.previewUrl
38 }
39
40 return this.video.thumbnailUrl
41 }
42
43 getProgressPercent () {
44 if (!this.video.userHistory) return 0
45
46 const currentTime = this.video.userHistory.currentTime
47
48 return (currentTime / this.video.duration) * 100
49 }
50
51 getVideoRouterLink () {
52 if (this.routerLink) return this.routerLink
53
54 return [ '/videos/watch', this.video.uuid ]
55 }
56
57 onWatchLaterClick (event: Event) {
58 this.watchLaterClick.emit(this.inWatchLaterPlaylist)
59
60 event.stopPropagation()
61 return false
62 }
63 }