1 import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, LOCALE_ID, OnInit, Output, ViewChild } from '@angular/core'
2 import { User } from '../users'
3 import { Video } from './video.model'
4 import { ServerService } from '@app/core'
5 import { ServerConfig, 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'
9 import { VideoThumbnailComponent } from './video-thumbnail.component'
11 export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto'
12 export type MiniatureDisplayOptions = {
16 privacyLabel?: boolean
19 blacklistInfo?: boolean
24 selector: 'my-video-miniature',
25 styleUrls: [ './video-miniature.component.scss' ],
26 templateUrl: './video-miniature.component.html',
27 changeDetection: ChangeDetectionStrategy.OnPush
29 export class VideoMiniatureComponent implements OnInit {
33 @Input() ownerDisplayType: OwnerDisplayType = 'account'
34 @Input() displayOptions: MiniatureDisplayOptions = {
43 @Input() displayAsRow = false
44 @Input() displayVideoActions = true
46 @Output() videoBlacklisted = new EventEmitter()
47 @Output() videoUnblacklisted = new EventEmitter()
48 @Output() videoRemoved = new EventEmitter()
50 @ViewChild('thumbnail', { static: true }) thumbnail: VideoThumbnailComponent
52 videoActionsDisplayOptions: VideoActionsDisplayType = {
61 serverConfig: ServerConfig
63 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
66 private screenService: ScreenService,
67 private serverService: ServerService,
69 @Inject(LOCALE_ID) private localeId: string
73 return this.video.isVideoNSFWForUser(this.user, this.serverConfig)
77 this.serverConfig = this.serverService.getTmpConfig()
78 this.serverService.getConfig()
79 .subscribe(config => this.serverConfig = config)
83 // We rely on mouseenter to lazy load actions
84 if (this.screenService.isInTouchScreen()) {
89 displayOwnerAccount () {
90 return this.ownerDisplayTypeChosen === 'account'
93 displayOwnerVideoChannel () {
94 return this.ownerDisplayTypeChosen === 'videoChannel'
98 return this.video.privacy.id === VideoPrivacy.UNLISTED
102 return this.video.privacy.id === VideoPrivacy.PRIVATE
105 getStateLabel (video: Video) {
106 if (!video.state) return ''
108 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
109 return this.i18n('Published')
112 if (video.scheduledUpdate) {
113 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
114 return this.i18n('Publication scheduled on ') + updateAt
117 if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
118 return this.i18n('Waiting transcoding')
121 if (video.state.id === VideoState.TO_TRANSCODE) {
122 return this.i18n('To transcode')
125 if (video.state.id === VideoState.TO_IMPORT) {
126 return this.i18n('To import')
133 if (this.displayVideoActions) this.showActions = true
134 this.thumbnail.load()
137 onVideoBlacklisted () {
138 this.videoBlacklisted.emit()
141 onVideoUnblacklisted () {
142 this.videoUnblacklisted.emit()
146 this.videoRemoved.emit()
150 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
151 this.ownerDisplayTypeChosen = this.ownerDisplayType
155 // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
156 // -> Use the account name
158 this.video.channel.name === `${this.video.account.name}_channel` ||
159 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}$/)
161 this.ownerDisplayTypeChosen = 'account'
163 this.ownerDisplayTypeChosen = 'videoChannel'