1 import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } 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'
8 export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto'
9 export type MiniatureDisplayOptions = {
13 privacyLabel?: boolean
16 blacklistInfo?: boolean
21 selector: 'my-video-miniature',
22 styleUrls: [ './video-miniature.component.scss' ],
23 templateUrl: './video-miniature.component.html',
24 changeDetection: ChangeDetectionStrategy.OnPush
26 export class VideoMiniatureComponent implements OnInit {
30 @Input() ownerDisplayType: OwnerDisplayType = 'account'
31 @Input() displayOptions: MiniatureDisplayOptions = {
40 @Input() displayAsRow = false
42 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
45 private serverService: ServerService,
47 @Inject(LOCALE_ID) private localeId: string
51 return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
55 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
56 this.ownerDisplayTypeChosen = this.ownerDisplayType
60 // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
61 // -> Use the account name
63 this.video.channel.name === `${this.video.account.name}_channel` ||
64 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}$/)
66 this.ownerDisplayTypeChosen = 'account'
68 this.ownerDisplayTypeChosen = 'videoChannel'
72 displayOwnerAccount () {
73 return this.ownerDisplayTypeChosen === 'account'
76 displayOwnerVideoChannel () {
77 return this.ownerDisplayTypeChosen === 'videoChannel'
81 return this.video.privacy.id === VideoPrivacy.UNLISTED
85 return this.video.privacy.id === VideoPrivacy.PRIVATE
88 getStateLabel (video: Video) {
89 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
90 return this.i18n('Published')
93 if (video.scheduledUpdate) {
94 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
95 return this.i18n('Publication scheduled on ') + updateAt
98 if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
99 return this.i18n('Waiting transcoding')
102 if (video.state.id === VideoState.TO_TRANSCODE) {
103 return this.i18n('To transcode')
106 if (video.state.id === VideoState.TO_IMPORT) {
107 return this.i18n('To import')