]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video-miniature.component.ts
Add language filters in user preferences
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-miniature.component.ts
CommitLineData
3a0fb65c 1import { ChangeDetectionStrategy, Component, EventEmitter, Inject, Input, LOCALE_ID, OnInit, Output } from '@angular/core'
b1fa3eba
C
2import { User } from '../users'
3import { Video } from './video.model'
0883b324 4import { ServerService } from '@app/core'
e2409062
C
5import { VideoPrivacy, VideoState } from '../../../../../shared'
6import { I18n } from '@ngx-translate/i18n-polyfill'
3a0fb65c
C
7import { VideoActionsDisplayType } from '@app/shared/video/video-actions-dropdown.component'
8import { ScreenService } from '@app/shared/misc/screen.service'
501bc6c2 9
22a16e36 10export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto'
e2409062
C
11export type MiniatureDisplayOptions = {
12 date?: boolean
13 views?: boolean
14 by?: boolean
15 privacyLabel?: boolean
16 privacyText?: boolean
17 state?: boolean
18 blacklistInfo?: boolean
19 nsfw?: boolean
20}
22a16e36 21
501bc6c2
C
22@Component({
23 selector: 'my-video-miniature',
ec8d8440 24 styleUrls: [ './video-miniature.component.scss' ],
89724816
C
25 templateUrl: './video-miniature.component.html',
26 changeDetection: ChangeDetectionStrategy.OnPush
501bc6c2 27})
22a16e36 28export class VideoMiniatureComponent implements OnInit {
df98563e
C
29 @Input() user: User
30 @Input() video: Video
e2409062 31
22a16e36 32 @Input() ownerDisplayType: OwnerDisplayType = 'account'
e2409062
C
33 @Input() displayOptions: MiniatureDisplayOptions = {
34 date: true,
35 views: true,
36 by: true,
37 privacyLabel: false,
38 privacyText: false,
39 state: false,
40 blacklistInfo: false
41 }
42 @Input() displayAsRow = false
3a0fb65c
C
43 @Input() displayVideoActions = true
44
45 @Output() videoBlacklisted = new EventEmitter()
46 @Output() videoUnblacklisted = new EventEmitter()
47 @Output() videoRemoved = new EventEmitter()
48
49 videoActionsDisplayOptions: VideoActionsDisplayType = {
50 playlist: true,
51 download: false,
52 update: true,
53 blacklist: true,
54 delete: true,
55 report: true
56 }
57 showActions = false
22a16e36
C
58
59 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
501bc6c2 60
e2409062 61 constructor (
3a0fb65c 62 private screenService: ScreenService,
e2409062
C
63 private serverService: ServerService,
64 private i18n: I18n,
65 @Inject(LOCALE_ID) private localeId: string
66 ) { }
0883b324 67
d1a63fc7
C
68 get isVideoBlur () {
69 return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
70 }
71
22a16e36 72 ngOnInit () {
3a0fb65c 73 this.setUpBy()
22a16e36 74
8dfceec4
C
75 // We rely on mouseenter to lazy load actions
76 if (this.screenService.isInTouchScreen()) {
743f023c 77 this.loadActions()
22a16e36 78 }
92fb909c 79 }
22a16e36
C
80
81 displayOwnerAccount () {
82 return this.ownerDisplayTypeChosen === 'account'
83 }
84
85 displayOwnerVideoChannel () {
86 return this.ownerDisplayTypeChosen === 'videoChannel'
87 }
017c3dca
C
88
89 isUnlistedVideo () {
90 return this.video.privacy.id === VideoPrivacy.UNLISTED
91 }
92
93 isPrivateVideo () {
94 return this.video.privacy.id === VideoPrivacy.PRIVATE
95 }
e2409062
C
96
97 getStateLabel (video: Video) {
98 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
99 return this.i18n('Published')
100 }
101
102 if (video.scheduledUpdate) {
103 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
104 return this.i18n('Publication scheduled on ') + updateAt
105 }
106
107 if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
108 return this.i18n('Waiting transcoding')
109 }
110
111 if (video.state.id === VideoState.TO_TRANSCODE) {
112 return this.i18n('To transcode')
113 }
114
115 if (video.state.id === VideoState.TO_IMPORT) {
116 return this.i18n('To import')
117 }
118
119 return ''
120 }
3a0fb65c
C
121
122 loadActions () {
123 if (this.displayVideoActions) this.showActions = true
124 }
125
126 onVideoBlacklisted () {
127 this.videoBlacklisted.emit()
128 }
129
130 onVideoUnblacklisted () {
131 this.videoUnblacklisted.emit()
132 }
133
134 onVideoRemoved () {
135 this.videoRemoved.emit()
136 }
137
138 private setUpBy () {
139 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
140 this.ownerDisplayTypeChosen = this.ownerDisplayType
141 return
142 }
143
144 // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
145 // -> Use the account name
146 if (
147 this.video.channel.name === `${this.video.account.name}_channel` ||
148 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}$/)
149 ) {
150 this.ownerDisplayTypeChosen = 'account'
151 } else {
152 this.ownerDisplayTypeChosen = 'videoChannel'
153 }
154 }
501bc6c2 155}