]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-forms/form-validators/video-validators.service.ts
removed minimum width css to fit mobile devices with lesser width (#3090)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / form-validators / video-validators.service.ts
CommitLineData
e309822b 1import { Injectable } from '@angular/core'
66357162 2import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'
67ed6552 3import { BuildFormValidator } from './form-validator.service'
e309822b
C
4
5@Injectable()
6export class VideoValidatorsService {
7 readonly VIDEO_NAME: BuildFormValidator
8 readonly VIDEO_PRIVACY: BuildFormValidator
9 readonly VIDEO_CATEGORY: BuildFormValidator
10 readonly VIDEO_LICENCE: BuildFormValidator
11 readonly VIDEO_LANGUAGE: BuildFormValidator
12 readonly VIDEO_IMAGE: BuildFormValidator
13 readonly VIDEO_CHANNEL: BuildFormValidator
14 readonly VIDEO_DESCRIPTION: BuildFormValidator
02c01341
RK
15 readonly VIDEO_TAGS_ARRAY: BuildFormValidator
16 readonly VIDEO_TAG: BuildFormValidator
e309822b 17 readonly VIDEO_SUPPORT: BuildFormValidator
bbe0f064 18 readonly VIDEO_SCHEDULE_PUBLICATION_AT: BuildFormValidator
1e74f19a 19 readonly VIDEO_ORIGINALLY_PUBLISHED_AT: BuildFormValidator
e309822b 20
66357162 21 constructor () {
e309822b
C
22
23 this.VIDEO_NAME = {
24 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ],
25 MESSAGES: {
66357162
C
26 'required': $localize`Video name is required.`,
27 'minlength': $localize`Video name must be at least 3 characters long.`,
28 'maxlength': $localize`Video name cannot be more than 120 characters long.`
e309822b
C
29 }
30 }
31
32 this.VIDEO_PRIVACY = {
33 VALIDATORS: [ Validators.required ],
34 MESSAGES: {
66357162 35 'required': $localize`Video privacy is required.`
e309822b
C
36 }
37 }
38
39 this.VIDEO_CATEGORY = {
40 VALIDATORS: [ ],
41 MESSAGES: {}
42 }
43
44 this.VIDEO_LICENCE = {
45 VALIDATORS: [ ],
46 MESSAGES: {}
47 }
48
49 this.VIDEO_LANGUAGE = {
50 VALIDATORS: [ ],
51 MESSAGES: {}
52 }
53
54 this.VIDEO_IMAGE = {
55 VALIDATORS: [ ],
56 MESSAGES: {}
57 }
58
59 this.VIDEO_CHANNEL = {
60 VALIDATORS: [ Validators.required ],
61 MESSAGES: {
66357162 62 'required': $localize`Video channel is required.`
e309822b
C
63 }
64 }
65
66 this.VIDEO_DESCRIPTION = {
67 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(10000) ],
68 MESSAGES: {
66357162
C
69 'minlength': $localize`Video description must be at least 3 characters long.`,
70 'maxlength': $localize`Video description cannot be more than 10000 characters long.`
e309822b
C
71 }
72 }
73
02c01341 74 this.VIDEO_TAG = {
e309822b
C
75 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ],
76 MESSAGES: {
66357162
C
77 'minlength': $localize`A tag should be more than 2 characters long.`,
78 'maxlength': $localize`A tag should be less than 30 characters long.`
e309822b
C
79 }
80 }
81
02c01341
RK
82 this.VIDEO_TAGS_ARRAY = {
83 VALIDATORS: [ Validators.maxLength(5), this.arrayTagLengthValidator() ],
84 MESSAGES: {
66357162
C
85 'maxlength': $localize`A maximum of 5 tags can be used on a video.`,
86 'arrayTagLength': $localize`A tag should be more than 2, and less than 30 characters long.`
02c01341
RK
87 }
88 }
89
e309822b 90 this.VIDEO_SUPPORT = {
d23e6a1c 91 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ],
e309822b 92 MESSAGES: {
66357162
C
93 'minlength': $localize`Video support must be at least 3 characters long.`,
94 'maxlength': $localize`Video support cannot be more than 1000 characters long.`
e309822b
C
95 }
96 }
bbe0f064
C
97
98 this.VIDEO_SCHEDULE_PUBLICATION_AT = {
99 VALIDATORS: [ ],
100 MESSAGES: {
66357162 101 'required': $localize`A date is required to schedule video update.`
bbe0f064
C
102 }
103 }
1e74f19a 104
105 this.VIDEO_ORIGINALLY_PUBLISHED_AT = {
106 VALIDATORS: [ ],
107 MESSAGES: {}
108 }
e309822b 109 }
02c01341
RK
110
111 arrayTagLengthValidator (min = 2, max = 30): ValidatorFn {
112 return (control: AbstractControl): ValidationErrors => {
113 const array = control.value as Array<string>
114
115 if (array.every(e => e.length > min && e.length < max)) {
116 return null
117 }
118
119 return { 'arrayTagLength': true }
120 }
121 }
e309822b 122}