Files
gem5/util/gem5-resources-manager/static/js/index.js
KUNAL PAI 9b9dc09f6e resources: Add the gem5 Resources Manager
A GUI web-based tool to manage gem5 Resources.

Can manage in two data sources,
a MongoDB database or a JSON file.

The JSON file can be both local or remote.

JSON files are written to a temporary file before
writing to the local file.

The Manager supports the following functions
on a high-level:
- searching for a resource by ID
- navigating to a resource version
- adding a new resource
- adding a new version to a resource
- editing any information within a searched resource
(while enforcing the gem5 Resources schema
found at: https://resources.gem5.org/gem5-resources-schema.json)
- deleting a resource version
- undo and redo up to the last 10 operations

The Manager also allows a user to save a session
through localStorage and re-access it through a password securely.

This patch also provides a
Command Line Interface tool mainly for
MongoDB-related functions.

This CLI tool can currently:
- backup a MongoDB collection to a JSON file
- restore a JSON file to a MongoDB collection
- search for a resource through its ID and
view its JSON object
- make a JSON file that is compliant with the
gem5 Resources Schema

Co-authored-by: Parth Shah <helloparthshah@gmail.com>
Co-authored-by: Harshil2107 <harshilp2107@gmail.com>
Co-authored-by: aarsli <arsli@ucdavis.edu>
Change-Id: I8107f609c869300b5323d4942971a7ce7c28d6b5
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/71218
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
2023-07-08 02:01:02 +00:00

76 lines
2.1 KiB
JavaScript

window.onload = () => {
let select = document.getElementById("sessions-dropdown");
const sessions = JSON.parse(localStorage.getItem("sessions"));
if (sessions === null) {
document.getElementById("showSavedSessionModal").disabled = true;
return;
}
Object.keys(sessions).forEach((alias) => {
let option = document.createElement("option");
option.value = alias;
option.innerHTML = alias;
select.appendChild(option);
});
}
const loadSessionBtn = document.getElementById("loadSession");
loadSessionBtn.disabled = true;
let password = document.getElementById("session-password");
password.addEventListener("input", () => {
loadSessionBtn.disabled = password.value === "";
});
document.getElementById("close-load-session-modal").addEventListener("click", () => {
document.getElementById("savedSessionModal").querySelector("form").reset();
})
function showSavedSessionModal() {
const savedSessionModal = new bootstrap.Modal(document.getElementById('savedSessionModal'), { focus: true, keyboard: false });
savedSessionModal.show();
}
function loadSession() {
bootstrap.Modal.getInstance(document.getElementById("savedSessionModal")).hide();
const alias = document.getElementById("sessions-dropdown").value;
const session = JSON.parse(localStorage.getItem("sessions"))[alias];
if (session === null) {
appendAlert("Error!", "sessionNotFound", "Saved Session Not Found!", "danger");
return;
}
toggleInteractables(true);
fetch("/loadSession", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
password: document.getElementById("session-password").value,
alias: alias,
session: session
})
})
.then((res) => {
toggleInteractables(false);
if (res.status !== 200) {
res.json()
.then((error) => {
document.getElementById("savedSessionModal").querySelector("form").reset();
appendAlert("Error!", "invalidStatus", `${error["error"]}`, "danger");
return;
})
}
if (res.redirected) {
window.location = res.url;
}
})
}