Skip to content

Commit 29175fb

Browse files
authored
Add change tracking to visualisation tool + present changes on save (#13)
1 parent c149714 commit 29175fb

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/Visualiser/Pages/Index.cshtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@
9494
</div>
9595
<form id="saveNetwork" asp-page-handler="Network" method="post">
9696
<div class="modal-body">
97-
Are you sure you wish to save your changes?
97+
<p>Are you sure you wish to save your changes?</p>
98+
99+
<div id="changeTracker" style="max-height: 300px; overflow: auto;"></div>
98100

99101
<div class="alert alert-warning mt-4" role="alert">
100-
Changes cannot be undone!
102+
Once saved, these changes cannot be undone!
101103
</div>
102104

103105
</div>

src/Visualiser/wwwroot/js/network.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var dataset = {
55
edges: new vis.DataSet(),
66
};
77

8+
const changeTracker = [];
9+
810
dataset.nodes.forEach(saturateNode);
911
dataset.edges.forEach(saturateEdge);
1012

@@ -79,6 +81,10 @@ $("#editNodeForm").on("submit", function (event) {
7981
reassignNode(node, toClusterId);
8082
}
8183

84+
if(node.hardLink != hardLink) {
85+
changeTracker.push(`Hardlink ${hardLink ? 'added to' : 'removed from'} ${node.id} (${node.group})`);
86+
}
87+
8288
node.hardLink = hardLink;
8389

8490
saturateNode(node);
@@ -137,6 +143,8 @@ document.getElementById("findClusterForm").addEventListener("submit", async even
137143
dataset.nodes.add(cluster.nodes);
138144
dataset.edges.add(cluster.edges);
139145

146+
changeTracker.push(`Cluster ${cluster.upci} added to network`);
147+
140148
findClusterModal.hide();
141149
})
142150
.catch(error => {
@@ -162,6 +170,7 @@ $("#reassignCheckbox").on('change', event => {
162170
})
163171

164172
$("#saveNetworkButton").on("click", function() {
173+
$("#changeTracker").html(`<ul class="list-group list-group-flush list-group-numbered">${changeTracker.map(change => `<li class="list-group-item">${change}</li>`).join('')}</ul>`);
165174
saveNetworkModal.show();
166175
});
167176

@@ -245,6 +254,8 @@ function addEdge(node, callback) {
245254
node.probability = 1.0;
246255
saturateEdge(node);
247256

257+
changeTracker.push(`Edge added from ${node.from} to ${node.to}`);
258+
248259
callback(node);
249260
}
250261

@@ -268,8 +279,6 @@ function edgeExists(fromNodeId, toNodeId) {
268279
}
269280

270281
function editNode(node, callback) {
271-
let clusters = getClusters();
272-
273282
if (node.type === "cluster") {
274283
alert("You cannot edit an empty cluster. Reassign nodes to it instead.");
275284
callback(null);
@@ -451,6 +460,8 @@ function reassignNode(node, toClusterId) {
451460
let edges = dataset.edges.get({ filter: (edge) => edge.from === node.id || edge.to === node.id });
452461
edges.forEach(edge => dataset.edges.remove(edge.id));
453462

463+
const fromClusterId = node.id;
464+
454465
// Destroy target cluster
455466
if (isCluster(toClusterId)) {
456467
dataset.nodes.remove(toClusterId);
@@ -479,6 +490,8 @@ function reassignNode(node, toClusterId) {
479490
saturateEdge(edge);
480491
});
481492

493+
changeTracker.push(`${node.id} reassigned from ${fromClusterId} to ${toClusterId}`);
494+
482495
// Move the node to target group
483496
node.group = toClusterId;
484497
saturateNode(node);

0 commit comments

Comments
 (0)