Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<link rel="stylesheet" href="graphView.css?v=2" />
</head>
<body>
<div class="alert-warning">Not an official GR tool.</div>

<canvas id="bg-canvas"></canvas>

<div class="app-shell">
Expand Down Expand Up @@ -120,7 +118,7 @@ <h1>GRCAN Viewer</h1>
<script src="formSuperAdd.js?v=1"></script>
<script src="diffViewer.js?v=2"></script>
<script src="cytoscape.min.js"></script>
<script src="viewer.js?v=14"></script>
<script src="viewer.js?v=15"></script>
<script src="graphView.js?v=3"></script>
<script src="background.js?v=3"></script>
</body>
Expand Down
69 changes: 65 additions & 4 deletions Web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ window.addEventListener("DOMContentLoaded", function () {
const searchInput = document.getElementById("viewer-search");
let nodeIdMap = new Map();
let currentRef = "";
const requestedQueryKey = (() => {
try {
const params = new URLSearchParams(window.location.search);
if (params.has("ref")) return "ref";
if (params.has("branch")) return "branch";
return "ref";
} catch (_err) {
return "ref";
}
})();
const requestedRefFromUrl = (() => {
try {
const params = new URLSearchParams(window.location.search);
const ref = params.get("ref") || params.get("branch");
return ref ? ref.trim() : "";
} catch (_err) {
return "";
}
})();
let _allNodes = []; // persisted node→bus→messages index for search
let _searchDropdown = null;

Expand Down Expand Up @@ -63,6 +82,31 @@ window.addEventListener("DOMContentLoaded", function () {
container.appendChild(d);
}

function updateLocationState(ref) {
const url = new URL(window.location.href);
const isCustomFile = !!window.GrcanApi.isLocalMode();
const hasEdits =
!isCustomFile &&
!!editor &&
!!editor.hasUnsavedEdits &&
editor.hasUnsavedEdits();

if (isCustomFile) {
url.search = "";
url.hash = "custom";
} else {
if (ref) {
url.searchParams.set(requestedQueryKey, ref);
} else {
url.searchParams.delete("ref");
url.searchParams.delete("branch");
}
url.hash = hasEdits ? "edited" : "";
}

window.history.replaceState(null, "", url);
}

function messageChangeState(msgName, deviceName, busCanonical) {
const busPort = busCanonical
? window.GrcanApi.busToPort(busCanonical)
Expand Down Expand Up @@ -1113,6 +1157,7 @@ window.addEventListener("DOMContentLoaded", function () {
await renderBusNode(null, text);
}
restoreSelection(snapshot || navSnapshot());
updateLocationState(currentRef);
}

if (editor) {
Expand Down Expand Up @@ -1179,6 +1224,7 @@ window.addEventListener("DOMContentLoaded", function () {
}
await renderHierarchy(ref);
currentRef = ref;
updateLocationState(currentRef);
if (typeof window.regenerateAndDrawBg === "function") {
window.regenerateAndDrawBg();
}
Expand Down Expand Up @@ -1210,12 +1256,21 @@ window.addEventListener("DOMContentLoaded", function () {
refSelect.appendChild(opt);
});

if (branches.includes("main")) {
refSelect.value = "main";
await renderHierarchy("main");
currentRef = "main";
const availableRefs = new Set([...branches, ...tags]);
const initialRef = availableRefs.has(requestedRefFromUrl)
? requestedRefFromUrl
: branches.includes("main")
? "main"
: "";

if (initialRef) {
refSelect.value = initialRef;
await renderHierarchy(initialRef);
currentRef = initialRef;
updateLocationState(currentRef);
} else {
setPlaceholder(firstList, "Select a ref");
updateLocationState("");
}
}

Expand All @@ -1235,6 +1290,7 @@ window.addEventListener("DOMContentLoaded", function () {
localFileInput.value = "";
window.GrcanApi.setLocalCandoText(null);
refSelect.disabled = false;
updateLocationState(currentRef);
if (currentRef) renderHierarchy(currentRef);
}
});
Expand All @@ -1246,20 +1302,25 @@ window.addEventListener("DOMContentLoaded", function () {
localFileInput.style.display = "none";
window.GrcanApi.setLocalCandoText(null);
refSelect.disabled = false;
updateLocationState(currentRef);
return;
}
const reader = new FileReader();
reader.onload = function (e) {
window.GrcanApi.setLocalCandoText(e.target.result);
refSelect.disabled = true;
renderHierarchy(currentRef || "local");
updateLocationState(currentRef);
};
reader.readAsText(file);
});

localFileInput.addEventListener("cancel", function () {
localToggle.checked = false;
localFileInput.style.display = "none";
window.GrcanApi.setLocalCandoText(null);
refSelect.disabled = false;
updateLocationState(currentRef);
});
}

Expand Down
Loading