a21c14f61c0cb4eb740fb84575fe0b11986c953d
2 Copyright 2018 EveryUP srl
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 //GraphEditor instance
18 var graph_editor
= new TCD3
.ModelGraphEditor();
21 "nsd": ["vnf", "ns_vl"],
22 "vnfd": ["vdu", "cp", "vnf_vl", "int_cp"]
27 type
: type_view
[getUrlParameter('type')],
32 view
: [getUrlParameter('type')]
36 $(document
).ready(function () {
38 graph_editor
.addListener("filters_changed", changeFilter
);
39 graph_editor
.addListener("node:selected", refreshElementInfo
);
40 graph_editor
.addListener("node:deselected", refreshElementInfo
);
42 // graph_editor initialization
44 width
: $('#graph_editor_container').width(),
45 height
: $('#graph_editor_container').height(),
47 data_url
: window
.location
.href
,
48 //desc_id: getUrlParameter('id'),
49 gui_properties
: osm_gui_properties
,
53 behaviors
: buildBehaviorsOnEvents()
56 graph_editor
.handleFiltersParams(params
);
62 function handleForce(el
) {
63 graph_editor
.handleForce((el
.getAttribute('aria-pressed') === "true"));
66 function changeFilter(e
, c
) {
67 if (c
&& c
.link
&& c
.link
.view
[0]) {
68 updateLegend(c
.link
.view
[0]);
70 //layerDetails(graph_editor.getCurrentFilters())
73 function resetFilters() {
74 graph_editor
.handleFiltersParams(params
);
77 function buildBehaviorsOnEvents() {
79 var contextmenuNodesAction
= [
82 action: function (elm
, c_node
, i
) {
83 if (c_node
.info
.type
!== undefined) {
84 var current_layer_nodes
= Object
.keys(graph_editor
.model
.layer
[graph_editor
.getCurrentView()].nodes
);
85 if (current_layer_nodes
.indexOf(c_node
.info
.type
) >= 0) {
86 if (graph_editor
.model
.layer
[graph_editor
.getCurrentView()].nodes
[c_node
.info
.type
].expands
) {
87 var new_layer
= graph_editor
.model
.layer
[graph_editor
.getCurrentView()].nodes
[c_node
.info
.type
].expands
;
88 graph_editor
.handleFiltersParams({
90 type
: Object
.keys(graph_editor
.model
.layer
[new_layer
].nodes
),
101 showAlert('This is not an explorable node.')
110 'nodes': contextmenuNodesAction
115 function refreshElementInfo(event
, element
) {
116 if (event
.type
=== 'node:selected') {
117 switch (element
.info
.type
) {
119 vnfDetails(element
.info
.osm
);
122 vduDetails(element
.info
.osm
);
126 cpDetails(element
.info
.osm
);
130 vlDetails(element
.info
.osm
);
134 else if (event
.type
=== 'node:deselected') {
135 layerDetails(graph_editor
.getCurrentFilters())
139 function layerDetails(filters
) {
140 var side
= $('#side');
141 var graph_parameters
= graph_editor
.getGraphParams();
142 var layer_template
= '';
143 console
.log(graph_parameters
)
144 if(graph_parameters
['view'] && filters
.link
.view
.length
>0 && filters
.link
.view
[0]){
145 if(filters
.link
.view
[0] === 'nsr') {
146 layer_template
= getMainSection('NS View');
147 layer_template
+= getChildrenTable(graph_parameters
['view']['nsr']);
149 else if(filters
.link
.view
[0] === 'vnfr') {
150 layer_template
= getMainSection('VNF View');
151 var vnfr_id
= filters
.link
.group
[0];
152 layer_template
+= getChildrenTable(graph_parameters
['view']['vnfr'][vnfr_id
]);
157 side
.append(layer_template
)
160 function updateLegend(view
) {
161 var legend
= $('#legenda');
162 var nodes
= type_view
[view
];
163 var legend_template
= '';
164 var nodes_properties
= osm_gui_properties
['nodes'];
165 for (var n
in nodes
){
167 if(nodes_properties
[node
]){
168 legend_template
+= '<div class="node">' +
169 '<div class="icon" style="background-color:' + nodes_properties
[node
].color
+'"></div>' +
170 '<div class="name">' +nodes_properties
[node
].name
+ '</div></div>';
175 legend
.append(legend_template
)
180 'ip-address': 'IP', 'vnfd-id': 'Vnfd Id', 'vnfd-ref': 'Vnfd Ref', 'vim-account-id': 'Vim Id',
181 'member-vnf-index-ref': 'Member index', 'created-time': 'Created', 'id': 'Id', 'mgmt-network': 'Mgmt network',
182 'name': 'Name', 'type': 'Type', 'vim-network-name': 'Vim network name', 'connection-point-id': 'Cp Id',
183 'vdu-id-ref': 'Vdu Id', 'nsr-id-ref': 'Nsr Id'
186 function vnfDetails(vnfr
) {
187 var side
= $('#side');
188 var vnfr_template
= getMainSection('VNF');
190 vnfr_template
+= getChildrenTable(vnfr
);
192 side
.append(vnfr_template
)
195 function vduDetails(vdur
) {
196 var side
= $('#side');
197 var vdur_template
= getMainSectionWithStatus('VDU', vdur
['status'] === 'ACTIVE');
198 vdur_template
+= getChildrenTable(vdur
);
200 if (vdur
['interface'] && vdur
['interface'].length
> 0) {
201 vdur_template
+= getSubSection('Interfaces:');
202 vdur_template
+= '<table class="children">';
204 for (var i
= 0; i
< vdur
['interface'].length
; ++i
) {
205 var interface = vdur
['interface'][i
];
206 var interface_template
= '<tr><td>' + interface['name'] + '</td>'
207 + '<td>IP:' + interface['ip-address'] + '</td>'
208 + '<td>MAC:' + interface['mac-address'] + '</td>';
209 vdur_template
+= interface_template
;
211 vdur_template
+= '</table>';
215 side
.append(vdur_template
)
218 function cpDetails(cp
) {
219 var side
= $('#side');
220 var cp_template
= getMainSection('Connection Point');
222 cp_template
+= getChildrenTable(cp
);
224 side
.append(cp_template
);
227 function vlDetails(vl
) {
228 var side
= $('#side');
229 var vl_template
= getMainSection('Virtual Link');
231 vl_template
+= getChildrenTable(vl
);
233 side
.append(vl_template
);
237 function getMainSection(title
) {
238 return '<div class="section"><span style="font-weight: 500;">' + title
+ '</span></div>';
241 function getSubSection(title
) {
242 return '<div class="section"><span>' + title
+ '</span></div>';
245 function getMainSectionWithStatus(title
, status
) {
246 var template
= '<div class="section"><span style="font-weight: 500;">' + title
+ '</span>';
248 template
+= '<div class="status active"><span class="indicator"></span> ACTIVE</div>';
250 template
+= '<div class="status"><span class="indicator"></span>NO ACTIVE</div>';
251 template
+= '</div>';
255 function getChildrenTable(data
) {
256 var template
= '<table class="children">';
258 for (var key
in data
) {
259 if (typeof data
[key
] === 'string') {
260 var key_map
= (map
[key
]) ? map
[key
] : key
;
261 template
+= '<tr><td>' + key_map
+ '</td><td><input name="'+key
+'" class="form-control input-sm" type="text" value="' + data
[key
] + '"></td></tr>';
264 template
+= '</table>';