Added record deletion and minor behavioural improvements

This commit is contained in:
Lukas Metzger 2018-04-12 12:23:14 +02:00
parent 67c2f2d2a2
commit b083024ab2
7 changed files with 56 additions and 17 deletions

View File

@ -49,11 +49,12 @@ export class DomainsComponent implements OnInit {
const res = await this.domains.getList(this.pageRequested, this.gs.pageSize, searchStr, sortStr, typeFilter);
this.pagingInfo = res.paging;
this.domainList = res.results;
if (res.paging.total < this.pageRequested && res.paging.total > 1) {
if (res.paging.total < this.pageRequested) {
this.pageRequested = Math.max(1, res.paging.total);
await this.loadData();
} else {
this.pagingInfo = res.paging;
this.domainList = res.results;
}
}

View File

@ -31,10 +31,19 @@ export class EditAuthAddComponent implements OnInit {
public async setupFormControls() {
this.inputName = this.fb.control('');
this.inputType = this.fb.control('A');
this.inputType = this.fb.control('');
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]+$/)]);
this.inputPriority = this.fb.control('', [Validators.required, Validators.pattern(/^[0-9]+$/)]);
this.inputTtl = this.fb.control('', [Validators.required, Validators.pattern(/^[0-9]+$/)]);
this.resetForm();
}
private resetForm() {
this.inputName.reset('');
this.inputType.reset('A');
this.inputContent.reset('');
this.inputPriority.reset('0');
this.inputTtl.reset('86400');
}
public fullName(): string {
@ -50,5 +59,7 @@ export class EditAuthAddComponent implements OnInit {
this.inputContent.value, this.inputPriority.value, this.inputTtl.value);
this.recordAdded.emit();
this.resetForm();
}
}

View File

@ -39,8 +39,8 @@
<td class="align-middle text-center py-0">
<span *ngIf="!editMode">
<app-fa-icon class="cursor-pointer mx-1" icon="edit" appStopPropagateClick (click)="onEditClick()"></app-fa-icon>
<app-fa-icon class="cursor-pointer mx-1" icon="trash" appStopPropagateClick></app-fa-icon>
<app-fa-icon class="cursor-pointer mx-1" icon="key" appStopPropagateClick></app-fa-icon>
<app-fa-icon class="cursor-pointer mx-1" icon="trash" appStopPropagateClick (click)="onDeleteClick()"></app-fa-icon>
<app-fa-icon class="cursor-pointer mx-1" icon="key" appStopPropagateClick (click)="onRemoteClick()"></app-fa-icon>
</span>
<span *ngIf="editMode">
<button class="btn btn-primary btn-sm w-100" (click)="onSave()">Save</button>

View File

@ -1,3 +1,5 @@
import { ModalOptionsDatatype } from './../../datatypes/modal-options.datatype';
import { ModalService } from './../../services/modal.service';
import { RecordsOperation } from './../../operations/records.operations';
import { StateService } from './../../services/state.service';
import { DomainApitype } from './../../apitypes/Domain.apitype';
@ -16,6 +18,7 @@ export class EditAuthLineComponent implements OnInit, OnChanges {
@Input() domain: DomainApitype;
@Output() recordUpdated = new EventEmitter<void>();
@Output() recordDeleted = new EventEmitter<number>();
public editMode = false;
@ -25,7 +28,7 @@ export class EditAuthLineComponent implements OnInit, OnChanges {
public inputPriority: FormControl;
public inputTtl: FormControl;
constructor(private fb: FormBuilder, public gs: StateService, private records: RecordsOperation) {
constructor(private fb: FormBuilder, public gs: StateService, private records: RecordsOperation, private modal: ModalService) {
this.setupFormControls();
}
@ -78,4 +81,26 @@ export class EditAuthLineComponent implements OnInit, OnChanges {
this.editMode = false;
this.recordUpdated.emit();
}
public async onDeleteClick() {
try {
await this.modal.showMessage(new ModalOptionsDatatype({
heading: 'Confirm deletion',
body: 'Are you shure you want to delete the ' + this.inputType.value +
' record ' + this.fullName() + ' with content ' + this.inputContent.value + '?',
acceptText: 'Delete',
dismisText: 'Cancel',
acceptClass: 'danger'
}));
await this.records.delete(this.entry.id);
this.recordDeleted.emit(this.entry.id);
} catch (e) {
}
}
public async onRemoteClick() {
}
}

View File

@ -116,7 +116,8 @@
</tr>
</thead>
<tbody>
<tr app-edit-auth-line *ngFor="let record of recordList" [entry]="record" [domain]="domain" (recordUpdated)="updateSerial()"></tr>
<tr app-edit-auth-line *ngFor="let record of recordList" [entry]="record" [domain]="domain" (recordUpdated)="updateSerial()"
(recordDeleted)="updateSerial(); loadRecords();"></tr>
</tbody>
<tfoot>
<tr app-edit-auth-add [domain]="domain" (recordAdded)="updateSerial(); loadRecords();"></tr>

View File

@ -119,11 +119,12 @@ export class EditAuthComponent implements OnInit {
const res = await this.records.getListForDomain(this.domainId, this.pageRequested,
this.gs.pageSize, queryName, typeFilter, queryContent, sortStr);
this.pagingInfo = res.paging;
this.recordList = res.results;
if (res.paging.total < this.pageRequested && res.paging.total > 1) {
if (res.paging.total < this.pageRequested) {
this.pageRequested = Math.max(1, res.paging.total);
await this.loadRecords();
} else {
this.pagingInfo = res.paging;
this.recordList = res.results;
}
}

View File

@ -49,12 +49,12 @@ export class UsersComponent implements OnInit {
const res = await this.users.getList(this.pageRequested, this.gs.pageSize, searchStr, sortStr, typeFilter);
this.pagingInfo = res.paging;
this.userList = res.results;
if (res.paging.total < this.pageRequested && res.paging.total > 1) {
if (res.paging.total < this.pageRequested) {
this.pageRequested = Math.max(1, res.paging.total);
await this.loadData();
} else {
this.pagingInfo = res.paging;
this.userList = res.results;
}
}