import { Component, OnInit, AfterViewInit, AfterContentInit, ViewChild } from '@angular/core'; import { Router } from '@angular/router'; import { TreeNode } from 'primeng/primeng'; @Component({ selector: 'of-infra-map', templateUrl: './map.component.html' }) export class MapComponent implements OnInit, AfterContentInit { infraTree: TreeNode[] = testInfraList; display = false; constructor(private router: Router) {} ngAfterContentInit() {} ngOnInit() {} showDialog() { this.display = true; } expandAll() { this.infraTree.forEach(node => { this.expandRecursive(node, true); }); } collapseAll() { this.infraTree.forEach(node => { this.expandRecursive(node, false); }); } private expandRecursive(node: TreeNode, isExpand: boolean) { node.expanded = isExpand; if (node.children) { node.children.forEach(childNode => { this.expandRecursive(childNode, isExpand); }); } } } const testInfraList = [ { label: 'Infra', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Zone - 192.168.1.0/24', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Host - 192.168.1.106 - Snoop Host', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - WMI, SSH, SNMP', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true }, { label: 'Service - FTP(21)', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - FTP, Sensor', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true } ] } ] }, { label: 'Host - 192.168.1.103 - Geek Host', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - WMI, SSH, SNMP', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true }, { label: 'Service - MySQL(3306)', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - MySQL, PING', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true } ] }, { label: 'Service - PostgreSQL(5555)', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - PostgreSQL, PING', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true } ] } ] } ] }, { label: 'Zone - 192.168.10.0/24', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Host - 192.168.10.106 - Snoop Host', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - WMI, SSH, SNMP', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true }, { label: 'Service - FTP(21)', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - FTP, Sensor', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true } ] } ] }, { label: 'Host - 192.168.10.103 - Geek Host', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - WMI, SSH, SNMP', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true }, { label: 'Service - MySQL(3306)', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - MySQL, PING', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true } ] }, { label: 'Service - PostgreSQL(5555)', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true, children: [ { label: 'Sensors - PostgreSQL, PING', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: true } ] } ] } ] } ] } ];