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); 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!! *********** // ********* DO IT!! ***********
// ***************************** // *****************************
@@ -213,6 +195,7 @@ function spin(selection, duration) {
duration = duration || 1500; duration = duration || 1500;
if (! graph.inspect().status.forceRunning) { if (! graph.inspect().status.forceRunning) {
d3.select('#nd2_netmap-spinner').style('fill', '#CCFFCC').attr('d', circle); d3.select('#nd2_netmap-spinner').style('fill', '#CCFFCC').attr('d', circle);
saveMapPositions();
return; return;
} }
d3.select('#nd2_netmap-spinner').style('fill', '#FFE4B5').attr('d', arc); 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); 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 ************* // ************ full screen handling *************
// *********************************************** // ***********************************************

View File

@@ -23,13 +23,6 @@
$('.nd_modal').modal({show: false}); $('.nd_modal').modal({show: false});
$("[rel=tooltip]").tooltip({live: true}); $("[rel=tooltip]").tooltip({live: true});
$("[rel=popover]").popover({live: true}); $("[rel=popover]").popover({live: true});
// positions save not available in netmap neighbors view
if ($("input[name='mapshow']:checked").val() == 'neighbors') {
$('#nd_netmap-save').prop('disabled', true).removeClass('btn-info');
} else {
$('#nd_netmap-save').prop('disabled', false).addClass('btn-info');
}
} }
// on load, establish global delegations for now and future // on load, establish global delegations for now and future
@@ -147,15 +140,6 @@
.filter(function(n) { return n.selected }) .filter(function(n) { return n.selected })
.each(function(n) { n.fixed = true }); .each(function(n) { n.fixed = true });
}); });
$('#nd_netmap-save').on('click', function(event) {
event.preventDefault();
// if user enters vlan but does not submit this will save wrong data
$.post(
'[% uri_for('/ajax/data/device/netmappositions') %]'
,$("#nd_vlan-entry, #nd_hgroup-select, input[name='mapshow']").serialize()
+ '&positions=' + JSON.stringify(graph.positions())
);
});
$('#nd_netmap-zoomtodevice').on('click', function(event) { $('#nd_netmap-zoomtodevice').on('click', function(event) {
event.preventDefault(); event.preventDefault();
var node = graph.nodeDataById( graph['nd2']['centernode'] ); var node = graph.nodeDataById( graph['nd2']['centernode'] );

View File

@@ -30,11 +30,6 @@
</div> </div>
</div> </div>
<label><span id="">Positions: </span>
<button id="nd_netmap-save" class="nd_sidebar-btn-netmap btn btn-small" disabled>
<i class="icon-save icon-large pull-left nd_navbar-icon"></i> Save</button>
</label>
<table margin="0" border="0" class="nd_netmap-pin-controls"> <table margin="0" border="0" class="nd_netmap-pin-controls">
<tr> <tr>
<td class="nd_netmap-pin-controls-top-row"> <td class="nd_netmap-pin-controls-top-row">