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 { 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'
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 = {
58 serverConfig: ServerConfig
60 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
63 private screenService: ScreenService,
64 private serverService: ServerService,
66 @Inject(LOCALE_ID) private localeId: string
70 return this.video.isVideoNSFWForUser(this.user, this.serverConfig)
74 this.serverConfig = this.serverService.getTmpConfig()
75 this.serverService.getConfig()
76 .subscribe(config => this.serverConfig = config)
80 // We rely on mouseenter to lazy load actions
81 if (this.screenService.isInTouchScreen()) {
86 displayOwnerAccount () {
87 return this.ownerDisplayTypeChosen === 'account'
90 displayOwnerVideoChannel () {
91 return this.ownerDisplayTypeChosen === 'videoChannel'
95 return this.video.privacy.id === VideoPrivacy.UNLISTED
99 return this.video.privacy.id === VideoPrivacy.PRIVATE
102 getStateLabel (video: Video) {
103 if (!video.state) return ''
105 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
106 return this.i18n('Published')
109 if (video.scheduledUpdate) {
110 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
111 return this.i18n('Publication scheduled on ') + updateAt
114 if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
115 return this.i18n('Waiting transcoding')
118 if (video.state.id === VideoState.TO_TRANSCODE) {
119 return this.i18n('To transcode')
122 if (video.state.id === VideoState.TO_IMPORT) {
123 return this.i18n('To import')
130 if (this.displayVideoActions) this.showActions = true
133 onVideoBlacklisted () {
134 this.videoBlacklisted.emit()
137 onVideoUnblacklisted () {
138 this.videoUnblacklisted.emit()
142 this.videoRemoved.emit()
146 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
147 this.ownerDisplayTypeChosen = this.ownerDisplayType
151 // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
152 // -> Use the account name
154 this.video.channel.name === `${this.video.account.name}_channel` ||
155 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}$/)
157 this.ownerDisplayTypeChosen = 'account'
159 this.ownerDisplayTypeChosen = 'videoChannel'