aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/shared/video-edit.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-15 16:52:15 +0200
committerChocobozzz <me@florianbigard.com>2018-06-15 18:20:56 +0200
commitbbe0f0645ca958d33a3f409b15166609733b663f (patch)
treeedcd5d702c73cda74a2177c4bdc08c616334337d /client/src/app/videos/+video-edit/shared/video-edit.component.ts
parent2baea0c77cc765f7cbca9c9a2f4272268892a35c (diff)
downloadPeerTube-bbe0f0645ca958d33a3f409b15166609733b663f.tar.gz
PeerTube-bbe0f0645ca958d33a3f409b15166609733b663f.tar.zst
PeerTube-bbe0f0645ca958d33a3f409b15166609733b663f.zip
Add ability to schedule video publication
Diffstat (limited to 'client/src/app/videos/+video-edit/shared/video-edit.component.ts')
-rw-r--r--client/src/app/videos/+video-edit/shared/video-edit.component.ts79
1 files changed, 67 insertions, 12 deletions
diff --git a/client/src/app/videos/+video-edit/shared/video-edit.component.ts b/client/src/app/videos/+video-edit/shared/video-edit.component.ts
index ee4fd5dc1..24418fc4f 100644
--- a/client/src/app/videos/+video-edit/shared/video-edit.component.ts
+++ b/client/src/app/videos/+video-edit/shared/video-edit.component.ts
@@ -1,5 +1,5 @@
1import { Component, Input, OnInit } from '@angular/core' 1import { Component, Input, OnInit } from '@angular/core'
2import { FormGroup, ValidatorFn } from '@angular/forms' 2import { FormGroup, ValidatorFn, Validators } from '@angular/forms'
3import { ActivatedRoute, Router } from '@angular/router' 3import { ActivatedRoute, Router } from '@angular/router'
4import { FormReactiveValidationMessages, VideoValidatorsService } from '@app/shared' 4import { FormReactiveValidationMessages, VideoValidatorsService } from '@app/shared'
5import { NotificationsService } from 'angular2-notifications' 5import { NotificationsService } from 'angular2-notifications'
@@ -7,6 +7,7 @@ import { ServerService } from '../../../core/server'
7import { VideoEdit } from '../../../shared/video/video-edit.model' 7import { VideoEdit } from '../../../shared/video/video-edit.model'
8import { map } from 'rxjs/operators' 8import { map } from 'rxjs/operators'
9import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 9import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
10import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar'
10 11
11@Component({ 12@Component({
12 selector: 'my-video-edit', 13 selector: 'my-video-edit',
@@ -20,16 +21,26 @@ export class VideoEditComponent implements OnInit {
20 @Input() validationMessages: FormReactiveValidationMessages = {} 21 @Input() validationMessages: FormReactiveValidationMessages = {}
21 @Input() videoPrivacies = [] 22 @Input() videoPrivacies = []
22 @Input() userVideoChannels: { id: number, label: string, support: string }[] = [] 23 @Input() userVideoChannels: { id: number, label: string, support: string }[] = []
24 @Input() schedulePublicationPossible = true
25
26 // So that it can be accessed in the template
27 readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY
23 28
24 videoCategories = [] 29 videoCategories = []
25 videoLicences = [] 30 videoLicences = []
26 videoLanguages = [] 31 videoLanguages = []
27 video: VideoEdit
28 32
29 tagValidators: ValidatorFn[] 33 tagValidators: ValidatorFn[]
30 tagValidatorsMessages: { [ name: string ]: string } 34 tagValidatorsMessages: { [ name: string ]: string }
31 35
36 schedulePublicationEnabled = false
37
32 error: string = null 38 error: string = null
39 calendarLocale: any = {}
40 minScheduledDate = new Date()
41
42 calendarTimezone: string
43 calendarDateFormat: string
33 44
34 constructor ( 45 constructor (
35 private formValidatorService: FormValidatorService, 46 private formValidatorService: FormValidatorService,
@@ -37,10 +48,15 @@ export class VideoEditComponent implements OnInit {
37 private route: ActivatedRoute, 48 private route: ActivatedRoute,
38 private router: Router, 49 private router: Router,
39 private notificationsService: NotificationsService, 50 private notificationsService: NotificationsService,
40 private serverService: ServerService 51 private serverService: ServerService,
52 private i18nPrimengCalendarService: I18nPrimengCalendarService
41 ) { 53 ) {
42 this.tagValidators = this.videoValidatorsService.VIDEO_TAGS.VALIDATORS 54 this.tagValidators = this.videoValidatorsService.VIDEO_TAGS.VALIDATORS
43 this.tagValidatorsMessages = this.videoValidatorsService.VIDEO_TAGS.MESSAGES 55 this.tagValidatorsMessages = this.videoValidatorsService.VIDEO_TAGS.MESSAGES
56
57 this.calendarLocale = this.i18nPrimengCalendarService.getCalendarLocale()
58 this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone()
59 this.calendarDateFormat = this.i18nPrimengCalendarService.getDateFormat()
44 } 60 }
45 61
46 updateForm () { 62 updateForm () {
@@ -64,7 +80,8 @@ export class VideoEditComponent implements OnInit {
64 tags: null, 80 tags: null,
65 thumbnailfile: null, 81 thumbnailfile: null,
66 previewfile: null, 82 previewfile: null,
67 support: this.videoValidatorsService.VIDEO_SUPPORT 83 support: this.videoValidatorsService.VIDEO_SUPPORT,
84 schedulePublicationAt: this.videoValidatorsService.VIDEO_SCHEDULE_PUBLICATION_AT
68 } 85 }
69 86
70 this.formValidatorService.updateForm( 87 this.formValidatorService.updateForm(
@@ -75,6 +92,52 @@ export class VideoEditComponent implements OnInit {
75 defaultValues 92 defaultValues
76 ) 93 )
77 94
95 this.trackChannelChange()
96 this.trackPrivacyChange()
97 }
98
99 ngOnInit () {
100 this.updateForm()
101
102 this.videoCategories = this.serverService.getVideoCategories()
103 this.videoLicences = this.serverService.getVideoLicences()
104 this.videoLanguages = this.serverService.getVideoLanguages()
105
106 setTimeout(() => this.minScheduledDate = new Date(), 1000 * 60) // Update every minute
107 }
108
109 private trackPrivacyChange () {
110 // We will update the "support" field depending on the channel
111 this.form.controls[ 'privacy' ]
112 .valueChanges
113 .pipe(map(res => parseInt(res.toString(), 10)))
114 .subscribe(
115 newPrivacyId => {
116 this.schedulePublicationEnabled = newPrivacyId === this.SPECIAL_SCHEDULED_PRIVACY
117
118 // Value changed
119 const scheduleControl = this.form.get('schedulePublicationAt')
120 const waitTranscodingControl = this.form.get('waitTranscoding')
121
122 if (this.schedulePublicationEnabled) {
123 scheduleControl.setValidators([ Validators.required ])
124
125 waitTranscodingControl.disable()
126 waitTranscodingControl.setValue(false)
127 } else {
128 scheduleControl.clearValidators()
129
130 waitTranscodingControl.enable()
131 waitTranscodingControl.setValue(true)
132 }
133
134 scheduleControl.updateValueAndValidity()
135 waitTranscodingControl.updateValueAndValidity()
136 }
137 )
138 }
139
140 private trackChannelChange () {
78 // We will update the "support" field depending on the channel 141 // We will update the "support" field depending on the channel
79 this.form.controls[ 'channelId' ] 142 this.form.controls[ 'channelId' ]
80 .valueChanges 143 .valueChanges
@@ -108,14 +171,6 @@ export class VideoEditComponent implements OnInit {
108 ) 171 )
109 } 172 }
110 173
111 ngOnInit () {
112 this.updateForm()
113
114 this.videoCategories = this.serverService.getVideoCategories()
115 this.videoLicences = this.serverService.getVideoLicences()
116 this.videoLanguages = this.serverService.getVideoLanguages()
117 }
118
119 private updateSupportField (support: string) { 174 private updateSupportField (support: string) {
120 return this.form.patchValue({ support: support || '' }) 175 return this.form.patchValue({ support: support || '' })
121 } 176 }