@@ -18,6 +18,7 @@ import { ArpTable } from "./arp_table";
1818import { Layer } from "../../types/layer" ;
1919import { DataNetworkDevice , DataSwitch } from "../../types/data-devices" ;
2020import { SwitchingTable } from "./switching_table" ;
21+ import { ToggleInfo } from "../components/toggle_info" ;
2122
2223export class DeviceInfo extends BaseInfo {
2324 readonly device : ViewDevice ;
@@ -26,6 +27,7 @@ export class DeviceInfo extends BaseInfo {
2627 super ( getTypeName ( device ) + " Information" ) ;
2728 this . device = device ;
2829 this . addCommonInfoFields ( ) ;
30+ this . addCommonButtons ( ) ;
2931 }
3032
3133 protected addCommonInfoFields ( ) : void {
@@ -38,34 +40,11 @@ export class DeviceInfo extends BaseInfo {
3840 connections ,
3941 TOOLTIP_KEYS . CONNECTED_DEVICES ,
4042 ) ;
41-
42- const layer = this . device . viewgraph . getLayer ( ) ;
43- const showIp = this . device . getType ( ) !== DeviceType . Switch ;
44- const showMac = layer === Layer . Link ;
45-
46- if ( showIp ) {
47- this . device . interfaces . forEach ( ( iface ) => {
48- this . information . addField (
49- TOOLTIP_KEYS . IP_ADDRESS + ( iface . name ? ` (${ iface . name } )` : "" ) ,
50- iface . ip . toString ( ) ,
51- TOOLTIP_KEYS . IP_ADDRESS ,
52- ) ;
53- } ) ;
54- }
55-
56- if ( showMac ) {
57- this . device . interfaces . forEach ( ( iface ) => {
58- this . information . addField (
59- TOOLTIP_KEYS . MAC_ADDRESS + ( iface . name ? ` (${ iface . name } )` : "" ) ,
60- iface . mac . toString ( ) ,
61- TOOLTIP_KEYS . MAC_ADDRESS ,
62- ) ;
63- } ) ;
64- }
6543 }
6644
6745 protected addCommonButtons ( ) : void {
6846 this . addDivider ( ) ;
47+
6948 const connectButton = new Button ( {
7049 text : TOOLTIP_KEYS . CONNECT_DEVICE ,
7150 onClick : ( ) => this . device . selectToConnect ( ) ,
@@ -91,9 +70,47 @@ export class DeviceInfo extends BaseInfo {
9170 } ) ;
9271
9372 this . inputFields . push ( connectButton . toHTML ( ) , deleteButton . toHTML ( ) ) ;
73+
74+ this . addIfacesToggle ( ) ;
9475 this . addDivider ( ) ;
9576 }
9677
78+ addIfacesToggle ( ) : void {
79+ const layer = this . device . viewgraph . getLayer ( ) ;
80+ const showIp = this . device . getType ( ) !== DeviceType . Switch ;
81+ const showMac = layer === Layer . Link ;
82+
83+ const fields : { key : string ; value : string ; tooltip : string } [ ] = [ ] ;
84+
85+ if ( showIp ) {
86+ this . device . interfaces . forEach ( ( iface ) => {
87+ fields . push ( {
88+ key : TOOLTIP_KEYS . IP_ADDRESS + ( iface . name ? ` (${ iface . name } )` : "" ) ,
89+ value : iface . ip . toString ( ) ,
90+ tooltip : TOOLTIP_KEYS . IP_ADDRESS ,
91+ } ) ;
92+ } ) ;
93+ }
94+ if ( showMac ) {
95+ this . device . interfaces . forEach ( ( iface ) => {
96+ fields . push ( {
97+ key :
98+ TOOLTIP_KEYS . MAC_ADDRESS + ( iface . name ? ` (${ iface . name } )` : "" ) ,
99+ value : iface . mac . toString ( ) ,
100+ tooltip : TOOLTIP_KEYS . MAC_ADDRESS ,
101+ } ) ;
102+ } ) ;
103+ }
104+
105+ const toggleInfo = new ToggleInfo ( {
106+ title : "Interfaces" ,
107+ fields,
108+ toggleButtonText : { on : "Hide Interfaces" , off : "Show Interfaces" } ,
109+ } ) ;
110+
111+ this . inputFields . push ( toggleInfo . toHTML ( ) ) ;
112+ }
113+
97114 addProgramRunner ( runner : ProgramRunner , programs : ProgramInfo [ ] ) : void {
98115 const programRunnerInfo = new ProgramRunnerInfo ( runner , programs ) ;
99116 this . inputFields . push ( ...programRunnerInfo . toHTML ( ) ) ;
0 commit comments