fixing infra map

This commit is contained in:
snoop 2018-04-16 20:23:43 +09:00
parent c694cb96b6
commit bff8a97cd1

View File

@ -10,10 +10,13 @@ import { TreeNode } from 'primeng/primeng';
import { Store, select } from '@ngrx/store';
import * as ListStore from '../../store/list';
import { ListSelector } from '../../store';
import { Page } from 'app/commons/model';
import { Page, PageParams } from 'app/commons/model';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { Target } from 'packages/target/model';
import { Infra, InfraHost, InfraOSApplication, InfraService } from '../../model';
import { Domain } from 'packages/domain/model';
import { AuthSelector } from 'packages/member/store';
interface HostData {
id: string;
@ -27,7 +30,8 @@ interface HostData {
templateUrl: './map.component.html'
})
export class MapComponent implements OnInit, AfterContentInit {
infraTree: TreeNode[] = testInfraList;
// infraTree: TreeNode[] = testInfraList;
infraTree: TreeNode[] = [];
infras$ = this.listStore.pipe(select(ListSelector.select('page')));
@ -45,11 +49,31 @@ export class MapComponent implements OnInit, AfterContentInit {
ngAfterContentInit() {
this.listStore.select(AuthSelector.select('domain')).subscribe(
(domain: Domain) => {
const pageParams: PageParams = {
pageNo: '0',
countPerPage: '10',
sortCol: 'id',
sortDirection: 'descending'
};
this.listStore.dispatch(new ListStore.ReadAllByDomain({domain: domain, pageParams: pageParams}));
},
(error) => {
console.log(error);
}
);
this.infras$.subscribe(
(page: Page) => {
console.log(page);
if (page !== null) {
this.totalList = page.content;
this.generateInfraHostData();
console.log(this.totalList);
this.infraTree = this.generateInfraHostData();
}
},
(error: RPCClientError) => {
@ -60,7 +84,7 @@ export class MapComponent implements OnInit, AfterContentInit {
ngOnInit() {}
generateInfraHostData(filterStr?: string) {
generateInfraHostData(filterStr?: string): TreeNode[] {
const itl: TreeNode[] = [];
@ -136,67 +160,79 @@ export class MapComponent implements OnInit, AfterContentInit {
// }
const probeTreeNodes: TreeNode[] = [];
probeMap.forEach((ifhl: InfraHost[], key: number) => {
}
const tp: TreeNode = {
label: 'Probe - ' + key,
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(),
children: [],
};
}
ifhl.map((ih: InfraHost, idx: number) => {
const th: TreeNode = {
label: 'Host - ' + ih.ip,
const ProbeTree = {
label: 'Probe',
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: true,
children: [],
};
// const probeTreeNodes: TreeNode[] = [];
probeMap.forEach((ifhl: InfraHost[], key: number) => {
const tp: TreeNode = {
label: 'Probe - ' + key,
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(),
children: [],
};
ifhl.map((ih: InfraHost, idx: number) => {
const th: TreeNode = {
label: 'Host - ' + ih.ip,
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(),
children: [],
};
if (hostMap.has(ih.ip)) {
const ifsl = hostMap.get(ih.ip);
for (let i = 0 ; i < ifsl.length; ++i) {
const ts: TreeNode = {
label: 'Service - ' + ifsl[i].vendor.name,
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(),
children: [],
};
if (hostMap.has(ih.ip)) {
th.children.push(ts);
}
const ifsl = hostMap.get(ih.ip);
for (let i = 0 ; i < ifsl.length; ++i) {
const ts: TreeNode = {
label: 'Service - ' + ifsl[i].vendor.name,
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: this.DEFAULT_EXPANDED.valueOf(),
children: [],
};
th.children.push(ts);
}
}
}
tp.children.push(th);
tp.children.push(th);
});
});
probeTreeNodes.push(tp);
});
ProbeTree.children.push(tp);
});
infraTree.children.push(probeTreeNodes);
infraTree.children.push(ProbeTree);
}
}
this.loading = false;
itl.push(infraTree);
return infraTree;
return itl;
}