From 67ed6552b831df66713bac9e672738796128d33f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jun 2020 14:10:17 +0200 Subject: Reorganize client shared modules --- .../shared/batch-domains-modal.component.html | 43 -------------- .../shared/batch-domains-modal.component.scss | 3 - .../config/shared/batch-domains-modal.component.ts | 54 ----------------- .../shared/batch-domains-validators.service.ts | 68 ---------------------- .../src/app/+admin/config/shared/config.service.ts | 6 +- 5 files changed, 3 insertions(+), 171 deletions(-) delete mode 100644 client/src/app/+admin/config/shared/batch-domains-modal.component.html delete mode 100644 client/src/app/+admin/config/shared/batch-domains-modal.component.scss delete mode 100644 client/src/app/+admin/config/shared/batch-domains-modal.component.ts delete mode 100644 client/src/app/+admin/config/shared/batch-domains-validators.service.ts (limited to 'client/src/app/+admin/config/shared') diff --git a/client/src/app/+admin/config/shared/batch-domains-modal.component.html b/client/src/app/+admin/config/shared/batch-domains-modal.component.html deleted file mode 100644 index 1b85c8f48..000000000 --- a/client/src/app/+admin/config/shared/batch-domains-modal.component.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - diff --git a/client/src/app/+admin/config/shared/batch-domains-modal.component.scss b/client/src/app/+admin/config/shared/batch-domains-modal.component.scss deleted file mode 100644 index 9621a566f..000000000 --- a/client/src/app/+admin/config/shared/batch-domains-modal.component.scss +++ /dev/null @@ -1,3 +0,0 @@ -textarea { - height: 200px; -} diff --git a/client/src/app/+admin/config/shared/batch-domains-modal.component.ts b/client/src/app/+admin/config/shared/batch-domains-modal.component.ts deleted file mode 100644 index 620f2726b..000000000 --- a/client/src/app/+admin/config/shared/batch-domains-modal.component.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Component, OnInit, ViewChild, Input, Output, EventEmitter } from '@angular/core' -import { I18n } from '@ngx-translate/i18n-polyfill' -import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' -import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' -import { FormReactive } from '@app/shared/forms' -import { BatchDomainsValidatorsService } from './batch-domains-validators.service' - -@Component({ - selector: 'my-batch-domains-modal', - templateUrl: './batch-domains-modal.component.html', - styleUrls: [ './batch-domains-modal.component.scss' ] -}) -export class BatchDomainsModalComponent extends FormReactive implements OnInit { - @ViewChild('modal', { static: true }) modal: NgbModal - @Input() placeholder = 'example.com' - @Input() action: string - @Output() domains = new EventEmitter() - - private openedModal: NgbModalRef - - constructor ( - protected formValidatorService: FormValidatorService, - private modalService: NgbModal, - private batchDomainsValidatorsService: BatchDomainsValidatorsService, - private i18n: I18n - ) { - super() - } - - ngOnInit () { - if (!this.action) this.action = this.i18n('Process domains') - - this.buildForm({ - domains: this.batchDomainsValidatorsService.DOMAINS - }) - } - - openModal () { - this.openedModal = this.modalService.open(this.modal, { centered: true }) - } - - hide () { - this.openedModal.close() - } - - submit () { - this.domains.emit( - this.batchDomainsValidatorsService.getNotEmptyHosts(this.form.controls['domains'].value) - ) - this.form.reset() - this.hide() - } -} diff --git a/client/src/app/+admin/config/shared/batch-domains-validators.service.ts b/client/src/app/+admin/config/shared/batch-domains-validators.service.ts deleted file mode 100644 index 46fa6514d..000000000 --- a/client/src/app/+admin/config/shared/batch-domains-validators.service.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { I18n } from '@ngx-translate/i18n-polyfill' -import { Validators, ValidatorFn } from '@angular/forms' -import { Injectable } from '@angular/core' -import { BuildFormValidator, validateHost } from '@app/shared/forms/form-validators' - -@Injectable() -export class BatchDomainsValidatorsService { - readonly DOMAINS: BuildFormValidator - - constructor (private i18n: I18n) { - this.DOMAINS = { - VALIDATORS: [ Validators.required, this.validDomains, this.isHostsUnique ], - MESSAGES: { - 'required': this.i18n('Domain is required.'), - 'validDomains': this.i18n('Domains entered are invalid.'), - 'uniqueDomains': this.i18n('Domains entered contain duplicates.') - } - } - } - - getNotEmptyHosts (hosts: string) { - return hosts - .split('\n') - .filter((host: string) => host && host.length !== 0) // Eject empty hosts - } - - private validDomains: ValidatorFn = (control) => { - if (!control.value) return null - - const newHostsErrors = [] - const hosts = this.getNotEmptyHosts(control.value) - - for (const host of hosts) { - if (validateHost(host) === false) { - newHostsErrors.push(this.i18n('{{host}} is not valid', { host })) - } - } - - /* Is not valid. */ - if (newHostsErrors.length !== 0) { - return { - 'validDomains': { - reason: 'invalid', - value: newHostsErrors.join('. ') + '.' - } - } - } - - /* Is valid. */ - return null - } - - private isHostsUnique: ValidatorFn = (control) => { - if (!control.value) return null - - const hosts = this.getNotEmptyHosts(control.value) - - if (hosts.every((host: string) => hosts.indexOf(host) === hosts.lastIndexOf(host))) { - return null - } else { - return { - 'uniqueDomains': { - reason: 'invalid' - } - } - } - } -} diff --git a/client/src/app/+admin/config/shared/config.service.ts b/client/src/app/+admin/config/shared/config.service.ts index 874b8094d..f182946b8 100644 --- a/client/src/app/+admin/config/shared/config.service.ts +++ b/client/src/app/+admin/config/shared/config.service.ts @@ -1,10 +1,10 @@ import { catchError } from 'rxjs/operators' import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' -import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' -import { environment } from '../../../../environments/environment' -import { RestExtractor } from '../../../shared' +import { RestExtractor } from '@app/core' import { I18n } from '@ngx-translate/i18n-polyfill' +import { CustomConfig } from '@shared/models' +import { environment } from '../../../../environments/environment' @Injectable() export class ConfigService { -- cgit v1.2.3