Commit d57101ac authored by Matija Obreza's avatar Matija Obreza

Updated node keys

- Root defaults to 0
- Sorting by key for the table
parent d484f4eb
......@@ -61,35 +61,35 @@
<div class="row">
<div class="large-12 columns">
<label>
Node ID
<input type="text" class="inputName" id='NodeID' placeholder="PEA" />
Node name
<input type="text" class="inputName" id='NodeName' placeholder="Node name" />
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>
Full node ID
<input type="text" class="inputName" id='FullNodeID' disabled/>
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>
Node name
<input type="text" class="inputName" id='NodeName' placeholder="Node name" />
Relative weight <em>[0 &mdash; 100]</em>
<input type="text" class="inputName" id='NodeWeight' placeholder="100" />
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>
Relative weight <em>[0 &mdash; 100]</em>
<input type="text" class="inputName" id='NodeWeight' placeholder="100" />
Node ID
<input type="text" class="inputName" id='NodeID' placeholder="PEA" />
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>
Full node ID
<input type="text" class="inputName" id='FullNodeID' disabled/>
</label>
</div>
</div>
<div class="row">
<div class="large-8 columns">
&nbsp;
......
......@@ -113,7 +113,7 @@ function assignIDs(node) {
node.fullID = `${node.parent.fullID}.${node.nodeId}`
}
} else {
node.fullID = node.nodeId;
node.fullID = node.nodeId || '0';
}
if (node.children && node.children.length !== 0) {
......@@ -171,7 +171,22 @@ let outer_update = null;
export function draw_nodes_table(tbody) {
$(tbody).empty();
$(tbody).append(`<tr><th>ID</th><th>Node title</th></tr>`);
for (let n of getNodesKeys()) {
const nodes = getNodesKeys().sort((a, b) => {
if ((a.id !== null && a.id !== undefined) && (b.id !== null || b.id !== undefined)) {
const dA = a.id.match(/\./g) || 0; // dots in A
const dB = b.id.match(/\./g) || 0; // dots in B
if (dA.length === dB.length) {
return a.id.localeCompare(b.id);
} else {
return dA - dB;
}
} else if (a.id !== null) {
return 1;
} else {
return -1;
}
});
for (let n of nodes) {
$(tbody).append(`<tr><td>${n.id}</td><td>${n.name}</td></tr>`);
}
}
......@@ -253,7 +268,7 @@ export function draw_tree(container, treeData) {
$("#NodeName").val(d.name);
$("#NodeWeight").val(d.weight);
$('#NodePropertiesModal').foundation('open');
$("#NodeID").focus();
$("#NodeName").focus();
}
},
{
......@@ -270,7 +285,7 @@ export function draw_tree(container, treeData) {
$("#NodeName").val('');
$("#NodeWeight").val(''); // 100 - sumChildrenWeights(d)
$('#NodePropertiesModal').foundation('open');
$('#NodeID').focus();
$('#NodeName').focus();
}
},
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment