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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
/**
* ============LICENSE_START========================================================================
* ONAP : ccsdk feature sdnr wt odlux
* =================================================================================================
* Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
* =================================================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
* ============LICENSE_END==========================================================================
*/
import * as React from 'react';
import { Theme } from '@mui/material/styles';
import { WithStyles } from '@mui/styles';
import createStyles from '@mui/styles/createStyles';
import withStyles from '@mui/styles/withStyles';
import AddIcon from '@mui/icons-material/Add';
import Refresh from '@mui/icons-material/Refresh';
import LinkIcon from '@mui/icons-material/Link';
import LinkOffIcon from '@mui/icons-material/LinkOff';
import RemoveIcon from '@mui/icons-material/RemoveCircleOutline';
import EditIcon from '@mui/icons-material/Edit';
import Info from '@mui/icons-material/Info';
import ComputerIcon from '@mui/icons-material/Computer';
import { MenuItem, Divider, Typography } from '@mui/material';
import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
import { connect, Connect, IDispatcher } from '../../../../framework/src/flux/connect';
import { NavigateToApplication } from '../../../../framework/src/actions/navigationActions';
import { createNetworkElementsActions, createNetworkElementsProperties } from '../handlers/networkElementsHandler';
import { NetworkElementConnection } from '../models/networkElementConnection';
import { ModuleSet, TopologyNode } from '../models/topologyNetconf';
import EditNetworkElementDialog, { EditNetworkElementDialogMode } from './editNetworkElementDialog';
import RefreshNetworkElementsDialog, { RefreshNetworkElementsDialogMode } from './refreshNetworkElementsDialog';
import InfoNetworkElementDialog, { InfoNetworkElementDialogMode } from './infoNetworkElementDialog';
import { loadAllInfoElementAsync, loadAllInfoElementFeaturesAsync } from '../actions/infoNetworkElementActions';
import { connectService } from '../services/connectService';
import { getAccessPolicyByUrl } from '../../../../framework/src/services/restService';
const styles = (theme: Theme) => createStyles({
connectionStatusConnected: {
color: 'darkgreen',
},
connectionStatusConnecting: {
color: 'blue',
},
connectionStatusDisconnected: {
color: 'red',
},
button: {
margin: 0,
padding: "6px 6px",
minWidth: 'unset'
},
spacer: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
display: "inline"
}
});
type GetStatelessComponentProps<T> = T extends (props: infer P & { children?: React.ReactNode }) => any ? P : any
const MenuItemExt: React.FC<GetStatelessComponentProps<typeof MenuItem>> = (props) => {
const [disabled, setDisabled] = React.useState(true);
const onMouseDown = (ev: React.MouseEvent<HTMLElement>) => {
if (ev.button === 1) {
setDisabled(!disabled);
ev.preventDefault();
}
};
return (
<div onMouseDown={onMouseDown} >
<MenuItem {...{ ...props, disabled: props.disabled && disabled }} />
</div>
);
};
const mapProps = (state: IApplicationStoreState) => ({
networkElementsProperties: createNetworkElementsProperties(state),
applicationState: state,
});
const mapDispatch = (dispatcher: IDispatcher) => ({
networkElementsActions: createNetworkElementsActions(dispatcher.dispatch),
navigateToApplication: (applicationName: string, path?: string) => dispatcher.dispatch(new NavigateToApplication(applicationName, path)),
networkElementInfo: async (nodeId: string) => await dispatcher.dispatch(loadAllInfoElementAsync(nodeId)),
networkElementFeaturesInfo: async (nodeId: string) => await dispatcher.dispatch(loadAllInfoElementFeaturesAsync(nodeId))
});
type NetworkElementsListComponentProps = WithStyles<typeof styles> & Connect<typeof mapProps, typeof mapDispatch>;
type NetworkElementsListComponentState = {
networkElementToEdit: NetworkElementConnection,
networkElementEditorMode: EditNetworkElementDialogMode,
refreshNetworkElementsEditorMode: RefreshNetworkElementsDialogMode,
infoNetworkElementEditorMode: InfoNetworkElementDialogMode,
elementInfo: TopologyNode | null,
elementInfoFeature: ModuleSet | null
}
const emptyRequireNetworkElement: NetworkElementConnection = { id: "", nodeId: "", host: "", port: 0, status: "Disconnected", isRequired: false };
let initialSorted = false;
const NetworkElementTable = MaterialTable as MaterialTableCtorType<NetworkElementConnection>;
export class NetworkElementsListComponent extends React.Component<NetworkElementsListComponentProps, NetworkElementsListComponentState> {
constructor(props: NetworkElementsListComponentProps) {
super(props);
this.state = {
networkElementToEdit: emptyRequireNetworkElement,
networkElementEditorMode: EditNetworkElementDialogMode.None,
refreshNetworkElementsEditorMode: RefreshNetworkElementsDialogMode.None,
elementInfo: null,
elementInfoFeature: null,
infoNetworkElementEditorMode: InfoNetworkElementDialogMode.None
};
}
getContextMenu(rowData: NetworkElementConnection): JSX.Element[] {
const mountUri = rowData.id && connectService.getNetworkElementUri(rowData.id);
const mountPolicy = mountUri && getAccessPolicyByUrl(mountUri);
const canMount = mountPolicy && mountPolicy.POST || false;
const { configuration } = this.props.applicationState as any;
const buttonArray = [
<MenuItemExt aria-label={"mount-button"} onClick={event => this.onOpenMountdNetworkElementsDialog(event, rowData)} disabled={!canMount} ><LinkIcon /><Typography>Mount</Typography></MenuItemExt>,
<MenuItemExt aria-label={"unmount-button"} onClick={event => this.onOpenUnmountdNetworkElementsDialog(event, rowData)} disabled={!canMount} ><LinkOffIcon /><Typography>Unmount</Typography></MenuItemExt>,
<Divider />,
<MenuItem aria-label={"info-button"} onClick={event => this.onOpenInfoNetworkElementDialog(event, rowData)} disabled={rowData.status === "Connecting" || rowData.status === "Disconnected"} ><Info /><Typography>Info</Typography></MenuItem>,
<MenuItem aria-label={"edit-button"} onClick={event => this.onOpenEditNetworkElementDialog(event, rowData)}><EditIcon /><Typography>Edit</Typography></MenuItem>,
<MenuItem aria-label={"remove-button"} onClick={event => this.onOpenRemoveNetworkElementDialog(event, rowData)} ><RemoveIcon /><Typography>Remove</Typography></MenuItem>,
<Divider />,
<MenuItem aria-label={"inventory-button"} onClick={event => this.props.navigateToApplication("inventory", rowData.nodeId)}><Typography>Inventory</Typography></MenuItem>,
<Divider />,
<MenuItem aria-label={"fault-button"} onClick={event => this.props.navigateToApplication("fault", rowData.nodeId)} ><Typography>Fault</Typography></MenuItem>,
<MenuItem aria-label={"configure-button"} onClick={event => this.props.navigateToApplication("configuration", rowData.nodeId)} disabled={rowData.status === "Connecting" || rowData.status === "Disconnected" || !configuration}><Typography>Configure</Typography></MenuItem>,
<MenuItem onClick={event => this.props.navigateToApplication("accounting", rowData.nodeId)} disabled={true}><Typography>Accounting</Typography></MenuItem>,
<MenuItem aria-label={"performance-button"} onClick={event => this.props.navigateToApplication("performanceHistory", rowData.nodeId)}><Typography>Performance</Typography></MenuItem>,
<MenuItem onClick={event => this.props.navigateToApplication("security", rowData.nodeId)} disabled={true} ><Typography>Security</Typography></MenuItem>,
];
if (rowData.weburi) {
// add an icon for gui cuttrough, if weburi is available
return [<MenuItem aria-label={"web-client-button"} onClick={event => window.open(rowData.weburi, "_blank")} ><ComputerIcon /><Typography>Web Client</Typography></MenuItem>].concat(buttonArray)
} else {
return buttonArray;
}
}
// private navigationCreator
render(): JSX.Element {
const { classes } = this.props;
const { networkElementToEdit } = this.state;
let savedRadio = "password";
if (this.state.networkElementToEdit.password && this.state.networkElementToEdit.password.length > 0) {
savedRadio = 'password'
} else if (this.state.networkElementToEdit.tlsKey && this.state.networkElementToEdit.tlsKey.length > 0) {
savedRadio = 'tlsKey'
}
// const mountUri = rowData.id && connectService.getNetworkElementUri(rowData.id);
// const mountPolicy = mountUri && getAccessPolicyByUrl(mountUri);
// const canAdd = mountPolicy && mountPolicy.POST || false;
const canAdd = true;
const addRequireNetworkElementAction = {
icon: AddIcon, tooltip: 'Add', ariaLabel: "add-element", onClick: () => {
this.setState({
networkElementEditorMode: EditNetworkElementDialogMode.AddNewNetworkElement,
networkElementToEdit: emptyRequireNetworkElement,
});
}
};
const refreshNetworkElementsAction = {
icon: Refresh, tooltip: 'Refresh Network Elements table', ariaLabel: 'refresh', onClick: () => {
this.setState({
refreshNetworkElementsEditorMode: RefreshNetworkElementsDialogMode.RefreshNetworkElementsTable
});
}
};
return <>
<NetworkElementTable stickyHeader tableId="network-element-table" customActionButtons={[refreshNetworkElementsAction, ...(canAdd ? [addRequireNetworkElementAction] : [])]} columns={[
{ property: "nodeId", title: "Node Name", type: ColumnType.text },
{ property: "isRequired", title: "Required", type: ColumnType.boolean },
{ property: "status", title: "Connection Status", type: ColumnType.text, width:'15%' },
{ property: "host", title: "Host", type: ColumnType.text },
{ property: "port", title: "Port", type: ColumnType.numeric },
{ property: "coreModelCapability", title: "Core Model", type: ColumnType.text },
{ property: "deviceType", title: "Device Type", type: ColumnType.text },
{ property: "deviceFunction", title: "Device Function", type: ColumnType.text, width: '15%' }
]} idProperty="id" {...this.props.networkElementsActions} {...this.props.networkElementsProperties} asynchronus createContextMenu={rowData => {
return this.getContextMenu(rowData);
}} >
</NetworkElementTable>
<EditNetworkElementDialog
initialNetworkElement={networkElementToEdit}
mode={this.state.networkElementEditorMode}
onClose={this.onCloseEditNetworkElementDialog}
radioChecked={savedRadio}
/>
<RefreshNetworkElementsDialog
mode={this.state.refreshNetworkElementsEditorMode}
onClose={this.onCloseRefreshNetworkElementsDialog}
/>
<InfoNetworkElementDialog
initialNetworkElement={networkElementToEdit}
mode={this.state.infoNetworkElementEditorMode}
onClose={this.onCloseInfoNetworkElementDialog}
/>
</>;
};
public componentDidMount() {
if (!initialSorted) {
initialSorted = true;
this.props.networkElementsActions.onHandleRequestSort("node-id");
} else {
this.props.networkElementsActions.onRefresh();
}
}
private onOpenAddNetworkElementDialog = (event: React.MouseEvent<HTMLElement>, element: NetworkElementConnection) => {
this.setState({
networkElementToEdit: element,
networkElementEditorMode: EditNetworkElementDialogMode.AddNewNetworkElement
});
}
private onOpenRemoveNetworkElementDialog = (event: React.MouseEvent<HTMLElement>, element: NetworkElementConnection) => {
this.setState({
networkElementToEdit: element,
networkElementEditorMode: EditNetworkElementDialogMode.RemoveNetworkElement
});
}
private onOpenEditNetworkElementDialog = (event: React.MouseEvent<HTMLElement>, element: NetworkElementConnection) => {
let radioSaved;
if (element.password && element.password.length > 0)
radioSaved = 'password'
else if (element.tlsKey && element.tlsKey.length > 0)
radioSaved = 'tlsKey'
this.setState({
networkElementToEdit: {
nodeId: element.nodeId,
isRequired: element.isRequired,
host: element.host,
port: element.port,
username: element.username,
password: element.password,
tlsKey: element.tlsKey
},
networkElementEditorMode: EditNetworkElementDialogMode.EditNetworkElement
});
}
private onOpenUnmountdNetworkElementsDialog = (event: React.MouseEvent<HTMLElement>, element: NetworkElementConnection) => {
this.setState({
networkElementToEdit: element,
networkElementEditorMode: EditNetworkElementDialogMode.UnmountNetworkElement
});
}
private onOpenMountdNetworkElementsDialog = (event: React.MouseEvent<HTMLElement>, element: NetworkElementConnection) => {
this.setState({
networkElementToEdit: element,
networkElementEditorMode: EditNetworkElementDialogMode.MountNetworkElement
});
}
private onOpenInfoNetworkElementDialog = (event: React.MouseEvent<HTMLElement>, element: NetworkElementConnection) => {
this.props.networkElementInfo(element.nodeId);
this.props.networkElementFeaturesInfo(element.nodeId);
this.setState({
networkElementToEdit: element,
infoNetworkElementEditorMode: InfoNetworkElementDialogMode.InfoNetworkElement,
});
}
private onCloseEditNetworkElementDialog = () => {
this.setState({
networkElementEditorMode: EditNetworkElementDialogMode.None,
networkElementToEdit: emptyRequireNetworkElement,
});
}
private onCloseInfoNetworkElementDialog = () => {
this.setState({
infoNetworkElementEditorMode: InfoNetworkElementDialogMode.None,
networkElementToEdit: emptyRequireNetworkElement,
});
}
private onCloseRefreshNetworkElementsDialog = () => {
this.setState({
refreshNetworkElementsEditorMode: RefreshNetworkElementsDialogMode.None
});
}
}
export const NetworkElementsList = withStyles(styles)(connect(mapProps, mapDispatch)(NetworkElementsListComponent));
|