Added add line for auth record editor

This commit is contained in:
Lukas Metzger 2018-04-12 12:06:14 +02:00
parent 5208c36d8e
commit 67c2f2d2a2
5 changed files with 97 additions and 2 deletions

View file

@ -1,3 +1,4 @@
import { EditAuthAddComponent } from './pages/edit-auth/edit-auth-add.component';
import { EditAuthLineComponent } from './pages/edit-auth/edit-auth-line.component';
import { RecordsOperation } from './operations/records.operations';
import { LoggedOutGuard } from './services/logged-out-guard.service';
@ -67,7 +68,8 @@ import { UsersComponent } from './pages/users/users.component';
EditUserComponent,
CreateUserComponent,
SearchComponent,
EditAuthLineComponent
EditAuthLineComponent,
EditAuthAddComponent
],
imports: [
BrowserModule,

View file

@ -0,0 +1,36 @@
<td>Add</td>
<td class="align-middle py-0">
<div class="input-group input-group-sm">
<input class="form-control" type="text" [formControl]="inputName">
<div class="input-group-append">
<span class="input-group-text">.{{ domain.name }}</span>
</div>
</div>
</td>
<td class="align-middle py-0">
<app-select [options]="gs.recordTypes" notNull [formControl]="inputType"></app-select>
</td>
<td class="align-middle py-0">
<input class="form-control form-control-sm" type="text" [formControl]="inputContent">
</td>
<td class="align-middle py-0">
<div class="form-group m-0 position-relative">
<input class="form-control form-control-sm auto-invalid" type="text" [formControl]="inputPriority">
<div class="invalid-tooltip w-200 mw-200">
Must be positive integer.
</div>
</div>
</td>
<td class="align-middle py-0">
<div class="form-group m-0 position-relative">
<input class="form-control form-control-sm auto-invalid" type="text" [formControl]="inputTtl">
<div class="invalid-tooltip w-200 mw-200">
Must be positive integer.
</div>
</div>
</td>
<td class="align-middle text-center py-0">
<span>
<button class="btn btn-primary btn-sm w-100" (click)="onSave()">Add</button>
</span>
</td>

View file

@ -0,0 +1,54 @@
import { RecordsOperation } from './../../operations/records.operations';
import { StateService } from './../../services/state.service';
import { DomainApitype } from './../../apitypes/Domain.apitype';
import { FormControl, FormBuilder, Validators } from '@angular/forms';
import { RecordApitype } from './../../apitypes/Record.apitype';
import { Component, OnInit, Input, SimpleChanges, EventEmitter, Output } from '@angular/core';
@Component({
// tslint:disable-next-line:component-selector
selector: '[app-edit-auth-add]',
templateUrl: './edit-auth-add.component.html'
})
export class EditAuthAddComponent implements OnInit {
@Input() domain: DomainApitype;
@Output() recordAdded = new EventEmitter<void>();
public inputName: FormControl;
public inputType: FormControl;
public inputContent: FormControl;
public inputPriority: FormControl;
public inputTtl: FormControl;
constructor(private fb: FormBuilder, public gs: StateService, private records: RecordsOperation) {
this.setupFormControls();
}
ngOnInit(): void {
}
public async setupFormControls() {
this.inputName = this.fb.control('');
this.inputType = this.fb.control('A');
this.inputContent = this.fb.control('');
this.inputPriority = this.fb.control('0', [Validators.required, Validators.pattern(/^[0-9]+$/)]);
this.inputTtl = this.fb.control('86400', [Validators.required, Validators.pattern(/^[0-9]+$/)]);
}
public fullName(): string {
if (this.inputName.value !== '') {
return this.inputName.value + '.' + this.domain.name;
} else {
return this.domain.name;
}
}
public async onSave() {
await this.records.create(this.domain.id, this.fullName(), this.inputType.value,
this.inputContent.value, this.inputPriority.value, this.inputTtl.value);
this.recordAdded.emit();
}
}

View file

@ -118,6 +118,9 @@
<tbody>
<tr app-edit-auth-line *ngFor="let record of recordList" [entry]="record" [domain]="domain" (recordUpdated)="updateSerial()"></tr>
</tbody>
<tfoot>
<tr app-edit-auth-add [domain]="domain" (recordAdded)="updateSerial(); loadRecords();"></tr>
</tfoot>
</table>
</div>
</div>

View file

@ -75,7 +75,7 @@ export class EditAuthComponent implements OnInit {
this.typeFilter.reset();
}
private async updateSerial() {
public async updateSerial() {
const soa = await this.domains.getSoa(this.domainId);
if (soa !== false) {
this.soaForm.controls['serial'].reset(soa.serial);