diff --git a/frontend/src/app/apitypes/Soa.apitype.ts b/frontend/src/app/apitypes/Soa.apitype.ts new file mode 100644 index 0000000..e6d5b4a --- /dev/null +++ b/frontend/src/app/apitypes/Soa.apitype.ts @@ -0,0 +1,20 @@ +export class SoaApitype { + + public primary = ''; + + public email = ''; + + public refresh = 0; + + public retry = 0; + + public expire = 0; + + public ttl = 0; + + public serial = 0; + + constructor(init: Object) { + Object.assign(this, init); + } +} diff --git a/frontend/src/app/operations/domains.operations.ts b/frontend/src/app/operations/domains.operations.ts index 7c5b9f1..6b849d0 100644 --- a/frontend/src/app/operations/domains.operations.ts +++ b/frontend/src/app/operations/domains.operations.ts @@ -1,3 +1,4 @@ +import { SoaApitype } from './../apitypes/Soa.apitype'; import { SearchService, SearchServiceResult } from './../utils/search-service.interface'; import { DomainApitype } from './../apitypes/Domain.apitype'; import { ListApitype } from './../apitypes/List.apitype'; @@ -110,4 +111,13 @@ export class DomainsOperation implements SearchService { return false; } } + + public async getSoa(domainId: number) { + try { + return new SoaApitype(await this.http.get(['/domains', domainId.toString(), 'soa'])); + } catch (e) { + console.error(e); + return false; + } + } } diff --git a/frontend/src/app/pages/edit-auth/edit-auth.component.html b/frontend/src/app/pages/edit-auth/edit-auth.component.html index caf60e8..0c6e5e3 100644 --- a/frontend/src/app/pages/edit-auth/edit-auth.component.html +++ b/frontend/src/app/pages/edit-auth/edit-auth.component.html @@ -1,3 +1,70 @@ -

- Zone type: {{ type }} -

\ No newline at end of file +
+
+

Update SOA data for {{ domainName }}

+
+
+
+
+
+
+ + +
+ Primary can not be empty. +
+
+ +
+ + +
+ Must be a valid email address. +
+
+
+
+
+ + +
+ Refresh must be positive integer. +
+
+ +
+ + +
+ Retry must be positive integer. +
+
+
+
+
+ + +
+ Expire must be positive integer. +
+
+ +
+ + +
+ TTL must be positive integer. +
+
+
+
+
+ + +
+
+ +
+ +
+
+
\ No newline at end of file diff --git a/frontend/src/app/pages/edit-auth/edit-auth.component.ts b/frontend/src/app/pages/edit-auth/edit-auth.component.ts index 6eeff02..8edb7cc 100644 --- a/frontend/src/app/pages/edit-auth/edit-auth.component.ts +++ b/frontend/src/app/pages/edit-auth/edit-auth.component.ts @@ -1,4 +1,8 @@ -import { ActivatedRoute } from '@angular/router'; +import { DomainApitype } from './../../apitypes/Domain.apitype'; +import { SoaApitype } from './../../apitypes/Soa.apitype'; +import { DomainsOperation } from './../../operations/domains.operations'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { ActivatedRoute, ParamMap } from '@angular/router'; import { Component, OnInit } from '@angular/core'; @Component({ @@ -7,13 +11,68 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./edit-auth.component.scss'] }) export class EditAuthComponent implements OnInit { + public soaForm: FormGroup; - public type: string; + public type = ''; - constructor(private route: ActivatedRoute) { } + public domainName = ''; + + public domainId = 0; + + constructor(private route: ActivatedRoute, private fb: FormBuilder, private domains: DomainsOperation) { } ngOnInit() { + this.createForm(); + this.route.data.subscribe((data) => this.type = data.type); + + this.route.paramMap.subscribe((params) => this.initControl(params)); + } + + private async initControl(params: ParamMap) { + this.domainId = +params.get('domainId'); + + this.domains.getSingle(this.domainId).then((domain: DomainApitype) => { + this.domainName = domain.name; + }); + + this.domains.getSoa(this.domainId).then((soa: SoaApitype) => { + this.soaForm.reset({ + primary: soa.primary, + email: soa.email, + refresh: soa.refresh, + retry: soa.retry, + expire: soa.expire, + ttl: soa.ttl, + serial: soa.serial + }); + }); + } + + private async updateSerial() { + const soa = await this.domains.getSoa(this.domainId); + if (soa !== false) { + this.soaForm.controls['serial'].reset(soa.serial); + } + } + + private createForm() { + this.soaForm = this.fb.group({ + primary: ['', Validators.required], + email: ['', Validators.email], + refresh: ['', [Validators.required, Validators.pattern(/^[0-9]+$/)]], + retry: ['', [Validators.required, Validators.pattern(/^[0-9]+$/)]], + expire: ['', [Validators.required, Validators.pattern(/^[0-9]+$/)]], + ttl: ['', [Validators.required, Validators.pattern(/^[0-9]+$/)]], + serial: [''] + }); + } + + public async onSubmit() { + const v = this.soaForm.value; + await this.domains.setSoa(this.domainId, v.primary, v.email, v.refresh, v.retry, v.expire, v.ttl); + this.soaForm.markAsPristine(); + await this.updateSerial(); } }