aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/forms/form-validators/custom-config-validators.service.ts
blob: abcbca817ac52522baaddb0e63649826810c644c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Validators } from '@angular/forms'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { BuildFormValidator } from '@app/shared'
import { Injectable } from '@angular/core'

@Injectable()
export class CustomConfigValidatorsService {
  readonly INSTANCE_NAME: BuildFormValidator
  readonly INSTANCE_SHORT_DESCRIPTION: BuildFormValidator
  readonly SERVICES_TWITTER_USERNAME: BuildFormValidator
  readonly CACHE_PREVIEWS_SIZE: BuildFormValidator
  readonly CACHE_CAPTIONS_SIZE: BuildFormValidator
  readonly SIGNUP_LIMIT: BuildFormValidator
  readonly ADMIN_EMAIL: BuildFormValidator
  readonly TRANSCODING_THREADS: BuildFormValidator
  readonly INDEX_URL: BuildFormValidator

  constructor (private i18n: I18n) {
    this.INSTANCE_NAME = {
      VALIDATORS: [ Validators.required ],
      MESSAGES: {
        'required': this.i18n('Instance name is required.')
      }
    }

    this.INSTANCE_SHORT_DESCRIPTION = {
      VALIDATORS: [ Validators.max(250) ],
      MESSAGES: {
        'max': this.i18n('Short description should not be longer than 250 characters.')
      }
    }

    this.SERVICES_TWITTER_USERNAME = {
      VALIDATORS: [ Validators.required ],
      MESSAGES: {
        'required': this.i18n('Twitter username is required.')
      }
    }

    this.CACHE_PREVIEWS_SIZE = {
      VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ],
      MESSAGES: {
        'required': this.i18n('Previews cache size is required.'),
        'min': this.i18n('Previews cache size must be greater than 1.'),
        'pattern': this.i18n('Previews cache size must be a number.')
      }
    }

    this.CACHE_CAPTIONS_SIZE = {
      VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ],
      MESSAGES: {
        'required': this.i18n('Captions cache size is required.'),
        'min': this.i18n('Captions cache size must be greater than 1.'),
        'pattern': this.i18n('Captions cache size must be a number.')
      }
    }

    this.SIGNUP_LIMIT = {
      VALIDATORS: [ Validators.required, Validators.min(-1), Validators.pattern('-?[0-9]+') ],
      MESSAGES: {
        'required': this.i18n('Signup limit is required.'),
        'min': this.i18n('Signup limit must be greater than 1.'),
        'pattern': this.i18n('Signup limit must be a number.')
      }
    }

    this.ADMIN_EMAIL = {
      VALIDATORS: [ Validators.required, Validators.email ],
      MESSAGES: {
        'required': this.i18n('Admin email is required.'),
        'email': this.i18n('Admin email must be valid.')
      }
    }

    this.TRANSCODING_THREADS = {
      VALIDATORS: [ Validators.required, Validators.min(0) ],
      MESSAGES: {
        'required': this.i18n('Transcoding threads is required.'),
        'min': this.i18n('Transcoding threads must be greater or equal to 0.')
      }
    }

    this.INDEX_URL = {
      VALIDATORS: [ Validators.pattern(/^https:\/\//) ],
      MESSAGES: {
        'pattern': this.i18n('Index URL should be a URL')
      }
    }
  }
}