Files
gem5/util/gem5-resources-manager/static/js/app.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

136 lines
5.1 KiB
JavaScript

const loadingContainer = document.getElementById("loading-container");
const alertPlaceholder = document.getElementById('liveAlertPlaceholder');
const interactiveElems = document.querySelectorAll('button, input, select');
const appendAlert = (errorHeader, id, message, type) => {
const alertDiv = document.createElement('div');
alertDiv.classList.add("alert", `alert-${type}`, "alert-dismissible", "fade", "show", "d-flex", "flex-column", "shadow-sm");
alertDiv.setAttribute("role", "alert");
alertDiv.setAttribute("id", id);
alertDiv.style.maxWidth = "320px";
alertDiv.innerHTML = [
` <div class="d-flex align-items-center main-text-semi">`,
` <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1.5rem" class="bi bi-exclamation-octagon-fill me-3" viewBox="0 0 16 16">`,
` <path d="M11.46.146A.5.5 0 0 0 11.107 0H4.893a.5.5 0 0 0-.353.146L.146 4.54A.5.5 0 0 0 0 4.893v6.214a.5.5 0 0 0 .146.353l4.394 4.394a.5.5 0 0 0
.353.146h6.214a.5.5 0 0 0 .353-.146l4.394-4.394a.5.5 0 0 0 .146-.353V4.893a.5.5 0 0 0-.146-.353L11.46.146zM8 4c.535 0 .954.462.9.995l-.35
3.507a.552.552 0 0 1-1.1 0L7.1 4.995A.905.905 0 0 1 8 4zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>`,
` </svg>`,
` <span class="main-text-regular">${errorHeader}</span>`,
` <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>`,
` </div>`,
` <hr />`,
` <div>${message}</div>`,
].join('');
window.scrollTo(0, 0);
alertPlaceholder.append(alertDiv);
setTimeout(function () {
bootstrap.Alert.getOrCreateInstance(document.getElementById(`${id}`)).close();
}, 5000);
}
function toggleInteractables(isBlocking, excludedOnNotBlockingIds = [], otherBlockingUpdates = () => {}) {
if (isBlocking) {
loadingContainer.classList.add("d-flex");
interactiveElems.forEach(elems => {
elems.disabled = true;
});
window.scrollTo(0, 0);
otherBlockingUpdates();
return;
}
setTimeout(() => {
loadingContainer.classList.remove("d-flex");
interactiveElems.forEach(elems => {
!excludedOnNotBlockingIds.includes(elems.id) ? elems.disabled = false : null;
});
otherBlockingUpdates();
}, 250);
}
function showResetSavedSessionsModal() {
let sessions = localStorage.getItem("sessions");
if (sessions === null) {
appendAlert('Error!', 'noSavedSessions', `No Saved Sessions Exist!`, 'danger');
return;
}
sessions = JSON.parse(sessions);
const resetSavedSessionsModal = new bootstrap.Modal(document.getElementById('resetSavedSessionsModal'), {
focus: true, keyboard: false
});
let select = document.getElementById("delete-session-dropdown");
select.innerHTML = "";
Object.keys(sessions).forEach((alias) => {
let option = document.createElement("option");
option.value = alias;
option.innerHTML = alias;
select.appendChild(option);
});
document.getElementById("selected-session").innerText = `"${document.getElementById("delete-session-dropdown").value}"`;
resetSavedSessionsModal.show();
}
function resetSavedSessions() {
bootstrap.Modal.getInstance(document.getElementById("resetSavedSessionsModal")).hide();
const sessions = JSON.parse(localStorage.getItem("sessions"));
if (sessions === null) {
appendAlert('Error!', 'noSavedSessions', `No Saved Sessions Exist!`, 'danger');
return;
}
const activeTab = document.getElementById("reset-tabs").querySelector(".nav-link.active").getAttribute("id");
if (activeTab === "delete-one-tab") {
const deleteOneConfirmation = document.getElementById("delete-one-confirmation").value;
if (deleteOneConfirmation !== document.getElementById("delete-session-dropdown").value) {
document.getElementById("resetSavedSessionsModal").querySelectorAll("form").forEach(form => {
form.reset();
})
appendAlert('Error!', 'noSavedSessions', `Invalid Confirmation Entry!`, 'danger');
return;
}
delete sessions[document.getElementById("delete-session-dropdown").value];
Object.keys(sessions).length === 0
? localStorage.removeItem("sessions")
: localStorage.setItem("sessions", JSON.stringify(sessions));
} else {
const deleteAllConfirmation = document.getElementById("delete-all-confirmation").value;
if (deleteAllConfirmation !== "Delete All") {
document.getElementById("resetSavedSessionsModal").querySelectorAll("form").forEach(form => {
form.reset();
})
appendAlert('Error!', 'noSavedSessions', `Invalid Confirmation Entry!`, 'danger');
return;
}
localStorage.removeItem("sessions");
}
appendAlert('Success!', 'resetCookies', `Saved Session Reset Successful!`, 'success');
setTimeout(() => {
location.reload();
}, 750);
}
document.getElementById("close-reset-modal").addEventListener("click", () => {
document.getElementById("resetSavedSessionsModal").querySelectorAll("form").forEach(form => {
form.reset();
})
});
document.getElementById("delete-session-dropdown").addEventListener("change", () => {
document.getElementById("selected-session").innerText =
`"${document.getElementById("delete-session-dropdown").value}"`;
});