diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-05 15:01:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-05 15:02:27 +0200 |
commit | e309822b93d9b69f30cbe830ef3d09dfdb2c13b2 (patch) | |
tree | 41dbc3b3108ced7fdba4062974e568695c30e486 /client/src/app/shared | |
parent | d4d5853e65e584ca51c718f8df590b987f981047 (diff) | |
download | PeerTube-e309822b93d9b69f30cbe830ef3d09dfdb2c13b2.tar.gz PeerTube-e309822b93d9b69f30cbe830ef3d09dfdb2c13b2.tar.zst PeerTube-e309822b93d9b69f30cbe830ef3d09dfdb2c13b2.zip |
Add form validator translations
Diffstat (limited to 'client/src/app/shared')
20 files changed, 420 insertions, 288 deletions
diff --git a/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts b/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts new file mode 100644 index 000000000..1b36bbc6b --- /dev/null +++ b/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts | |||
@@ -0,0 +1,72 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
3 | import { BuildFormValidator } from '@app/shared' | ||
4 | import { Injectable } from '@angular/core' | ||
5 | |||
6 | @Injectable() | ||
7 | export class CustomConfigValidatorsService { | ||
8 | readonly INSTANCE_NAME: BuildFormValidator | ||
9 | readonly INSTANCE_SHORT_DESCRIPTION: BuildFormValidator | ||
10 | readonly SERVICES_TWITTER_USERNAME: BuildFormValidator | ||
11 | readonly CACHE_PREVIEWS_SIZE: BuildFormValidator | ||
12 | readonly SIGNUP_LIMIT: BuildFormValidator | ||
13 | readonly ADMIN_EMAIL: BuildFormValidator | ||
14 | readonly TRANSCODING_THREADS: BuildFormValidator | ||
15 | |||
16 | constructor (private i18n: I18n) { | ||
17 | this.INSTANCE_NAME = { | ||
18 | VALIDATORS: [ Validators.required ], | ||
19 | MESSAGES: { | ||
20 | 'required': this.i18n('Instance name is required.') | ||
21 | } | ||
22 | } | ||
23 | |||
24 | this.INSTANCE_SHORT_DESCRIPTION = { | ||
25 | VALIDATORS: [ Validators.max(250) ], | ||
26 | MESSAGES: { | ||
27 | 'max': this.i18n('Short description should not be longer than 250 characters.') | ||
28 | } | ||
29 | } | ||
30 | |||
31 | this.SERVICES_TWITTER_USERNAME = { | ||
32 | VALIDATORS: [ Validators.required ], | ||
33 | MESSAGES: { | ||
34 | 'required': this.i18n('Twitter username is required.') | ||
35 | } | ||
36 | } | ||
37 | |||
38 | this.CACHE_PREVIEWS_SIZE = { | ||
39 | VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ], | ||
40 | MESSAGES: { | ||
41 | 'required': this.i18n('Previews cache size is required.'), | ||
42 | 'min': this.i18n('Previews cache size must be greater than 1.'), | ||
43 | 'pattern': this.i18n('Previews cache size must be a number.') | ||
44 | } | ||
45 | } | ||
46 | |||
47 | this.SIGNUP_LIMIT = { | ||
48 | VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ], | ||
49 | MESSAGES: { | ||
50 | 'required': this.i18n('Signup limit is required.'), | ||
51 | 'min': this.i18n('Signup limit must be greater than 1.'), | ||
52 | 'pattern': this.i18n('Signup limit must be a number.') | ||
53 | } | ||
54 | } | ||
55 | |||
56 | this.ADMIN_EMAIL = { | ||
57 | VALIDATORS: [ Validators.required, Validators.email ], | ||
58 | MESSAGES: { | ||
59 | 'required': this.i18n('Admin email is required.'), | ||
60 | 'email': this.i18n('Admin email must be valid.') | ||
61 | } | ||
62 | } | ||
63 | |||
64 | this.TRANSCODING_THREADS = { | ||
65 | VALIDATORS: [ Validators.required, Validators.min(1) ], | ||
66 | MESSAGES: { | ||
67 | 'required': this.i18n('Transcoding threads is required.'), | ||
68 | 'min': this.i18n('Transcoding threads must be greater than 1.') | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/custom-config.ts b/client/src/app/shared/forms/form-validators/custom-config.ts deleted file mode 100644 index e3d9a4c7b..000000000 --- a/client/src/app/shared/forms/form-validators/custom-config.ts +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const INSTANCE_NAME = { | ||
4 | VALIDATORS: [ Validators.required ], | ||
5 | MESSAGES: { | ||
6 | 'required': 'Instance name is required.' | ||
7 | } | ||
8 | } | ||
9 | |||
10 | export const INSTANCE_SHORT_DESCRIPTION = { | ||
11 | VALIDATORS: [ Validators.max(250) ], | ||
12 | MESSAGES: { | ||
13 | 'max': 'Short description should not be longer than 250 characters.' | ||
14 | } | ||
15 | } | ||
16 | |||
17 | export const SERVICES_TWITTER_USERNAME = { | ||
18 | VALIDATORS: [ Validators.required ], | ||
19 | MESSAGES: { | ||
20 | 'required': 'Twitter username is required.' | ||
21 | } | ||
22 | } | ||
23 | |||
24 | export const CACHE_PREVIEWS_SIZE = { | ||
25 | VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ], | ||
26 | MESSAGES: { | ||
27 | 'required': 'Preview cache size is required.', | ||
28 | 'min': 'Preview cache size must be greater than 1.', | ||
29 | 'pattern': 'Preview cache size must be a number.' | ||
30 | } | ||
31 | } | ||
32 | |||
33 | export const SIGNUP_LIMIT = { | ||
34 | VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ], | ||
35 | MESSAGES: { | ||
36 | 'required': 'Signup limit is required.', | ||
37 | 'min': 'Signup limit must be greater than 1.', | ||
38 | 'pattern': 'Preview cache size must be a number.' | ||
39 | } | ||
40 | } | ||
41 | |||
42 | export const ADMIN_EMAIL = { | ||
43 | VALIDATORS: [ Validators.required, Validators.email ], | ||
44 | MESSAGES: { | ||
45 | 'required': 'Admin email is required.', | ||
46 | 'email': 'Admin email must be valid.' | ||
47 | } | ||
48 | } | ||
49 | |||
50 | export const TRANSCODING_THREADS = { | ||
51 | VALIDATORS: [ Validators.required, Validators.min(1) ], | ||
52 | MESSAGES: { | ||
53 | 'required': 'Transcoding threads is required.', | ||
54 | 'min': 'Transcoding threads must be greater than 1.' | ||
55 | } | ||
56 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/form-validator.service.ts b/client/src/app/shared/forms/form-validators/form-validator.service.ts index 5c3d3e4bd..d10e17ca7 100644 --- a/client/src/app/shared/forms/form-validators/form-validator.service.ts +++ b/client/src/app/shared/forms/form-validators/form-validator.service.ts | |||
@@ -3,11 +3,12 @@ import { Injectable } from '@angular/core' | |||
3 | import { FormReactiveErrors, FormReactiveValidationMessages } from '@app/shared/forms/form-reactive' | 3 | import { FormReactiveErrors, FormReactiveValidationMessages } from '@app/shared/forms/form-reactive' |
4 | import { I18n } from '@ngx-translate/i18n-polyfill' | 4 | import { I18n } from '@ngx-translate/i18n-polyfill' |
5 | 5 | ||
6 | export type BuildFormValidator = { | ||
7 | VALIDATORS: ValidatorFn[], | ||
8 | MESSAGES: { [ name: string ]: string } | ||
9 | } | ||
6 | export type BuildFormArgument = { | 10 | export type BuildFormArgument = { |
7 | [ id: string ]: { | 11 | [ id: string ]: BuildFormValidator |
8 | VALIDATORS: ValidatorFn[], | ||
9 | MESSAGES: { [ name: string ]: string } | ||
10 | } | ||
11 | } | 12 | } |
12 | export type BuildFormDefaultValues = { | 13 | export type BuildFormDefaultValues = { |
13 | [ name: string ]: string | string[] | 14 | [ name: string ]: string | string[] |
diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts index cf544b2a9..487683088 100644 --- a/client/src/app/shared/forms/form-validators/index.ts +++ b/client/src/app/shared/forms/form-validators/index.ts | |||
@@ -1,5 +1,10 @@ | |||
1 | export * from './custom-config-validators.service' | ||
1 | export * from './form-validator.service' | 2 | export * from './form-validator.service' |
2 | export * from './host' | 3 | export * from './host' |
3 | export * from './user' | 4 | export * from './login-validators.service' |
4 | export * from './video-abuse' | 5 | export * from './reset-password-validators.service' |
5 | export * from './video' | 6 | export * from './user-validators.service' |
7 | export * from './video-abuse-validators.service' | ||
8 | export * from './video-channel-validators.service' | ||
9 | export * from './video-comment-validators.service' | ||
10 | export * from './video-validators.service' | ||
diff --git a/client/src/app/shared/forms/form-validators/login-validators.service.ts b/client/src/app/shared/forms/form-validators/login-validators.service.ts new file mode 100644 index 000000000..9d68f830c --- /dev/null +++ b/client/src/app/shared/forms/form-validators/login-validators.service.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class LoginValidatorsService { | ||
8 | readonly LOGIN_USERNAME: BuildFormValidator | ||
9 | readonly LOGIN_PASSWORD: BuildFormValidator | ||
10 | |||
11 | constructor (private i18n: I18n) { | ||
12 | this.LOGIN_USERNAME = { | ||
13 | VALIDATORS: [ | ||
14 | Validators.required | ||
15 | ], | ||
16 | MESSAGES: { | ||
17 | 'required': this.i18n('Username is required.') | ||
18 | } | ||
19 | } | ||
20 | |||
21 | this.LOGIN_PASSWORD = { | ||
22 | VALIDATORS: [ | ||
23 | Validators.required | ||
24 | ], | ||
25 | MESSAGES: { | ||
26 | 'required': this.i18n('Password is required.') | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/login.ts b/client/src/app/shared/forms/form-validators/login.ts deleted file mode 100644 index f37f8d285..000000000 --- a/client/src/app/shared/forms/form-validators/login.ts +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const LOGIN_USERNAME = { | ||
4 | VALIDATORS: [ | ||
5 | Validators.required | ||
6 | ], | ||
7 | MESSAGES: { | ||
8 | 'required': 'Username is required.' | ||
9 | } | ||
10 | } | ||
11 | export const LOGIN_PASSWORD = { | ||
12 | VALIDATORS: [ | ||
13 | Validators.required | ||
14 | ], | ||
15 | MESSAGES: { | ||
16 | 'required': 'Password is required.' | ||
17 | } | ||
18 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/reset-password-validators.service.ts b/client/src/app/shared/forms/form-validators/reset-password-validators.service.ts new file mode 100644 index 000000000..df206254d --- /dev/null +++ b/client/src/app/shared/forms/form-validators/reset-password-validators.service.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class ResetPasswordValidatorsService { | ||
8 | readonly RESET_PASSWORD_CONFIRM: BuildFormValidator | ||
9 | |||
10 | constructor (private i18n: I18n) { | ||
11 | this.RESET_PASSWORD_CONFIRM = { | ||
12 | VALIDATORS: [ | ||
13 | Validators.required | ||
14 | ], | ||
15 | MESSAGES: { | ||
16 | 'required': this.i18n('Confirmation of the password is required.') | ||
17 | } | ||
18 | } | ||
19 | } | ||
20 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/reset-password.ts b/client/src/app/shared/forms/form-validators/reset-password.ts deleted file mode 100644 index 7dafdef9a..000000000 --- a/client/src/app/shared/forms/form-validators/reset-password.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const RESET_PASSWORD_CONFIRM = { | ||
4 | VALIDATORS: [ | ||
5 | Validators.required | ||
6 | ], | ||
7 | MESSAGES: { | ||
8 | 'required': 'Confirmation of the password is required.' | ||
9 | } | ||
10 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/user-validators.service.ts b/client/src/app/shared/forms/form-validators/user-validators.service.ts new file mode 100644 index 000000000..bb6ff2068 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/user-validators.service.ts | |||
@@ -0,0 +1,93 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { BuildFormValidator } from '@app/shared' | ||
4 | import { Injectable } from '@angular/core' | ||
5 | |||
6 | @Injectable() | ||
7 | export class UserValidatorsService { | ||
8 | readonly USER_USERNAME: BuildFormValidator | ||
9 | readonly USER_EMAIL: BuildFormValidator | ||
10 | readonly USER_PASSWORD: BuildFormValidator | ||
11 | readonly USER_VIDEO_QUOTA: BuildFormValidator | ||
12 | readonly USER_ROLE: BuildFormValidator | ||
13 | readonly USER_DISPLAY_NAME: BuildFormValidator | ||
14 | readonly USER_DESCRIPTION: BuildFormValidator | ||
15 | |||
16 | constructor (private i18n: I18n) { | ||
17 | |||
18 | this.USER_USERNAME = { | ||
19 | VALIDATORS: [ | ||
20 | Validators.required, | ||
21 | Validators.minLength(3), | ||
22 | Validators.maxLength(20), | ||
23 | Validators.pattern(/^[a-z0-9._]+$/) | ||
24 | ], | ||
25 | MESSAGES: { | ||
26 | 'required': this.i18n('Username is required.'), | ||
27 | 'minlength': this.i18n('Username must be at least 3 characters long.'), | ||
28 | 'maxlength': this.i18n('Username cannot be more than 20 characters long.'), | ||
29 | 'pattern': this.i18n('Username should be only lowercase alphanumeric characters.') | ||
30 | } | ||
31 | } | ||
32 | |||
33 | this.USER_EMAIL = { | ||
34 | VALIDATORS: [ Validators.required, Validators.email ], | ||
35 | MESSAGES: { | ||
36 | 'required': this.i18n('Email is required.'), | ||
37 | 'email': this.i18n('Email must be valid.') | ||
38 | } | ||
39 | } | ||
40 | |||
41 | this.USER_PASSWORD = { | ||
42 | VALIDATORS: [ | ||
43 | Validators.required, | ||
44 | Validators.minLength(6), | ||
45 | Validators.maxLength(255) | ||
46 | ], | ||
47 | MESSAGES: { | ||
48 | 'required': this.i18n('Password is required.'), | ||
49 | 'minlength': this.i18n('Password must be at least 6 characters long.'), | ||
50 | 'maxlength': this.i18n('Password cannot be more than 255 characters long.') | ||
51 | } | ||
52 | } | ||
53 | |||
54 | this.USER_VIDEO_QUOTA = { | ||
55 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | ||
56 | MESSAGES: { | ||
57 | 'required': this.i18n('Video quota is required.'), | ||
58 | 'min': this.i18n('Quota must be greater than -1.') | ||
59 | } | ||
60 | } | ||
61 | |||
62 | this.USER_ROLE = { | ||
63 | VALIDATORS: [ Validators.required ], | ||
64 | MESSAGES: { | ||
65 | 'required': this.i18n('User role is required.') | ||
66 | } | ||
67 | } | ||
68 | |||
69 | this.USER_DISPLAY_NAME = { | ||
70 | VALIDATORS: [ | ||
71 | Validators.required, | ||
72 | Validators.minLength(3), | ||
73 | Validators.maxLength(120) | ||
74 | ], | ||
75 | MESSAGES: { | ||
76 | 'required': this.i18n('Display name is required.'), | ||
77 | 'minlength': this.i18n('Display name must be at least 3 characters long.'), | ||
78 | 'maxlength': this.i18n('Display name cannot be more than 120 characters long.') | ||
79 | } | ||
80 | } | ||
81 | |||
82 | this.USER_DESCRIPTION = { | ||
83 | VALIDATORS: [ | ||
84 | Validators.minLength(3), | ||
85 | Validators.maxLength(250) | ||
86 | ], | ||
87 | MESSAGES: { | ||
88 | 'minlength': this.i18n('Description must be at least 3 characters long.'), | ||
89 | 'maxlength': this.i18n('Description cannot be more than 250 characters long.') | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/user.ts b/client/src/app/shared/forms/form-validators/user.ts deleted file mode 100644 index 0973f1b00..000000000 --- a/client/src/app/shared/forms/form-validators/user.ts +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const USER_USERNAME = { | ||
4 | VALIDATORS: [ | ||
5 | Validators.required, | ||
6 | Validators.minLength(3), | ||
7 | Validators.maxLength(20), | ||
8 | Validators.pattern(/^[a-z0-9._]+$/) | ||
9 | ], | ||
10 | MESSAGES: { | ||
11 | 'required': 'Username is required.', | ||
12 | 'minlength': 'Username must be at least 3 characters long.', | ||
13 | 'maxlength': 'Username cannot be more than 20 characters long.', | ||
14 | 'pattern': 'Username should be only lowercase alphanumeric characters.' | ||
15 | } | ||
16 | } | ||
17 | export const USER_EMAIL = { | ||
18 | VALIDATORS: [ Validators.required, Validators.email ], | ||
19 | MESSAGES: { | ||
20 | 'required': 'Email is required.', | ||
21 | 'email': 'Email must be valid.' | ||
22 | } | ||
23 | } | ||
24 | export const USER_PASSWORD = { | ||
25 | VALIDATORS: [ | ||
26 | Validators.required, | ||
27 | Validators.minLength(6), | ||
28 | Validators.maxLength(255) | ||
29 | ], | ||
30 | MESSAGES: { | ||
31 | 'required': 'Password is required.', | ||
32 | 'minlength': 'Password must be at least 6 characters long.', | ||
33 | 'maxlength': 'Password cannot be more than 255 characters long.' | ||
34 | } | ||
35 | } | ||
36 | export const USER_VIDEO_QUOTA = { | ||
37 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | ||
38 | MESSAGES: { | ||
39 | 'required': 'Video quota is required.', | ||
40 | 'min': 'Quota must be greater than -1.' | ||
41 | } | ||
42 | } | ||
43 | export const USER_ROLE = { | ||
44 | VALIDATORS: [ Validators.required ], | ||
45 | MESSAGES: { | ||
46 | 'required': 'User role is required.' | ||
47 | } | ||
48 | } | ||
49 | export const USER_DISPLAY_NAME = { | ||
50 | VALIDATORS: [ | ||
51 | Validators.required, | ||
52 | Validators.minLength(3), | ||
53 | Validators.maxLength(120) | ||
54 | ], | ||
55 | MESSAGES: { | ||
56 | 'required': 'Display name is required.', | ||
57 | 'minlength': 'Display name must be at least 3 characters long.', | ||
58 | 'maxlength': 'Display name cannot be more than 120 characters long.' | ||
59 | } | ||
60 | } | ||
61 | export const USER_DESCRIPTION = { | ||
62 | VALIDATORS: [ | ||
63 | Validators.minLength(3), | ||
64 | Validators.maxLength(250) | ||
65 | ], | ||
66 | MESSAGES: { | ||
67 | 'minlength': 'Description must be at least 3 characters long.', | ||
68 | 'maxlength': 'Description cannot be more than 250 characters long.' | ||
69 | } | ||
70 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/validator-message.ts b/client/src/app/shared/forms/form-validators/validator-message.ts deleted file mode 100644 index 5ce45833b..000000000 --- a/client/src/app/shared/forms/form-validators/validator-message.ts +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | export type ValidatorMessage = { | ||
2 | [ id: string ]: { | ||
3 | [ error: string ]: string | ||
4 | } | ||
5 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video-abuse-validators.service.ts b/client/src/app/shared/forms/form-validators/video-abuse-validators.service.ts new file mode 100644 index 000000000..774e6a488 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/video-abuse-validators.service.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class VideoAbuseValidatorsService { | ||
8 | readonly VIDEO_ABUSE_REASON: BuildFormValidator | ||
9 | |||
10 | constructor (private i18n: I18n) { | ||
11 | this.VIDEO_ABUSE_REASON = { | ||
12 | VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ], | ||
13 | MESSAGES: { | ||
14 | 'required': this.i18n('Report reason is required.'), | ||
15 | 'minlength': this.i18n('Report reason must be at least 2 characters long.'), | ||
16 | 'maxlength': this.i18n('Report reason cannot be more than 300 characters long.') | ||
17 | } | ||
18 | } | ||
19 | } | ||
20 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video-abuse.ts b/client/src/app/shared/forms/form-validators/video-abuse.ts deleted file mode 100644 index 4b2a2b789..000000000 --- a/client/src/app/shared/forms/form-validators/video-abuse.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const VIDEO_ABUSE_REASON = { | ||
4 | VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ], | ||
5 | MESSAGES: { | ||
6 | 'required': 'Report reason is required.', | ||
7 | 'minlength': 'Report reason must be at least 2 characters long.', | ||
8 | 'maxlength': 'Report reason cannot be more than 300 characters long.' | ||
9 | } | ||
10 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts new file mode 100644 index 000000000..28b063f89 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts | |||
@@ -0,0 +1,48 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class VideoChannelValidatorsService { | ||
8 | readonly VIDEO_CHANNEL_DISPLAY_NAME: BuildFormValidator | ||
9 | readonly VIDEO_CHANNEL_DESCRIPTION: BuildFormValidator | ||
10 | readonly VIDEO_CHANNEL_SUPPORT: BuildFormValidator | ||
11 | |||
12 | constructor (private i18n: I18n) { | ||
13 | this.VIDEO_CHANNEL_DISPLAY_NAME = { | ||
14 | VALIDATORS: [ | ||
15 | Validators.required, | ||
16 | Validators.minLength(3), | ||
17 | Validators.maxLength(120) | ||
18 | ], | ||
19 | MESSAGES: { | ||
20 | 'required': i18n('Display name is required.'), | ||
21 | 'minlength': i18n('Display name must be at least 3 characters long.'), | ||
22 | 'maxlength': i18n('Display name cannot be more than 120 characters long.') | ||
23 | } | ||
24 | } | ||
25 | |||
26 | this.VIDEO_CHANNEL_DESCRIPTION = { | ||
27 | VALIDATORS: [ | ||
28 | Validators.minLength(3), | ||
29 | Validators.maxLength(500) | ||
30 | ], | ||
31 | MESSAGES: { | ||
32 | 'minlength': i18n('Description must be at least 3 characters long.'), | ||
33 | 'maxlength': i18n('Description cannot be more than 500 characters long.') | ||
34 | } | ||
35 | } | ||
36 | |||
37 | this.VIDEO_CHANNEL_SUPPORT = { | ||
38 | VALIDATORS: [ | ||
39 | Validators.minLength(3), | ||
40 | Validators.maxLength(500) | ||
41 | ], | ||
42 | MESSAGES: { | ||
43 | 'minlength': i18n('Support text must be at least 3 characters long.'), | ||
44 | 'maxlength': i18n('Support text cannot be more than 500 characters long.') | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video-channel.ts b/client/src/app/shared/forms/form-validators/video-channel.ts deleted file mode 100644 index 2185cdaa9..000000000 --- a/client/src/app/shared/forms/form-validators/video-channel.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const VIDEO_CHANNEL_DISPLAY_NAME = { | ||
4 | VALIDATORS: [ | ||
5 | Validators.required, | ||
6 | Validators.minLength(3), | ||
7 | Validators.maxLength(120) | ||
8 | ], | ||
9 | MESSAGES: { | ||
10 | 'required': 'Display name is required.', | ||
11 | 'minlength': 'Display name must be at least 3 characters long.', | ||
12 | 'maxlength': 'Display name cannot be more than 120 characters long.' | ||
13 | } | ||
14 | } | ||
15 | export const VIDEO_CHANNEL_DESCRIPTION = { | ||
16 | VALIDATORS: [ | ||
17 | Validators.minLength(3), | ||
18 | Validators.maxLength(500) | ||
19 | ], | ||
20 | MESSAGES: { | ||
21 | 'minlength': 'Description must be at least 3 characters long.', | ||
22 | 'maxlength': 'Description cannot be more than 500 characters long.' | ||
23 | } | ||
24 | } | ||
25 | export const VIDEO_CHANNEL_SUPPORT = { | ||
26 | VALIDATORS: [ | ||
27 | Validators.minLength(3), | ||
28 | Validators.maxLength(500) | ||
29 | ], | ||
30 | MESSAGES: { | ||
31 | 'minlength': 'Support text must be at least 3 characters long.', | ||
32 | 'maxlength': 'Support text cannot be more than 500 characters long.' | ||
33 | } | ||
34 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video-comment-validators.service.ts b/client/src/app/shared/forms/form-validators/video-comment-validators.service.ts new file mode 100644 index 000000000..45c7081ef --- /dev/null +++ b/client/src/app/shared/forms/form-validators/video-comment-validators.service.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class VideoCommentValidatorsService { | ||
8 | readonly VIDEO_COMMENT_TEXT: BuildFormValidator | ||
9 | |||
10 | constructor (private i18n: I18n) { | ||
11 | this.VIDEO_COMMENT_TEXT = { | ||
12 | VALIDATORS: [ Validators.required, Validators.minLength(1), Validators.maxLength(3000) ], | ||
13 | MESSAGES: { | ||
14 | 'required': this.i18n('Comment is required.'), | ||
15 | 'minlength': this.i18n('Comment must be at least 2 characters long.'), | ||
16 | 'maxlength': this.i18n('Comment cannot be more than 3000 characters long.') | ||
17 | } | ||
18 | } | ||
19 | } | ||
20 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video-comment.ts b/client/src/app/shared/forms/form-validators/video-comment.ts deleted file mode 100644 index 290d83195..000000000 --- a/client/src/app/shared/forms/form-validators/video-comment.ts +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const VIDEO_COMMENT_TEXT = { | ||
4 | VALIDATORS: [ Validators.required, Validators.minLength(1), Validators.maxLength(3000) ], | ||
5 | MESSAGES: { | ||
6 | 'required': 'Comment is required.', | ||
7 | 'minlength': 'Comment must be at least 2 characters long.', | ||
8 | 'maxlength': 'Comment cannot be more than 3000 characters long.' | ||
9 | } | ||
10 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video-validators.service.ts b/client/src/app/shared/forms/form-validators/video-validators.service.ts new file mode 100644 index 000000000..76fc5cf04 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/video-validators.service.ts | |||
@@ -0,0 +1,88 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
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: BuildFormValidator | ||
17 | readonly VIDEO_SUPPORT: BuildFormValidator | ||
18 | |||
19 | constructor (private i18n: I18n) { | ||
20 | |||
21 | this.VIDEO_NAME = { | ||
22 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ], | ||
23 | MESSAGES: { | ||
24 | 'required': this.i18n('Video name is required.'), | ||
25 | 'minlength': this.i18n('Video name must be at least 3 characters long.'), | ||
26 | 'maxlength': this.i18n('Video name cannot be more than 120 characters long.') | ||
27 | } | ||
28 | } | ||
29 | |||
30 | this.VIDEO_PRIVACY = { | ||
31 | VALIDATORS: [ Validators.required ], | ||
32 | MESSAGES: { | ||
33 | 'required': this.i18n('Video privacy is required.') | ||
34 | } | ||
35 | } | ||
36 | |||
37 | this.VIDEO_CATEGORY = { | ||
38 | VALIDATORS: [ ], | ||
39 | MESSAGES: {} | ||
40 | } | ||
41 | |||
42 | this.VIDEO_LICENCE = { | ||
43 | VALIDATORS: [ ], | ||
44 | MESSAGES: {} | ||
45 | } | ||
46 | |||
47 | this.VIDEO_LANGUAGE = { | ||
48 | VALIDATORS: [ ], | ||
49 | MESSAGES: {} | ||
50 | } | ||
51 | |||
52 | this.VIDEO_IMAGE = { | ||
53 | VALIDATORS: [ ], | ||
54 | MESSAGES: {} | ||
55 | } | ||
56 | |||
57 | this.VIDEO_CHANNEL = { | ||
58 | VALIDATORS: [ Validators.required ], | ||
59 | MESSAGES: { | ||
60 | 'required': this.i18n('Video channel is required.') | ||
61 | } | ||
62 | } | ||
63 | |||
64 | this.VIDEO_DESCRIPTION = { | ||
65 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(10000) ], | ||
66 | MESSAGES: { | ||
67 | 'minlength': this.i18n('Video description must be at least 3 characters long.'), | ||
68 | 'maxlength': this.i18n('Video description cannot be more than 10000 characters long.') | ||
69 | } | ||
70 | } | ||
71 | |||
72 | this.VIDEO_TAGS = { | ||
73 | VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ], | ||
74 | MESSAGES: { | ||
75 | 'minlength': this.i18n('A tag should be more than 2 characters long.'), | ||
76 | 'maxlength': this.i18n('A tag should be less than 30 characters long.') | ||
77 | } | ||
78 | } | ||
79 | |||
80 | this.VIDEO_SUPPORT = { | ||
81 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(500) ], | ||
82 | MESSAGES: { | ||
83 | 'minlength': this.i18n('Video support must be at least 3 characters long.'), | ||
84 | 'maxlength': this.i18n('Video support cannot be more than 500 characters long.') | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | } | ||
diff --git a/client/src/app/shared/forms/form-validators/video.ts b/client/src/app/shared/forms/form-validators/video.ts deleted file mode 100644 index a986243df..000000000 --- a/client/src/app/shared/forms/form-validators/video.ts +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | |||
3 | export const VIDEO_NAME = { | ||
4 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ], | ||
5 | MESSAGES: { | ||
6 | 'required': 'Video name is required.', | ||
7 | 'minlength': 'Video name must be at least 3 characters long.', | ||
8 | 'maxlength': 'Video name cannot be more than 120 characters long.' | ||
9 | } | ||
10 | } | ||
11 | |||
12 | export const VIDEO_PRIVACY = { | ||
13 | VALIDATORS: [ Validators.required ], | ||
14 | MESSAGES: { | ||
15 | 'required': 'Video privacy is required.' | ||
16 | } | ||
17 | } | ||
18 | |||
19 | export const VIDEO_CATEGORY = { | ||
20 | VALIDATORS: [ ], | ||
21 | MESSAGES: {} | ||
22 | } | ||
23 | |||
24 | export const VIDEO_LICENCE = { | ||
25 | VALIDATORS: [ ], | ||
26 | MESSAGES: {} | ||
27 | } | ||
28 | |||
29 | export const VIDEO_LANGUAGE = { | ||
30 | VALIDATORS: [ ], | ||
31 | MESSAGES: {} | ||
32 | } | ||
33 | |||
34 | export const VIDEO_IMAGE = { | ||
35 | VALIDATORS: [ ], | ||
36 | MESSAGES: {} | ||
37 | } | ||
38 | |||
39 | export const VIDEO_CHANNEL = { | ||
40 | VALIDATORS: [ Validators.required ], | ||
41 | MESSAGES: { | ||
42 | 'required': 'Video channel is required.' | ||
43 | } | ||
44 | } | ||
45 | |||
46 | export const VIDEO_DESCRIPTION = { | ||
47 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(10000) ], | ||
48 | MESSAGES: { | ||
49 | 'minlength': 'Video description must be at least 3 characters long.', | ||
50 | 'maxlength': 'Video description cannot be more than 10000 characters long.' | ||
51 | } | ||
52 | } | ||
53 | |||
54 | export const VIDEO_TAGS = { | ||
55 | VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ], | ||
56 | MESSAGES: { | ||
57 | 'minlength': 'A tag should be more than 2 characters long.', | ||
58 | 'maxlength': 'A tag should be less than 30 characters long.' | ||
59 | } | ||
60 | } | ||
61 | |||
62 | export const VIDEO_SUPPORT = { | ||
63 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(500) ], | ||
64 | MESSAGES: { | ||
65 | 'minlength': 'Video support must be at least 3 characters long.', | ||
66 | 'maxlength': 'Video support cannot be more than 500 characters long.' | ||
67 | } | ||
68 | } | ||
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 91d905ec7..b85445ef5 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts | |||
@@ -35,6 +35,12 @@ import { AccountService } from '@app/shared/account/account.service' | |||
35 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | 35 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
36 | import { I18n } from '@ngx-translate/i18n-polyfill' | 36 | import { I18n } from '@ngx-translate/i18n-polyfill' |
37 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | 37 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
38 | import { | ||
39 | CustomConfigValidatorsService, | ||
40 | LoginValidatorsService, | ||
41 | ResetPasswordValidatorsService, | ||
42 | UserValidatorsService, VideoAbuseValidatorsService, VideoChannelValidatorsService, VideoCommentValidatorsService, VideoValidatorsService | ||
43 | } from '@app/shared/forms' | ||
38 | 44 | ||
39 | @NgModule({ | 45 | @NgModule({ |
40 | imports: [ | 46 | imports: [ |
@@ -111,7 +117,17 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val | |||
111 | AccountService, | 117 | AccountService, |
112 | MarkdownService, | 118 | MarkdownService, |
113 | VideoChannelService, | 119 | VideoChannelService, |
120 | |||
114 | FormValidatorService, | 121 | FormValidatorService, |
122 | CustomConfigValidatorsService, | ||
123 | LoginValidatorsService, | ||
124 | ResetPasswordValidatorsService, | ||
125 | UserValidatorsService, | ||
126 | VideoAbuseValidatorsService, | ||
127 | VideoChannelValidatorsService, | ||
128 | VideoCommentValidatorsService, | ||
129 | VideoValidatorsService, | ||
130 | |||
115 | I18n | 131 | I18n |
116 | ] | 132 | ] |
117 | }) | 133 | }) |