diff options
Diffstat (limited to 'client/src/app/shared/form-validators/video-validators.ts')
-rw-r--r-- | client/src/app/shared/form-validators/video-validators.ts | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/client/src/app/shared/form-validators/video-validators.ts b/client/src/app/shared/form-validators/video-validators.ts new file mode 100644 index 000000000..23f2391b2 --- /dev/null +++ b/client/src/app/shared/form-validators/video-validators.ts | |||
@@ -0,0 +1,101 @@ | |||
1 | import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms' | ||
2 | import { BuildFormValidator } from './form-validator.model' | ||
3 | |||
4 | export const VIDEO_NAME_VALIDATOR: BuildFormValidator = { | ||
5 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ], | ||
6 | MESSAGES: { | ||
7 | 'required': $localize`Video name is required.`, | ||
8 | 'minlength': $localize`Video name must be at least 3 characters long.`, | ||
9 | 'maxlength': $localize`Video name cannot be more than 120 characters long.` | ||
10 | } | ||
11 | } | ||
12 | |||
13 | export const VIDEO_PRIVACY_VALIDATOR: BuildFormValidator = { | ||
14 | VALIDATORS: [ Validators.required ], | ||
15 | MESSAGES: { | ||
16 | 'required': $localize`Video privacy is required.` | ||
17 | } | ||
18 | } | ||
19 | |||
20 | export const VIDEO_CATEGORY_VALIDATOR: BuildFormValidator = { | ||
21 | VALIDATORS: [ ], | ||
22 | MESSAGES: {} | ||
23 | } | ||
24 | |||
25 | export const VIDEO_LICENCE_VALIDATOR: BuildFormValidator = { | ||
26 | VALIDATORS: [ ], | ||
27 | MESSAGES: {} | ||
28 | } | ||
29 | |||
30 | export const VIDEO_LANGUAGE_VALIDATOR: BuildFormValidator = { | ||
31 | VALIDATORS: [ ], | ||
32 | MESSAGES: {} | ||
33 | } | ||
34 | |||
35 | export const VIDEO_IMAGE_VALIDATOR: BuildFormValidator = { | ||
36 | VALIDATORS: [ ], | ||
37 | MESSAGES: {} | ||
38 | } | ||
39 | |||
40 | export const VIDEO_CHANNEL_VALIDATOR: BuildFormValidator = { | ||
41 | VALIDATORS: [ Validators.required ], | ||
42 | MESSAGES: { | ||
43 | 'required': $localize`Video channel is required.` | ||
44 | } | ||
45 | } | ||
46 | |||
47 | export const VIDEO_DESCRIPTION_VALIDATOR: BuildFormValidator = { | ||
48 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(10000) ], | ||
49 | MESSAGES: { | ||
50 | 'minlength': $localize`Video description must be at least 3 characters long.`, | ||
51 | 'maxlength': $localize`Video description cannot be more than 10000 characters long.` | ||
52 | } | ||
53 | } | ||
54 | |||
55 | export const VIDEO_TAG_VALIDATOR: BuildFormValidator = { | ||
56 | VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ], | ||
57 | MESSAGES: { | ||
58 | 'minlength': $localize`A tag should be more than 2 characters long.`, | ||
59 | 'maxlength': $localize`A tag should be less than 30 characters long.` | ||
60 | } | ||
61 | } | ||
62 | |||
63 | export const VIDEO_TAGS_ARRAY_VALIDATOR: BuildFormValidator = { | ||
64 | VALIDATORS: [ Validators.maxLength(5), arrayTagLengthValidator() ], | ||
65 | MESSAGES: { | ||
66 | 'maxlength': $localize`A maximum of 5 tags can be used on a video.`, | ||
67 | 'arrayTagLength': $localize`A tag should be more than 2, and less than 30 characters long.` | ||
68 | } | ||
69 | } | ||
70 | |||
71 | export const VIDEO_SUPPORT_VALIDATOR: BuildFormValidator = { | ||
72 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ], | ||
73 | MESSAGES: { | ||
74 | 'minlength': $localize`Video support must be at least 3 characters long.`, | ||
75 | 'maxlength': $localize`Video support cannot be more than 1000 characters long.` | ||
76 | } | ||
77 | } | ||
78 | |||
79 | export const VIDEO_SCHEDULE_PUBLICATION_AT_VALIDATOR: BuildFormValidator = { | ||
80 | VALIDATORS: [ ], | ||
81 | MESSAGES: { | ||
82 | 'required': $localize`A date is required to schedule video update.` | ||
83 | } | ||
84 | } | ||
85 | |||
86 | export const VIDEO_ORIGINALLY_PUBLISHED_AT_VALIDATOR: BuildFormValidator = { | ||
87 | VALIDATORS: [ ], | ||
88 | MESSAGES: {} | ||
89 | } | ||
90 | |||
91 | function arrayTagLengthValidator (min = 2, max = 30): ValidatorFn { | ||
92 | return (control: AbstractControl): ValidationErrors => { | ||
93 | const array = control.value as Array<string> | ||
94 | |||
95 | if (array.every(e => e.length > min && e.length < max)) { | ||
96 | return null | ||
97 | } | ||
98 | |||
99 | return { 'arrayTagLength': true } | ||
100 | } | ||
101 | } | ||