loadChildren

This commit is contained in:
insanity 2018-06-05 18:32:36 +09:00
parent a415181e26
commit 4443f075d8
2 changed files with 50 additions and 51 deletions

View File

@ -15,13 +15,14 @@
<!-- HOST node template --> <!-- HOST node template -->
<ng-template let-node pTemplate="HOST"> <ng-template let-node pTemplate="HOST">
<div @discoveryResultAnim> <div @discoveryResultAnim>
<div *ngIf="checkHighligtHost(node.label) else unhighlightHost"> <div *ngIf="checkHighligt(node.label) else unhighlightHost">
<p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px'}" <p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px'}"
(onChange)="onTargetSelect($event, node)"></p-toggleButton> (onChange)="onTargetSelect($event, node)"></p-toggleButton>
</div> </div>
<ng-template #unhighlightHost> <ng-template #unhighlightHost>
<div style="opacity: 0.2">{{node.label}}</div> <p-toggleButton onLabel="{{node.label}}" offLabel="{{node.label}}" onIcon="fa-check" offIcon="fa-square" [style]="{'width':'200px', 'opacity': '0.2'}"
(onChange)="onTargetSelect($event, node)"></p-toggleButton>
</ng-template> </ng-template>
</div> </div>
</ng-template> </ng-template>
@ -29,20 +30,21 @@
<!-- SERVICE node template --> <!-- SERVICE node template -->
<ng-template let-node pTemplate="SERVICE"> <ng-template let-node pTemplate="SERVICE">
<div @discoveryResultAnim> <div @discoveryResultAnim>
<div *ngIf="checkHighligtService(node.data.name) else unhighlightServ"> <div *ngIf="checkHighligt(node.data.name) else unhighlightServ">
<p-toggleButton onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}" <p-toggleButton onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}"
onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px'}" (onChange)="onTargetSelect($event, node)"></p-toggleButton> onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px'}" (onChange)="onTargetSelect($event, node.data.target)"></p-toggleButton>
</div> </div>
<ng-template #unhighlightServ> <ng-template #unhighlightServ>
<div style="opacity: 0.2">{{node.label}} {{node.data.portType}}</div> <p-toggleButton onLabel="{{node.label}} {{node.data.portType}}" offLabel="{{node.label}} {{node.data.portType}} {{node.data.portNumber}}"
onIcon="fa-check" offIcon="fa-square" [style]="{'width':'300px', 'opacity': '0.2'}" (onChange)="onTargetSelect($event, node.data.target)"></p-toggleButton>
</ng-template> </ng-template>
</div> </div>
</ng-template> </ng-template>
</p-tree> </p-tree>
<button class="ui-button-width-fit" [disabled]="selectedItems.length === 0" <button class="ui-button-width-fit" [disabled]="selectedItems.length === 0" type="button" label="Save" icon="ui-icon-close"
type="button" label="Save" icon="ui-icon-close" pButton (click)="saveTargets()"></button> pButton (click)="saveTargets()"></button>
</p-panel> </p-panel>

View File

@ -36,8 +36,8 @@ export class SearchResultComponent implements OnInit, OnChanges {
selectedItems: TreeNode[] = []; selectedItems: TreeNode[] = [];
msgs: Message[]; msgs: Message[];
infraHosts = []; discoveredHosts: Host[] = [];
infraServices = []; discoveredServices: Service[] = [];
constructor( constructor(
) { ) {
@ -56,7 +56,7 @@ export class SearchResultComponent implements OnInit, OnChanges {
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
if (changes['finished'] && changes['finished'].currentValue === true) { if (changes['finished'] && changes['finished'].currentValue === true) {
// this.saveInfras(); this.saveInfras();
// TODO: Comes after save infra // TODO: Comes after save infra
this.msgs = []; this.msgs = [];
this.msgs.push({ this.msgs.push({
@ -68,6 +68,7 @@ export class SearchResultComponent implements OnInit, OnChanges {
addHost(host: Host) { addHost(host: Host) {
this.discoveredHosts.push(host);
const idx = this.findHostIndex(host); const idx = this.findHostIndex(host);
this.hostNode.splice(idx, 0, { this.hostNode.splice(idx, 0, {
type: 'HOST', type: 'HOST',
@ -77,7 +78,7 @@ export class SearchResultComponent implements OnInit, OnChanges {
ipv6: host.ipv6, ipv6: host.ipv6,
mac: host.mac, mac: host.mac,
openPorts: [], openPorts: [],
zone: host.zone, target: host
}, },
expanded: true, expanded: true,
children: [] children: []
@ -85,6 +86,7 @@ export class SearchResultComponent implements OnInit, OnChanges {
} }
addService(service: Service) { addService(service: Service) {
this.discoveredServices.push(service);
const targetHostNode = this.findHostNodeByService(service); const targetHostNode = this.findHostNodeByService(service);
const idx = this.findServiceIndex(targetHostNode.children, service); const idx = this.findServiceIndex(targetHostNode.children, service);
targetHostNode.children.splice(idx, 0, { targetHostNode.children.splice(idx, 0, {
@ -94,7 +96,7 @@ export class SearchResultComponent implements OnInit, OnChanges {
name: service.serviceName, name: service.serviceName,
portType: service.port.portType, portType: service.port.portType,
portNumber: service.port.portNumber, portNumber: service.port.portNumber,
host: service.port.host target: service
}, },
}); });
} }
@ -160,26 +162,19 @@ export class SearchResultComponent implements OnInit, OnChanges {
}); });
} }
checkHighligtHost(label: string) { checkHighligt(label: string) {
if (!this.filterWord) { let highlight = true;
return true; if (this.filterWord && (label.toUpperCase().indexOf(this.filterWord.toUpperCase()) < 0)) {
highlight = false;
} }
if (this.filterWord && if (this.filterServices[label] === false) {
label.toUpperCase().indexOf(this.filterWord.toUpperCase()) > 0) { highlight = false;
return true;
} }
return false; return highlight;
} }
checkHighligtService(name: string) { saveInfras() {
if (this.filterServices && (this.filterServices[name])) { this.discoveredHosts.forEach(host => {
return true;
}
return false;
}
saveInfras(host: Host, service: Service) {
// Host
const infraHost: InfraHost = { const infraHost: InfraHost = {
probe: this.probeHost.probe, probe: this.probeHost.probe,
infraType: { infraType: {
@ -190,8 +185,9 @@ export class SearchResultComponent implements OnInit, OnChanges {
ipv6: host.ipv6, ipv6: host.ipv6,
mac: host.mac, mac: host.mac,
}; };
});
// Service this.discoveredServices.forEach(service => {
const infraService: InfraService = { const infraService: InfraService = {
probe: this.probeHost.probe, probe: this.probeHost.probe,
infraType: { infraType: {
@ -204,6 +200,7 @@ export class SearchResultComponent implements OnInit, OnChanges {
vendor: { vendor: {
} }
}; };
});
} }
saveTargets() { saveTargets() {