lotus/curiosrc/web/static/config/edit.html
Andrew Jackson (Ajax) f5b6c4edc7
curio cfg edit: ux cleanups (#11985)
* fixed popper and bools

* local fonts

* dark select boxes
2024-05-10 11:24:14 -05:00

165 lines
6.7 KiB
HTML

<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<title>JSON Schema Editor</title>
<script type="module" src="/ux/curio-ux.mjs"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@2.14.0/dist/jsoneditor.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/ui-darkness/jquery-ui.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/ui-darkness/theme.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body style="visibility: hidden;">
<style>
#saveButton {
display: block;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
font-size: 18px;
border: none;
outline: none;
background-color: green;
color: white;
cursor: pointer;
padding: 15px;
border-radius: 4px;
}
#saveButton:hover {
background-color: #555;
}
.help-button button {
font-size: 24px;
border-radius: 50%;
width: 50px;
height: 50px;
position: fixed;
bottom: 20px;
right: 120px;
z-index: 99;
}
.help-text {
display: none;
position: fixed;
border: 1px solid #ccc;
background-color: gray;
padding: 10px;
width: 200px;
bottom: 20px;
right: 200px;
z-index: 100;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.hidden {
display: none;
}
.show {
display: block;
}
/* Fix for dark mode */
.card.bg-light {
background-color: rgb(11, 22, 34) !important;
}
input.form-control {
background: #111;
color: white;
font-weight: bold;
}
</style>
<curio-ux>
<section class="section container-fluid implementations">
<div class="row justify-content-center content">
<div class="col-md-8">
<div>
<button id="saveButton" class="saveButton">Save</button>
</div>
<div class="help-button">
<button id="helpBtn">?</button>
<p id="helpText" class="hidden help-text">Checking a box and entering a non default value will uncomment the corresponding configuration variable.
Unchecking a box will reset the value to default.</p>
</div>
<div id="editor" data-bs-theme="dark"></div>
<script>
var editor;
var urlParams = new URLSearchParams(window.location.search);
var layer = urlParams.get('layer');
// Make simultaneous GET requests to fetch the existing data and JSON Schema
const layerPath = layer === 'default' ? 'config/default' : `config/layers/${layer}`;
Promise.all([
axios.get(`/api/${layerPath}`),
axios.get('/api/config/schema')
])
.then(responses => {
const existingData = responses[0].data;
const schema = responses[1].data;
// Create a JSON Editor instance and pass the schema and existing data
const container = document.getElementById('editor');
const options = {
//mode: 'tree',
schema: schema,
startval: existingData,
theme: 'bootstrap5',
iconlib: 'jqueryui',
show_opt_in: true,
disable_edit_json: true,
form_name_root: "Configuration",
disable_properties: true,
};
editor = new JSONEditor(container, options);
document.getElementById("helpBtn").addEventListener("click", function() {
var helpText = document.getElementById("helpText");
if (helpText.classList.contains("hidden")) {
helpText.classList.remove("hidden");
helpText.classList.add("show");
} else {
helpText.classList.remove("show");
helpText.classList.add("hidden");
}
});
// Attach function to saveButton click event
var saveButton = document.getElementById('saveButton');
saveButton.addEventListener('click', function() {
if (layer === 'default'){
alert('Error: cannot edit defaults');
} else {
const value = editor.getValue();
console.log(value)
axios.post('/api/config/layers/' + layer, value)
.then(response => {
// Set cookie named 'message' with the value 'Data saved successfully'
document.cookie = 'message=The layer "' + layer + '" saved successfully.; path=/;';
window.location.href = '/config/';
})
.catch(error => {
alert('Error saving data:', error);
});
}
});
})
.catch(error => {
console.error('Error fetching data:', error);
});
</script>
</div>
</div>
</section></curio-ux>
</body>
</html>