1 import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, LOCALE_ID, OnInit, Output } from '@angular/core'
2 import { User } from '../users'
3 import { Video } from './video.model'
4 import { ServerService } from '@app/core'
5 import { VideoPrivacy, VideoState } from '../../../../../shared'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { VideoActionsDisplayType } from '@app/shared/video/video-actions-dropdown.component'
8 import { ScreenService } from '@app/shared/misc/screen.service'
10 export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto'
11 export type MiniatureDisplayOptions = {
15 privacyLabel?: boolean
18 blacklistInfo?: boolean
23 selector: 'my-video-miniature',
24 styleUrls: [ './video-miniature.component.scss' ],
25 templateUrl: './video-miniature.component.html',
26 changeDetection: ChangeDetectionStrategy.OnPush
28 export class VideoMiniatureComponent implements OnInit {
32 @Input() ownerDisplayType: OwnerDisplayType = 'account'
33 @Input() displayOptions: MiniatureDisplayOptions = {
42 @Input() displayAsRow = false
43 @Input() displayVideoActions = true
45 @Output() videoBlacklisted = new EventEmitter()
46 @Output() videoUnblacklisted = new EventEmitter()
47 @Output() videoRemoved = new EventEmitter()
49 videoActionsDisplayOptions: VideoActionsDisplayType = {
59 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
62 private screenService: ScreenService,
63 private serverService: ServerService,
65 @Inject(LOCALE_ID) private localeId: string
69 return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
75 // We rely on mouseenter to lazy load actions
76 if (this.screenService.isInTouchScreen()) {
81 displayOwnerAccount () {
82 return this.ownerDisplayTypeChosen === 'account'
85 displayOwnerVideoChannel () {
86 return this.ownerDisplayTypeChosen === 'videoChannel'
90 return this.video.privacy.id === VideoPrivacy.UNLISTED
94 return this.video.privacy.id === VideoPrivacy.PRIVATE
97 getStateLabel (video: Video) {
98 if (!video.state) return ''
100 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
101 return this.i18n('Published')
104 if (video.scheduledUpdate) {
105 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
106 return this.i18n('Publication scheduled on ') + updateAt
109 if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
110 return this.i18n('Waiting transcoding')
113 if (video.state.id === VideoState.TO_TRANSCODE) {
114 return this.i18n('To transcode')
117 if (video.state.id === VideoState.TO_IMPORT) {
118 return this.i18n('To import')
125 if (this.displayVideoActions) this.showActions = true
128 onVideoBlacklisted () {
129 this.videoBlacklisted.emit()
132 onVideoUnblacklisted () {
133 this.videoUnblacklisted.emit()
137 this.videoRemoved.emit()
141 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
142 this.ownerDisplayTypeChosen = this.ownerDisplayType
146 // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
147 // -> Use the account name
149 this.video.channel.name === `${this.video.account.name}_channel` ||
150 this.video.channel.name.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
152 this.ownerDisplayTypeChosen = 'account'
154 this.ownerDisplayTypeChosen = 'videoChannel'