]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video/video-miniature.component.ts
e3552abbaf4caa8297214b575e90f3ed62c2a1d1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-miniature.component.ts
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 { 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
10 export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto'
11 export 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 }
21
22 @Component({
23 selector: 'my-video-miniature',
24 styleUrls: [ './video-miniature.component.scss' ],
25 templateUrl: './video-miniature.component.html',
26 changeDetection: ChangeDetectionStrategy.OnPush
27 })
28 export class VideoMiniatureComponent implements OnInit {
29 @Input() user: User
30 @Input() video: Video
31
32 @Input() ownerDisplayType: OwnerDisplayType = 'account'
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
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
58
59 private ownerDisplayTypeChosen: 'account' | 'videoChannel'
60
61 constructor (
62 private screenService: ScreenService,
63 private serverService: ServerService,
64 private i18n: I18n,
65 @Inject(LOCALE_ID) private localeId: string
66 ) { }
67
68 get isVideoBlur () {
69 return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
70 }
71
72 ngOnInit () {
73 this.setUpBy()
74
75 if (this.screenService.isInSmallView()) {
76 this.showActions = true
77 }
78 }
79
80 displayOwnerAccount () {
81 return this.ownerDisplayTypeChosen === 'account'
82 }
83
84 displayOwnerVideoChannel () {
85 return this.ownerDisplayTypeChosen === 'videoChannel'
86 }
87
88 isUnlistedVideo () {
89 return this.video.privacy.id === VideoPrivacy.UNLISTED
90 }
91
92 isPrivateVideo () {
93 return this.video.privacy.id === VideoPrivacy.PRIVATE
94 }
95
96 getStateLabel (video: Video) {
97 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
98 return this.i18n('Published')
99 }
100
101 if (video.scheduledUpdate) {
102 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
103 return this.i18n('Publication scheduled on ') + updateAt
104 }
105
106 if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
107 return this.i18n('Waiting transcoding')
108 }
109
110 if (video.state.id === VideoState.TO_TRANSCODE) {
111 return this.i18n('To transcode')
112 }
113
114 if (video.state.id === VideoState.TO_IMPORT) {
115 return this.i18n('To import')
116 }
117
118 return ''
119 }
120
121 loadActions () {
122 if (this.displayVideoActions) this.showActions = true
123 }
124
125 onVideoBlacklisted () {
126 this.videoBlacklisted.emit()
127 }
128
129 onVideoUnblacklisted () {
130 this.videoUnblacklisted.emit()
131 }
132
133 onVideoRemoved () {
134 this.videoRemoved.emit()
135 }
136
137 private setUpBy () {
138 if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') {
139 this.ownerDisplayTypeChosen = this.ownerDisplayType
140 return
141 }
142
143 // If the video channel name an UUID (not really displayable, we changed this behaviour in v1.0.0-beta.12)
144 // -> Use the account name
145 if (
146 this.video.channel.name === `${this.video.account.name}_channel` ||
147 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}$/)
148 ) {
149 this.ownerDisplayTypeChosen = 'account'
150 } else {
151 this.ownerDisplayTypeChosen = 'videoChannel'
152 }
153 }
154 }