]>
Commit | Line | Data |
---|---|---|
e2409062 | 1 | import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core' |
b1fa3eba C |
2 | import { User } from '../users' |
3 | import { Video } from './video.model' | |
0883b324 | 4 | import { ServerService } from '@app/core' |
e2409062 C |
5 | import { VideoPrivacy, VideoState } from '../../../../../shared' |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
501bc6c2 | 7 | |
22a16e36 | 8 | export type OwnerDisplayType = 'account' | 'videoChannel' | 'auto' |
e2409062 C |
9 | export type MiniatureDisplayOptions = { |
10 | date?: boolean | |
11 | views?: boolean | |
12 | by?: boolean | |
13 | privacyLabel?: boolean | |
14 | privacyText?: boolean | |
15 | state?: boolean | |
16 | blacklistInfo?: boolean | |
17 | nsfw?: boolean | |
18 | } | |
22a16e36 | 19 | |
501bc6c2 C |
20 | @Component({ |
21 | selector: 'my-video-miniature', | |
ec8d8440 | 22 | styleUrls: [ './video-miniature.component.scss' ], |
89724816 C |
23 | templateUrl: './video-miniature.component.html', |
24 | changeDetection: ChangeDetectionStrategy.OnPush | |
501bc6c2 | 25 | }) |
22a16e36 | 26 | export class VideoMiniatureComponent implements OnInit { |
df98563e C |
27 | @Input() user: User |
28 | @Input() video: Video | |
e2409062 | 29 | |
22a16e36 | 30 | @Input() ownerDisplayType: OwnerDisplayType = 'account' |
e2409062 C |
31 | @Input() displayOptions: MiniatureDisplayOptions = { |
32 | date: true, | |
33 | views: true, | |
34 | by: true, | |
35 | privacyLabel: false, | |
36 | privacyText: false, | |
37 | state: false, | |
38 | blacklistInfo: false | |
39 | } | |
40 | @Input() displayAsRow = false | |
22a16e36 C |
41 | |
42 | private ownerDisplayTypeChosen: 'account' | 'videoChannel' | |
501bc6c2 | 43 | |
e2409062 C |
44 | constructor ( |
45 | private serverService: ServerService, | |
46 | private i18n: I18n, | |
47 | @Inject(LOCALE_ID) private localeId: string | |
48 | ) { } | |
0883b324 | 49 | |
d1a63fc7 C |
50 | get isVideoBlur () { |
51 | return this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig()) | |
52 | } | |
53 | ||
22a16e36 C |
54 | ngOnInit () { |
55 | if (this.ownerDisplayType === 'account' || this.ownerDisplayType === 'videoChannel') { | |
56 | this.ownerDisplayTypeChosen = this.ownerDisplayType | |
57 | return | |
58 | } | |
59 | ||
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 | |
62 | if ( | |
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}$/) | |
65 | ) { | |
66 | this.ownerDisplayTypeChosen = 'account' | |
67 | } else { | |
68 | this.ownerDisplayTypeChosen = 'videoChannel' | |
69 | } | |
92fb909c | 70 | } |
22a16e36 C |
71 | |
72 | displayOwnerAccount () { | |
73 | return this.ownerDisplayTypeChosen === 'account' | |
74 | } | |
75 | ||
76 | displayOwnerVideoChannel () { | |
77 | return this.ownerDisplayTypeChosen === 'videoChannel' | |
78 | } | |
017c3dca C |
79 | |
80 | isUnlistedVideo () { | |
81 | return this.video.privacy.id === VideoPrivacy.UNLISTED | |
82 | } | |
83 | ||
84 | isPrivateVideo () { | |
85 | return this.video.privacy.id === VideoPrivacy.PRIVATE | |
86 | } | |
e2409062 C |
87 | |
88 | getStateLabel (video: Video) { | |
89 | if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) { | |
90 | return this.i18n('Published') | |
91 | } | |
92 | ||
93 | if (video.scheduledUpdate) { | |
94 | const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId) | |
95 | return this.i18n('Publication scheduled on ') + updateAt | |
96 | } | |
97 | ||
98 | if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) { | |
99 | return this.i18n('Waiting transcoding') | |
100 | } | |
101 | ||
102 | if (video.state.id === VideoState.TO_TRANSCODE) { | |
103 | return this.i18n('To transcode') | |
104 | } | |
105 | ||
106 | if (video.state.id === VideoState.TO_IMPORT) { | |
107 | return this.i18n('To import') | |
108 | } | |
109 | ||
110 | return '' | |
111 | } | |
501bc6c2 | 112 | } |