Added /domains/create/master,native
This commit is contained in:
parent
11416c682f
commit
0acd117e87
|
@ -1,3 +1,4 @@
|
|||
import { CreateAuthComponent } from './pages/create-auth/create-auth.component';
|
||||
import { CreateSlaveComponent } from './pages/create-slave/create-slave.component';
|
||||
import { EditSlaveComponent } from './pages/edit-slave/edit-slave.component';
|
||||
import { PasswordComponent } from './pages/password/password.component';
|
||||
|
@ -33,13 +34,29 @@ const routes: Routes = [
|
|||
component: EditSlaveComponent
|
||||
},
|
||||
{
|
||||
path: 'domains/auth/:domainId',
|
||||
component: EditAuthComponent
|
||||
path: 'domains/master/:domainId',
|
||||
component: EditAuthComponent,
|
||||
data: { type: 'MASTER' }
|
||||
},
|
||||
{
|
||||
path: 'domains/native/:domainId',
|
||||
component: EditAuthComponent,
|
||||
data: { type: 'NATIVE' }
|
||||
},
|
||||
{
|
||||
path: 'domains/create/slave',
|
||||
component: CreateSlaveComponent
|
||||
},
|
||||
{
|
||||
path: 'domains/create/master',
|
||||
component: CreateAuthComponent,
|
||||
data: { type: 'MASTER' }
|
||||
},
|
||||
{
|
||||
path: 'domains/create/native',
|
||||
component: CreateAuthComponent,
|
||||
data: { type: 'NATIVE' }
|
||||
},
|
||||
{
|
||||
path: 'password',
|
||||
component: PasswordComponent
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { CreateAuthComponent } from './pages/create-auth/create-auth.component';
|
||||
import { StopPropagateClickDirective } from './utils/stop-propagate-click.directive';
|
||||
import { PagesizeComponent } from './partials/pagesize/pagesize.component';
|
||||
import { PagingComponent } from './partials/paging/paging.component';
|
||||
|
@ -50,7 +51,8 @@ import { CreateSlaveComponent } from './pages/create-slave/create-slave.componen
|
|||
EditAuthComponent,
|
||||
SelectComponent,
|
||||
StopPropagateClickDirective,
|
||||
CreateSlaveComponent
|
||||
CreateSlaveComponent,
|
||||
CreateAuthComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
|
|
@ -15,7 +15,7 @@ export class ModalOptionsDatatype {
|
|||
heading: string
|
||||
body: string
|
||||
acceptText: string
|
||||
dismisText: string,
|
||||
dismisText?: string,
|
||||
acceptClass?: string
|
||||
}) {
|
||||
Object.assign(this, init);
|
||||
|
|
|
@ -76,8 +76,31 @@ export class DomainsOperation {
|
|||
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (e.response.status || e.response.status === 409) {
|
||||
throw new Error('Domain already exists!');
|
||||
} else {
|
||||
console.error(e);
|
||||
return new DomainApitype({});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async setSoa(domainId: number, primary: string, email: string, refresh: number,
|
||||
retry: number, expire: number, ttl: number): Promise<boolean> {
|
||||
try {
|
||||
await this.http.put(['/domains', domainId.toString(), 'soa'], {
|
||||
primary: primary,
|
||||
email: email,
|
||||
refresh: refresh,
|
||||
retry: retry,
|
||||
expire: expire,
|
||||
ttl: ttl
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<div class="row">
|
||||
<div class="col-12">
|
||||
<p class="font-weight-bold">Create {{ type | lowercase }} zone</p>
|
||||
</div>
|
||||
</div>
|
||||
<form autocomplete="off" [formGroup]="authForm" (ngSubmit)="onSubmit()">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 col-lg-3">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="name" />
|
||||
<div class="invalid-feedback">
|
||||
Name can not be empty.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Primary</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="primary" />
|
||||
<div class="invalid-feedback">
|
||||
Primary can not be empty.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Email</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="email" />
|
||||
<div class="invalid-feedback">
|
||||
Must be a valid email address.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-3 col-lg-2 offset-lg-1">
|
||||
<div class="form-group">
|
||||
<label>Refresh</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="refresh" />
|
||||
<div class="invalid-feedback">
|
||||
Refresh must be positive integer.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Retry</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="retry" />
|
||||
<div class="invalid-feedback">
|
||||
Retry must be positive integer.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-3 col-lg-2 offset-lg-1">
|
||||
<div class="form-group">
|
||||
<label>Expire</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="expire" />
|
||||
<div class="invalid-feedback">
|
||||
Expire must be positive integer.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>TTL</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="ttl" />
|
||||
<div class="invalid-feedback">
|
||||
TTL must be positive integer.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary float-right float-md-left" [disabled]="!authForm.valid || authForm.pristine">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
63
frontend/src/app/pages/create-auth/create-auth.component.ts
Normal file
63
frontend/src/app/pages/create-auth/create-auth.component.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
import { ModalOptionsDatatype } from './../../datatypes/modal-options.datatype';
|
||||
import { ModalService } from './../../services/modal.service';
|
||||
import { DomainsOperation } from './../../operations/domains.operations';
|
||||
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
||||
import { FormGroup, Validators, FormBuilder, AbstractControl, ValidationErrors } from '@angular/forms';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/timer';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { fromPromise } from 'rxjs/observable/fromPromise';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-slave',
|
||||
templateUrl: './create-auth.component.html',
|
||||
styleUrls: ['./create-auth.component.scss']
|
||||
})
|
||||
export class CreateAuthComponent implements OnInit {
|
||||
|
||||
public authForm: FormGroup;
|
||||
public type: string;
|
||||
|
||||
constructor(private fb: FormBuilder, private route: ActivatedRoute, private domains: DomainsOperation,
|
||||
private router: Router, private modal: ModalService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.createForm();
|
||||
|
||||
this.route.data.subscribe((data) => this.type = data.type);
|
||||
}
|
||||
|
||||
private createForm() {
|
||||
this.authForm = this.fb.group({
|
||||
name: ['', Validators.required],
|
||||
primary: ['', Validators.required],
|
||||
email: ['', Validators.email],
|
||||
refresh: ['3600', [Validators.required, Validators.pattern(/^[0-9]+$/)]],
|
||||
retry: ['900', [Validators.required, Validators.pattern(/^[0-9]+$/)]],
|
||||
expire: ['604800', [Validators.required, Validators.pattern(/^[0-9]+$/)]],
|
||||
ttl: ['86400', [Validators.required, Validators.pattern(/^[0-9]+$/)]]
|
||||
});
|
||||
}
|
||||
|
||||
public async onSubmit() {
|
||||
try {
|
||||
const v = this.authForm.value;
|
||||
|
||||
const domain = await this.domains.create(v.name, this.type);
|
||||
|
||||
await this.domains.setSoa(domain.id, v.primary, v.email, +v.refresh, +v.retry, +v.expire, +v.ttl);
|
||||
|
||||
this.router.navigate(['/domains/master', domain.id.toString()]);
|
||||
} catch (e) {
|
||||
await this.modal.showMessage(new ModalOptionsDatatype({
|
||||
heading: 'Error',
|
||||
body: e.message,
|
||||
acceptText: 'OK',
|
||||
dismisText: '',
|
||||
acceptClass: 'warning'
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
import { ModalService } from './../../services/modal.service';
|
||||
import { DomainsOperation } from './../../operations/domains.operations';
|
||||
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
||||
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ModalOptionsDatatype } from '../../datatypes/modal-options.datatype';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-slave',
|
||||
|
@ -12,7 +14,8 @@ export class CreateSlaveComponent implements OnInit {
|
|||
|
||||
public slaveForm: FormGroup;
|
||||
|
||||
constructor(private fb: FormBuilder, private route: ActivatedRoute, private domains: DomainsOperation, private router: Router) { }
|
||||
constructor(private fb: FormBuilder, private route: ActivatedRoute, private domains: DomainsOperation,
|
||||
private router: Router, private modal: ModalService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.createForm();
|
||||
|
@ -26,9 +29,20 @@ export class CreateSlaveComponent implements OnInit {
|
|||
}
|
||||
|
||||
public async onSubmit() {
|
||||
try {
|
||||
const v = this.slaveForm.value;
|
||||
|
||||
const newDomain = await this.domains.create(v.name, 'SLAVE', v.master);
|
||||
this.slaveForm.reset();
|
||||
|
||||
this.router.navigate(['/domains/slave', newDomain.id.toString()]);
|
||||
} catch (e) {
|
||||
await this.modal.showMessage(new ModalOptionsDatatype({
|
||||
heading: 'Error',
|
||||
body: e.message,
|
||||
acceptText: 'OK',
|
||||
dismisText: '',
|
||||
acceptClass: 'warning'
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
<div class="col-12 col-md-6" *ngIf="gs.isAdmin">
|
||||
<div class="btn-group btn-group-sm">
|
||||
<button disabled class="btn btn-secondary">Add domain</button>
|
||||
<button class="btn btn-secondary">MASTER</button>
|
||||
<button class="btn btn-secondary">NATIVE</button>
|
||||
<button routerLink="create/master" class="btn btn-secondary">MASTER</button>
|
||||
<button routerLink="create/native" class="btn btn-secondary">NATIVE</button>
|
||||
<button routerLink="create/slave" class="btn btn-secondary">SLAVE</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -84,8 +84,10 @@ export class DomainsComponent implements OnInit {
|
|||
public async onDomainClick(domain: DomainApitype) {
|
||||
if (domain.type === 'SLAVE') {
|
||||
this.router.navigate(['/domains/slave/', domain.id.toString()]);
|
||||
} else if (domain.type === 'MASTER' || domain.type === 'NATIVE') {
|
||||
this.router.navigate(['/domains/auth/', domain.id.toString()]);
|
||||
} else if (domain.type === 'MASTER') {
|
||||
this.router.navigate(['/domains/master/', domain.id.toString()]);
|
||||
} else if (domain.type === 'NATIVE') {
|
||||
this.router.navigate(['/domains/native/', domain.id.toString()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<p>
|
||||
edit-auth works!
|
||||
Zone type: {{ type }}
|
||||
</p>
|
|
@ -1,3 +1,4 @@
|
|||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
|
@ -7,9 +8,12 @@ import { Component, OnInit } from '@angular/core';
|
|||
})
|
||||
export class EditAuthComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
public type: string;
|
||||
|
||||
constructor(private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data) => this.type = data.type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<p>{{options.body}}</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" (click)="onDismis()">{{options.dismisText}}</button>
|
||||
<button type="button" *ngIf="options.dismisText.length > 0" class="btn btn-secondary" (click)="onDismis()">{{options.dismisText}}</button>
|
||||
<button type="button" class="btn" [ngClass]="'btn-' + options.acceptClass" (click)="onAccept()">{{options.acceptText}}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue