auto save map positions

This commit is contained in:
Oliver Gorwits
2018-03-19 19:01:11 +00:00
parent 938b375df6
commit 6b3e4ceba7
3 changed files with 15 additions and 39 deletions

View File

@@ -151,24 +151,6 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m
graph.inspect().main.force.on('start.draggednode', null);
});
// ********************************************************
// ********* save new node positions back to DB ***********
// ********************************************************
graph.inspect().main.force.on('end.savepositions', function() {
graph.inspect().main.nodes.each(function(n) { n.fixed = true });
if (mapdata['newnodes'] && ('[% params.mapshow %]' != 'neighbors')) {
$.post(
'[% uri_for('/ajax/data/device/netmappositions') %]'
,$("#nd_vlan-entry, #nd_hgroup-select, input[name='mapshow']").serialize()
+ '&positions=' + JSON.stringify(graph.positions())
);
}
graph.inspect().main.force.on('end.savepositions', null);
});
// *****************************
// ********* DO IT!! ***********
// *****************************
@@ -213,6 +195,7 @@ function spin(selection, duration) {
duration = duration || 1500;
if (! graph.inspect().status.forceRunning) {
d3.select('#nd2_netmap-spinner').style('fill', '#CCFFCC').attr('d', circle);
saveMapPositions();
return;
}
d3.select('#nd2_netmap-spinner').style('fill', '#FFE4B5').attr('d', arc);
@@ -225,6 +208,20 @@ function spin(selection, duration) {
setTimeout(function() { spin(selection, duration); }, duration);
}
// ********************************************************
// ********* save new node positions back to DB ***********
// ********************************************************
function saveMapPositions() {
graph.inspect().main.nodes.each(function(n) { n.fixed = true });
$.post(
'[% uri_for('/ajax/data/device/netmappositions') %]'
,$("#nd_vlan-entry, #nd_hgroup-select, #nd_lgroup-select, input[name='mapshow']").serialize()
+ '&positions=' + JSON.stringify(graph.positions())
);
toastr.success('Saved map positions.');
}
// ***********************************************
// ************ full screen handling *************
// ***********************************************