1 import { I18n } from '@ngx-translate/i18n-polyfill'
2 import { Validators, ValidatorFn, ValidationErrors, AbstractControl } from '@angular/forms'
3 import { Injectable } from '@angular/core'
4 import { BuildFormValidator } from './form-validator.service'
7 export class VideoValidatorsService {
8 readonly VIDEO_NAME: BuildFormValidator
9 readonly VIDEO_PRIVACY: BuildFormValidator
10 readonly VIDEO_CATEGORY: BuildFormValidator
11 readonly VIDEO_LICENCE: BuildFormValidator
12 readonly VIDEO_LANGUAGE: BuildFormValidator
13 readonly VIDEO_IMAGE: BuildFormValidator
14 readonly VIDEO_CHANNEL: BuildFormValidator
15 readonly VIDEO_DESCRIPTION: BuildFormValidator
16 readonly VIDEO_TAGS_ARRAY: BuildFormValidator
17 readonly VIDEO_TAG: BuildFormValidator
18 readonly VIDEO_SUPPORT: BuildFormValidator
19 readonly VIDEO_SCHEDULE_PUBLICATION_AT: BuildFormValidator
20 readonly VIDEO_ORIGINALLY_PUBLISHED_AT: BuildFormValidator
22 constructor (private i18n: I18n) {
25 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ],
27 'required': this.i18n('Video name is required.'),
28 'minlength': this.i18n('Video name must be at least 3 characters long.'),
29 'maxlength': this.i18n('Video name cannot be more than 120 characters long.')
33 this.VIDEO_PRIVACY = {
34 VALIDATORS: [ Validators.required ],
36 'required': this.i18n('Video privacy is required.')
40 this.VIDEO_CATEGORY = {
45 this.VIDEO_LICENCE = {
50 this.VIDEO_LANGUAGE = {
60 this.VIDEO_CHANNEL = {
61 VALIDATORS: [ Validators.required ],
63 'required': this.i18n('Video channel is required.')
67 this.VIDEO_DESCRIPTION = {
68 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(10000) ],
70 'minlength': this.i18n('Video description must be at least 3 characters long.'),
71 'maxlength': this.i18n('Video description cannot be more than 10000 characters long.')
76 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ],
78 'minlength': this.i18n('A tag should be more than 2 characters long.'),
79 'maxlength': this.i18n('A tag should be less than 30 characters long.')
83 this.VIDEO_TAGS_ARRAY = {
84 VALIDATORS: [ Validators.maxLength(5), this.arrayTagLengthValidator() ],
86 'maxlength': this.i18n('A maximum of 5 tags can be used on a video.'),
87 'arrayTagLength': this.i18n('A tag should be more than 2, and less than 30 characters long.')
91 this.VIDEO_SUPPORT = {
92 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ],
94 'minlength': this.i18n('Video support must be at least 3 characters long.'),
95 'maxlength': this.i18n('Video support cannot be more than 1000 characters long.')
99 this.VIDEO_SCHEDULE_PUBLICATION_AT = {
102 'required': this.i18n('A date is required to schedule video update.')
106 this.VIDEO_ORIGINALLY_PUBLISHED_AT = {
112 arrayTagLengthValidator (min = 2, max = 30): ValidatorFn {
113 return (control: AbstractControl): ValidationErrors => {
114 const array = control.value as Array<string>
116 if (array.every(e => e.length > min && e.length < max)) {
120 return { 'arrayTagLength': true }