diff options
Diffstat (limited to 'client/src/app/shared/forms/form-validators/custom-config-validators.service.ts')
-rw-r--r-- | client/src/app/shared/forms/form-validators/custom-config-validators.service.ts | 72 |
1 files changed, 72 insertions, 0 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 | } | ||