scan condition restore last

This commit is contained in:
insanity 2018-09-10 18:19:07 +09:00
parent 16b37e5061
commit 5b3ad22280
2 changed files with 45 additions and 8 deletions

View File

@ -1,4 +1,4 @@
<of-p-dropdownPanel #panel [style]="{'width':'400px'}" [headerStyle]="{'width':'300px'}" [blockTarget]="blockTarget" (cancel)="setDefault()"> <of-p-dropdownPanel #panel [style]="{'width':'400px'}" [headerStyle]="{'width':'300px'}" [blockTarget]="blockTarget" (cancel)="cancel()">
<p-header class="toolbar-button"> <p-header class="toolbar-button">
<button _ngcontent-c1="" class="button-component" type="button"> <button _ngcontent-c1="" class="button-component" type="button">
<!-- <svg _ngcontent-c1="" aria-hidden="true" class="octicon icon" version="1.1" viewBox="0 0 10 16" width="16px" height="16px"> <!-- <svg _ngcontent-c1="" aria-hidden="true" class="octicon icon" version="1.1" viewBox="0 0 10 16" width="16px" height="16px">
@ -87,7 +87,7 @@
</p-panel> </p-panel>
--> -->
<div class="ui-g-12"> <div class="ui-g-12">
<button type="button" pButton label="Reset" style="float: right;" (click)="setDefault()"></button> <button type="button" pButton label="Reset" style="float: right;" (click)="setDefault($event)"></button>
<button type="button" pButton label="Apply" style="float: right;" (click)="done()" [disabled]="portErrMsg || ipErrMsg"></button> <button type="button" pButton label="Apply" style="float: right;" (click)="done()" [disabled]="portErrMsg || ipErrMsg"></button>
</div> </div>
<!-- <p-footer> <!-- <p-footer>

View File

@ -29,11 +29,10 @@ export class ScannerSettingDropdownComponent implements OnInit {
includePortType: MetaPortTypeEnum[]; includePortType: MetaPortTypeEnum[];
firstPort: string; firstPort: string;
lastPort: string; lastPort: string;
ipErrMsg: string; ipErrMsg: string;
portErrMsg: string; portErrMsg: string;
zone: Zone; zone: Zone;
lastCondition: Condition = null;
constructor( constructor(
private discoveryConfigService: DiscoveryConfigService private discoveryConfigService: DiscoveryConfigService
@ -72,13 +71,13 @@ export class ScannerSettingDropdownComponent implements OnInit {
switch (this.ipType) { switch (this.ipType) {
case 'V4': case 'V4':
if (!(/^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$/.test(value))) { if (!(/^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$/.test(value))) {
this.ipErrMsg = 'INVALID_IP_FORMAT'; this.ipErrMsg = 'Invalid IP format.';
return; return;
} }
let from = idx === 0 ? value : this.firstIP; let from = idx === 0 ? value : this.firstIP;
let to = idx === 1 ? value : this.lastIP; let to = idx === 1 ? value : this.lastIP;
if (this.ipToNum(from) > this.ipToNum(to)) { if (this.ipToNum(from) > this.ipToNum(to)) {
this.ipErrMsg = 'INVALID_IP_RANGE'; this.ipErrMsg = 'Invalid IP range.';
return; return;
} }
break; break;
@ -106,7 +105,7 @@ export class ScannerSettingDropdownComponent implements OnInit {
let from = Number(fromStr); let from = Number(fromStr);
let to = Number(toStr) let to = Number(toStr)
if (from === NaN || to === NaN) { if (from === NaN || to === NaN) {
this.portErrMsg = 'INVALID_PORT_TYPE'; this.portErrMsg = 'Invalid Port Type.';
return; return;
} }
if (from <= 0) { if (from <= 0) {
@ -118,7 +117,7 @@ export class ScannerSettingDropdownComponent implements OnInit {
return; return;
} }
if (from > to) { if (from > to) {
this.portErrMsg = 'INVALID_PORT_RANGE'; this.portErrMsg = 'Invalid Port range.';
return; return;
} }
} }
@ -136,9 +135,38 @@ export class ScannerSettingDropdownComponent implements OnInit {
done() { done() {
// TODO: re-validation // TODO: re-validation
this.saveLastCondition();
this.setSummary(); this.setSummary();
this.panel.hide(); this.panel.hide();
}
cancel() {
if (null === this.lastCondition) {
this.setDefault();
} else {
this.restore();
}
}
saveLastCondition() {
var c: Condition = {
ipType: this.ipType,
firstIP: this.firstIP,
lastIP: this.lastIP,
includePortType: this.includePortType,
firstPort: this.firstPort,
lastPort: this.lastPort,
}
this.lastCondition = c;
}
restore() {
this.ipType = this.lastCondition.ipType;
this.firstIP = this.lastCondition.firstIP;
this.lastIP = this.lastCondition.lastIP;
this.includePortType = this.lastCondition.includePortType;
this.firstPort = this.lastCondition.firstPort;
this.lastPort = this.lastCondition.lastPort;
} }
setSummary(): void { setSummary(): void {
@ -165,3 +193,12 @@ export class ScannerSettingDropdownComponent implements OnInit {
} }
} }
class Condition {
ipType: MetaIPTypeEnum;
firstIP: string;
lastIP: string;
includePortType: MetaPortTypeEnum[];
firstPort: string;
lastPort: string;
}