1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
import * as React from 'react';
import { Theme, createStyles, WithStyles, withStyles, Tooltip } from '@material-ui/core';
import AddIcon from '@material-ui/icons/Add';
import LinkOffIcon from '@material-ui/icons/LinkOff';
import AddCircleIcon from '@material-ui/icons/AddCircleOutline';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
import { Connect, connect, IDispatcher } from '../../../../framework/src/flux/connect';
import { NavigateToApplication } from '../../../../framework/src/actions/navigationActions';
import { RequiredNetworkElementType } from '../models/requiredNetworkElements';
import { IMountedNetworkElementsState } from '../handlers/mountedNetworkElementsHandler';
import EditNetworkElementDialog, { EditNetworkElementDialogMode } from './editNetworkElementDialog';
import { NetworkElementBaseType } from 'models/networkElementBase';
const styles = (theme: Theme) => createStyles({
button: {
margin: 0,
padding: "6px 6px",
minWidth: 'unset'
},
spacer: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
display: "inline"
}
});
const mapProps = ({ connect: state }: IApplicationStoreState) => ({
mountedNetworkElements: state.mountedNetworkElements
});
const mapDispatch = (dispatcher: IDispatcher) => ({
navigateToApplication: (applicationName: string, path?: string) => dispatcher.dispatch(new NavigateToApplication(applicationName, path)),
});
type UnknownNetworkElementDisplayType = NetworkElementBaseType & {
connectionStatus: string,
coreModelRev: string,
airInterfaceRev: string
}
type UnknownNetworkElementsListProps = WithStyles<typeof styles> & Connect<typeof mapProps, typeof mapDispatch> & {}
type UnknownNetworkElementsListState = {
unknownNetworkElements: UnknownNetworkElementDisplayType[];
networkElementToEdit: RequiredNetworkElementType;
networkElementEditorMode: EditNetworkElementDialogMode;
}
const emptyRequireNetworkElement = { mountId: '', host: '', port: 0 };
const UnknownNetworkElementTable = MaterialTable as MaterialTableCtorType<UnknownNetworkElementDisplayType>;
export class UnknownNetworkElementsListComponent extends React.Component<UnknownNetworkElementsListProps, UnknownNetworkElementsListState> {
constructor(props: UnknownNetworkElementsListProps) {
super(props);
this.state = {
unknownNetworkElements: [],
networkElementToEdit: emptyRequireNetworkElement,
networkElementEditorMode: EditNetworkElementDialogMode.None,
};
}
static getDerivedStateFromProps(props: UnknownNetworkElementsListProps, state: UnknownNetworkElementsListState & { _mountedNetworkElements: IMountedNetworkElementsState }) {
if (props.mountedNetworkElements != state._mountedNetworkElements) {
state.unknownNetworkElements = props.mountedNetworkElements.elements.filter(element => !element.required).map(element => {
// handle onfCoreModelRevision
const onfCoreModelRevision = element.capabilities.find((cap) => {
return cap.module === 'core-model' || cap.module === 'CoreModel-CoreNetworkModule-ObjectClasses' ;
});
const onfAirInterfaceRevision = element.capabilities.find((cap) => {
return cap.module === 'microwave-model' || cap.module === 'MicrowaveModel-ObjectClasses-AirInterface' ;
});
return {
mountId: element.mountId,
host: element.host,
port: element.port,
connectionStatus: element.connectionStatus,
coreModelRev: onfCoreModelRevision && onfCoreModelRevision.revision || 'unknown',
airInterfaceRev: onfAirInterfaceRevision && onfAirInterfaceRevision.revision || 'unknown'
}
}
);
}
return state;
}
render(): JSX.Element {
const { classes } = this.props;
const { networkElementToEdit, networkElementEditorMode, unknownNetworkElements } = this.state;
const addRequireNetworkElementAction = {
icon: AddIcon, tooltip: 'Add', onClick: () => {
this.setState({
networkElementEditorMode: EditNetworkElementDialogMode.MountNetworkElementToUnknonwNetworkElements,
networkElementToEdit: emptyRequireNetworkElement,
});
}
};
return (
<>
<UnknownNetworkElementTable customActionButtons={ [addRequireNetworkElementAction] } asynchronus rows={ unknownNetworkElements } columns={ [
{ property: "mountId", title: "Name", type: ColumnType.text },
{ property: "connectionStatus", title: "Connection Status", type: ColumnType.text },
{ property: "host", title: "Host", type: ColumnType.text },
{ property: "port", title: "Port", type: ColumnType.text },
{ property: "coreModelRev", title: "Core Model", type: ColumnType.text },
{ property: "airInterfaceRev", title: "Air interface", type: ColumnType.text },
{
property: "actions", title: "Actions", type: ColumnType.custom, customControl: ({ rowData }) => (
<>
<div className={ classes.spacer }>
<Tooltip title={ "Unmount" } ><IconButton className={ classes.button } onClick={ event => this.onOpenUnmountdNetworkElementsDialog(event, rowData) } ><LinkOffIcon /></IconButton></Tooltip>
<Tooltip title={ "Add to required" } ><IconButton className={ classes.button } onClick={ event => this.onOpenAddToRequiredNetworkElementsDialog(event, rowData) } ><AddCircleIcon /></IconButton></Tooltip>
</div>
<div className={ classes.spacer }>
<Tooltip title={ "Info" } ><Button className={ classes.button } >I</Button></Tooltip>
</div>
<div className={ classes.spacer }>
<Tooltip title={ "Fault" } ><Button className={ classes.button } onClick={ this.navigateToApplicationHandlerCreator("fault", rowData) } >F</Button></Tooltip>
<Tooltip title={ "Configure" } ><Button className={ classes.button } onClick={ this.navigateToApplicationHandlerCreator("configure", rowData) } >C</Button></Tooltip>
<Tooltip title={ "Accounting " } ><Button className={ classes.button } onClick={ this.navigateToApplicationHandlerCreator("accounting", rowData) }>A</Button></Tooltip>
<Tooltip title={ "Performance" } ><Button className={ classes.button } onClick={ this.navigateToApplicationHandlerCreator("performance", rowData) }>P</Button></Tooltip>
<Tooltip title={ "Security" } ><Button className={ classes.button } onClick={ this.navigateToApplicationHandlerCreator("security", rowData) }>S</Button></Tooltip>
</div>
</>
)
},
] } idProperty="mountId" >
</UnknownNetworkElementTable>
<EditNetworkElementDialog
mode={ networkElementEditorMode }
initialNetworkElement={ networkElementToEdit }
onClose={ this.onCloseEditNetworkElementDialog }
/>
</>
);
};
private onOpenAddToRequiredNetworkElementsDialog = (event: React.MouseEvent<HTMLElement>, element: UnknownNetworkElementDisplayType) => {
this.setState({
networkElementToEdit: {
mountId: element.mountId,
host: element.host,
port: element.port,
username: 'admin',
password: 'admin',
},
networkElementEditorMode: EditNetworkElementDialogMode.UnknownNetworkElementToRequiredNetworkElements
});
event.preventDefault();
event.stopPropagation();
}
private onOpenUnmountdNetworkElementsDialog = (event: React.MouseEvent<HTMLElement>, element: UnknownNetworkElementDisplayType) => {
this.setState({
networkElementToEdit: {
mountId: element.mountId,
host: element.host,
port: element.port
},
networkElementEditorMode: EditNetworkElementDialogMode.UnmountNetworkElement
});
event.preventDefault();
event.stopPropagation();
}
private onCloseEditNetworkElementDialog = () => {
this.setState({
networkElementEditorMode: EditNetworkElementDialogMode.None,
networkElementToEdit: emptyRequireNetworkElement,
});
}
private navigateToApplicationHandlerCreator = (applicationName: string, element: NetworkElementBaseType) => (event: React.MouseEvent<HTMLElement>) => {
this.props.navigateToApplication(applicationName, element.mountId);
event.preventDefault();
event.stopPropagation();
}
}
export const UnknownNetworkElementsList = withStyles(styles)(connect(mapProps, mapDispatch)(UnknownNetworkElementsListComponent));
export default UnknownNetworkElementsList;
|