Fix note join bug
This commit is contained in:
parent
a54366eaa6
commit
c97a7cbb1a
1 changed files with 40 additions and 11 deletions
51
dist/main.js
vendored
51
dist/main.js
vendored
|
@ -17,6 +17,7 @@ let infoColumnCount = 5
|
||||||
// - Broadcast Address (last network address)
|
// - Broadcast Address (last network address)
|
||||||
let operatingMode = 'NORMAL'
|
let operatingMode = 'NORMAL'
|
||||||
let noteTimeout;
|
let noteTimeout;
|
||||||
|
let minSubnetSize = 30
|
||||||
|
|
||||||
$('input#network,input#netsize').on('input', function() {
|
$('input#network,input#netsize').on('input', function() {
|
||||||
$('#input_form')[0].classList.add('was-validated');
|
$('#input_form')[0].classList.add('was-validated');
|
||||||
|
@ -31,6 +32,11 @@ $('#btn_reset').on('click', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
|
if (operatingMode === 'AWS') {
|
||||||
|
minSubnetSize = 28
|
||||||
|
} else {
|
||||||
|
minSubnetSize = 30
|
||||||
|
}
|
||||||
let cidrInput = $('#network').val() + '/' + $('#netsize').val()
|
let cidrInput = $('#network').val() + '/' + $('#netsize').val()
|
||||||
let rootNetwork = get_network($('#network').val(), $('#netsize').val())
|
let rootNetwork = get_network($('#network').val(), $('#netsize').val())
|
||||||
let rootCidr = rootNetwork + '/' + $('#netsize').val()
|
let rootCidr = rootNetwork + '/' + $('#netsize').val()
|
||||||
|
@ -218,6 +224,20 @@ function count_network_children(network, subnetTree, ancestryList) {
|
||||||
return childCount
|
return childCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_network_children(network, subnetTree) {
|
||||||
|
// TODO: This might be able to be optimized. Ultimately it needs to count the number of keys underneath
|
||||||
|
// the current key are unsplit networks (IE rows in the table, IE keys with a value of {}).
|
||||||
|
let subnetList = []
|
||||||
|
for (let mapKey in subnetTree) {
|
||||||
|
if (Object.keys(subnetTree[mapKey]).length > 0) {
|
||||||
|
subnetList.push.apply(subnetList, get_network_children(network, subnetTree[mapKey]))
|
||||||
|
} else {
|
||||||
|
subnetList.push(mapKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return subnetList
|
||||||
|
}
|
||||||
|
|
||||||
function get_matching_network_list(network, subnetTree) {
|
function get_matching_network_list(network, subnetTree) {
|
||||||
let subnetList = []
|
let subnetList = []
|
||||||
for (let mapKey in subnetTree) {
|
for (let mapKey in subnetTree) {
|
||||||
|
@ -253,15 +273,11 @@ function mutate_subnet_map(verb, network, subnetTree) {
|
||||||
mutate_subnet_map(verb, network, subnetTree[mapKey])
|
mutate_subnet_map(verb, network, subnetTree[mapKey])
|
||||||
}
|
}
|
||||||
if (mapKey === network) {
|
if (mapKey === network) {
|
||||||
if (verb === 'split') {
|
|
||||||
let netSplit = mapKey.split('/')
|
let netSplit = mapKey.split('/')
|
||||||
// operatingMode NORMAL
|
let netSize = parseInt(netSplit[1])
|
||||||
let minSubnetSize = 30
|
if (verb === 'split') {
|
||||||
if (operatingMode === 'AWS') {
|
if (netSize < minSubnetSize) {
|
||||||
minSubnetSize = 28
|
let new_networks = split_network(netSplit[0], netSize)
|
||||||
}
|
|
||||||
if (parseInt(netSplit[1]) < minSubnetSize) {
|
|
||||||
let new_networks = split_network(netSplit[0], parseInt(netSplit[1]))
|
|
||||||
subnetTree[mapKey][new_networks[0]] = {}
|
subnetTree[mapKey][new_networks[0]] = {}
|
||||||
subnetTree[mapKey][new_networks[1]] = {}
|
subnetTree[mapKey][new_networks[1]] = {}
|
||||||
// Copy note to both children and delete Delete parent note
|
// Copy note to both children and delete Delete parent note
|
||||||
|
@ -272,9 +288,22 @@ function mutate_subnet_map(verb, network, subnetTree) {
|
||||||
} else if (verb === 'join') {
|
} else if (verb === 'join') {
|
||||||
// Keep the note of the first subnet (which matches the network address) and lose the second subnet's note
|
// Keep the note of the first subnet (which matches the network address) and lose the second subnet's note
|
||||||
// Could consider changing this to concatenate the notes into the parent, but I think this is more intuitive
|
// Could consider changing this to concatenate the notes into the parent, but I think this is more intuitive
|
||||||
subnetNotes[mapKey] = subnetNotes[Object.keys(subnetTree[mapKey])[0]]
|
// Find first (smallest) subnet note which matches the exact network address (this would be the top network in the join scope)
|
||||||
subnetNotes[Object.keys(subnetTree[mapKey])[0]] = ''
|
let smallestMatchingNetworkSize = 0
|
||||||
subnetNotes[Object.keys(subnetTree[mapKey])[1]] = ''
|
for (let subnetCidr in subnetNotes) {
|
||||||
|
if (subnetCidr.startsWith(netSplit[0])) {
|
||||||
|
if (parseInt(subnetCidr.split('/')[1]) > smallestMatchingNetworkSize) {
|
||||||
|
smallestMatchingNetworkSize = subnetCidr.split('/')[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subnetNotes[mapKey] = subnetNotes[netSplit[0] + '/' + smallestMatchingNetworkSize]
|
||||||
|
// Delete all notes of subnets under this collapsed subnet
|
||||||
|
let removeKeys = get_network_children(mapKey, subnetTree[mapKey], [])
|
||||||
|
for (let removeKey in removeKeys) {
|
||||||
|
subnetNotes[removeKey] = ''
|
||||||
|
}
|
||||||
|
// And delete the subnets themselves
|
||||||
subnetTree[mapKey] = {}
|
subnetTree[mapKey] = {}
|
||||||
} else {
|
} else {
|
||||||
// How did you get here?
|
// How did you get here?
|
||||||
|
|
Loading…
Reference in a new issue