]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video-miniature.component.ts
Add search bars for a user's videos and playlist library
[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'
ba430d75 5import { ServerConfig, VideoPrivacy, VideoState } from '../../../../../shared'
e2409062 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
ba430d75 58 serverConfig: ServerConfig
22a16e36
C
59
60 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
501bc6c2 61
e2409062 62 constructor (
3a0fb65c 63 private screenService: ScreenService,
e2409062
C
64 private serverService: ServerService,
65 private i18n: I18n,
66 @Inject(LOCALE_ID) private localeId: string
67 ) { }
0883b324 68
d1a63fc7 69 get isVideoBlur () {
ba430d75 70 return this.video.isVideoNSFWForUser(this.user, this.serverConfig)
d1a63fc7
C
71 }
72
22a16e36 73 ngOnInit () {
ba430d75
C
74 this.serverConfig = this.serverService.getTmpConfig()
75 this.serverService.getConfig()
76 .subscribe(config => this.serverConfig = config)
77
3a0fb65c 78 this.setUpBy()
22a16e36 79
8dfceec4
C
80 // We rely on mouseenter to lazy load actions
81 if (this.screenService.isInTouchScreen()) {
743f023c 82 this.loadActions()
22a16e36 83 }
92fb909c 84 }
22a16e36
C
85
86 displayOwnerAccount () {
87 return this.ownerDisplayTypeChosen === 'account'
88 }
89
90 displayOwnerVideoChannel () {
91 return this.ownerDisplayTypeChosen === 'videoChannel'
92 }
017c3dca
C
93
94 isUnlistedVideo () {
95 return this.video.privacy.id === VideoPrivacy.UNLISTED
96 }
97
98 isPrivateVideo () {
99 return this.video.privacy.id === VideoPrivacy.PRIVATE
100 }
e2409062
C
101
102 getStateLabel (video: Video) {
dedc7abb
C
103 if (!video.state) return ''
104
e2409062
C
105 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
106 return this.i18n('Published')
107 }
108
109 if (video.scheduledUpdate) {
110 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
111 return this.i18n('Publication scheduled on ') + updateAt
112 }
113
114 if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
115 return this.i18n('Waiting transcoding')
116 }
117
118 if (video.state.id === VideoState.TO_TRANSCODE) {
119 return this.i18n('To transcode')
120 }
121
122 if (video.state.id === VideoState.TO_IMPORT) {
123 return this.i18n('To import')
124 }
125
126 return ''
127 }
3a0fb65c
C
128
129 loadActions () {
130 if (this.displayVideoActions) this.showActions = true
131 }
132
133 onVideoBlacklisted () {
134 this.videoBlacklisted.emit()
135 }
136
137 onVideoUnblacklisted () {
138 this.videoUnblacklisted.emit()
139 }
140
141 onVideoRemoved () {
142 this.videoRemoved.emit()
143 }
144
145 private setUpBy () {
146 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
147 this.ownerDisplayTypeChosen = this.ownerDisplayType
148 return
149 }
150
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
153 if (
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}$/)
156 ) {
157 this.ownerDisplayTypeChosen = 'account'
158 } else {
159 this.ownerDisplayTypeChosen = 'videoChannel'
160 }
161 }
501bc6c2 162}