Add json object for environment info for each function, this is mutable from custom code

This commit is contained in:
Peter Stockings
2023-12-18 15:15:14 +11:00
parent 538d5083e4
commit 5cc29309d5
5 changed files with 79 additions and 24 deletions

View File

@@ -9,9 +9,10 @@
<div>
<div class="flex space-x-2 p-2 border-b border-gray-200 dark:border-gray-800">
<h1 class="font-semibold text-lg text-gray-400 font-mono flex items-center" data-id="52">Code</h1>
<button
class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 text-gray-600 dark:text-gray-400"
class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 text-gray-600 dark:text-gray-400 justify-between"
id="executeBtn">
<span class="sr-only" data-id="4">Bold</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
@@ -32,10 +33,36 @@
</svg>
</button>
<!-- Spacer Div -->
<div class="flex-auto"></div>
</div>
<div id="editor" class="relative rounded-lg shadow-lg p-4 mb-4">{{ script }}</div>
<div class="flex space-x-2 p-2 border-b border-gray-200 dark:border-gray-800 justify-between">
<h1 class="font-semibold text-lg text-gray-400 font-mono flex items-center" data-id="52">Environment</h1>
<!-- Spacer Div -->
<div class="flex-auto"></div>
</div>
<div id="editor-environment" class="relative rounded-lg shadow-lg p-4 mb-2">{{ environment_info }}</div>
<script>
var editor_environment = ace.edit("editor-environment");
editor_environment.setOptions({
maxLines: 15, //editor_environment.session.getLength()
minLines: 5
});
editor_environment.setTheme("ace/theme/github_dark");
editor_environment.session.setMode("ace/mode/json");
//editor_environment.session.$worker.send("changeOptions", [{ asi: true }]);
</script>
<div class="flex">
<button
class="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded flex mr-2"
@@ -60,9 +87,9 @@
<span>Delete</span>
</button>
</div>
</div>
<div id="output">
@@ -154,13 +181,14 @@
document.querySelector('#add-http-function').addEventListener('click', () => {
let name = '{{ name }}';
let script_content = editor.getValue().trim();
let environment_info = editor_environment.getValue().trim();
fetch("{{ url_for('edit_http_function') }}", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, script_content }),
body: JSON.stringify({ name, script_content, environment_info }),
})
.then(response => response.text())
.then(text => {

View File

@@ -10,6 +10,8 @@
<div>
<div class="flex space-x-2 p-2 border-b border-gray-200 dark:border-gray-800">
<h1 class="font-semibold text-lg text-gray-400 font-mono flex items-center" data-id="52">Code</h1>
<input type="text" id="function-name"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 max-w-fit"
placeholder="foo" required="" value="{{ name }}">
@@ -39,6 +41,28 @@
<div id="editor" class="relative rounded-lg shadow-lg p-4 mb-4">{{ script }}</div>
<div class="flex space-x-2 p-2 border-b border-gray-200 dark:border-gray-800 justify-between">
<h1 class="font-semibold text-lg text-gray-400 font-mono flex items-center" data-id="52">Environment</h1>
<!-- Spacer Div -->
<div class="flex-auto"></div>
</div>
<div id="editor-environment" class="relative rounded-lg shadow-lg p-4 mb-2">{}</div>
<script>
var editor_environment = ace.edit("editor-environment");
editor_environment.setOptions({
maxLines: 15, //editor_environment.session.getLength()
minLines: 5
});
editor_environment.setTheme("ace/theme/github_dark");
editor_environment.session.setMode("ace/mode/json");
//editor_environment.session.$worker.send("changeOptions", [{ asi: true }]);
</script>
<button
class="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded flex"
id="add-http-function">
@@ -141,13 +165,14 @@
document.querySelector('#add-http-function').addEventListener('click', () => {
let name = document.querySelector('#function-name').value;
let script_content = editor.getValue().trim();
let environment_info = editor_environment.getValue().trim();
fetch("{{ url_for('create_http_function') }}", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, script_content }),
body: JSON.stringify({ name, script_content, environment_info }),
})
.then(response => response.text())
.then(text => {