From b083024ab257a136224609930566862aa4e5b401 Mon Sep 17 00:00:00 2001 From: Lukas Metzger Date: Thu, 12 Apr 2018 12:23:14 +0200 Subject: [PATCH] Added record deletion and minor behavioural improvements --- .../app/pages/domains/domains.component.ts | 7 ++--- .../edit-auth/edit-auth-add.component.ts | 17 +++++++++--- .../edit-auth/edit-auth-line.component.html | 4 +-- .../edit-auth/edit-auth-line.component.ts | 27 ++++++++++++++++++- .../pages/edit-auth/edit-auth.component.html | 3 ++- .../pages/edit-auth/edit-auth.component.ts | 7 ++--- .../src/app/pages/users/users.component.ts | 8 +++--- 7 files changed, 56 insertions(+), 17 deletions(-) diff --git a/frontend/src/app/pages/domains/domains.component.ts b/frontend/src/app/pages/domains/domains.component.ts index 1708e40..6f879a6 100644 --- a/frontend/src/app/pages/domains/domains.component.ts +++ b/frontend/src/app/pages/domains/domains.component.ts @@ -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; } } diff --git a/frontend/src/app/pages/edit-auth/edit-auth-add.component.ts b/frontend/src/app/pages/edit-auth/edit-auth-add.component.ts index 3d066fe..9dcb732 100644 --- a/frontend/src/app/pages/edit-auth/edit-auth-add.component.ts +++ b/frontend/src/app/pages/edit-auth/edit-auth-add.component.ts @@ -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(); } } diff --git a/frontend/src/app/pages/edit-auth/edit-auth-line.component.html b/frontend/src/app/pages/edit-auth/edit-auth-line.component.html index caca792..1737e1f 100644 --- a/frontend/src/app/pages/edit-auth/edit-auth-line.component.html +++ b/frontend/src/app/pages/edit-auth/edit-auth-line.component.html @@ -39,8 +39,8 @@ - - + + diff --git a/frontend/src/app/pages/edit-auth/edit-auth-line.component.ts b/frontend/src/app/pages/edit-auth/edit-auth-line.component.ts index 444c3d7..0b80064 100644 --- a/frontend/src/app/pages/edit-auth/edit-auth-line.component.ts +++ b/frontend/src/app/pages/edit-auth/edit-auth-line.component.ts @@ -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(); + @Output() recordDeleted = new EventEmitter(); 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() { + + } } 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 65cca2f..3cf6b77 100644 --- a/frontend/src/app/pages/edit-auth/edit-auth.component.html +++ b/frontend/src/app/pages/edit-auth/edit-auth.component.html @@ -116,7 +116,8 @@ - + 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 11cda5c..20b50c1 100644 --- a/frontend/src/app/pages/edit-auth/edit-auth.component.ts +++ b/frontend/src/app/pages/edit-auth/edit-auth.component.ts @@ -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; } } diff --git a/frontend/src/app/pages/users/users.component.ts b/frontend/src/app/pages/users/users.component.ts index e245b31..af1b1d5 100644 --- a/frontend/src/app/pages/users/users.component.ts +++ b/frontend/src/app/pages/users/users.component.ts @@ -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; } }