]>
Commit | Line | Data |
---|---|---|
b7819090 | 1 | import { Component, EventEmitter, Input, Output } from '@angular/core' |
202f6b6c | 2 | import { Video } from './video.model' |
bbe0f064 | 3 | import { ScreenService } from '@app/shared/misc/screen.service' |
b7819090 | 4 | import { I18n } from '@ngx-translate/i18n-polyfill' |
202f6b6c C |
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 | |
e2f01c47 | 14 | @Input() routerLink: any[] |
be27ef3b | 15 | @Input() queryParams: { [ p: string ]: any } |
3290f37c | 16 | |
b7819090 C |
17 | @Input() displayWatchLaterPlaylist: boolean |
18 | @Input() inWatchLaterPlaylist: boolean | |
29128b2f | 19 | |
b7819090 C |
20 | @Output() watchLaterClick = new EventEmitter<boolean>() |
21 | ||
22 | addToWatchLaterText: string | |
23 | addedToWatchLaterText: string | |
29128b2f RK |
24 | |
25 | constructor ( | |
26 | private screenService: ScreenService, | |
b7819090 C |
27 | private i18n: I18n |
28 | ) { | |
29 | this.addToWatchLaterText = this.i18n('Add to watch later') | |
30 | this.addedToWatchLaterText = this.i18n('Remove from watch later') | |
e2f01c47 | 31 | } |
bbe0f064 | 32 | |
3290f37c C |
33 | getImageUrl () { |
34 | if (!this.video) return '' | |
35 | ||
bbe0f064 | 36 | if (this.screenService.isInMobileView()) { |
3290f37c C |
37 | return this.video.previewUrl |
38 | } | |
39 | ||
40 | return this.video.thumbnailUrl | |
41 | } | |
6e46de09 C |
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 | } | |
e2f01c47 C |
50 | |
51 | getVideoRouterLink () { | |
52 | if (this.routerLink) return this.routerLink | |
53 | ||
54 | return [ '/videos/watch', this.video.uuid ] | |
55 | } | |
29128b2f | 56 | |
b7819090 C |
57 | onWatchLaterClick (event: Event) { |
58 | this.watchLaterClick.emit(this.inWatchLaterPlaylist) | |
29128b2f | 59 | |
b7819090 C |
60 | event.stopPropagation() |
61 | return false | |
29128b2f | 62 | } |
202f6b6c | 63 | } |