Add syntax highlighting for different runtimes in function history for timer & http functions
This commit is contained in:
@@ -316,7 +316,7 @@ def history(function_id):
|
|||||||
# Fetch the http function to verify ownership
|
# Fetch the http function to verify ownership
|
||||||
http_function = db.execute(
|
http_function = db.execute(
|
||||||
"""
|
"""
|
||||||
SELECT id, name, script_content AS code, version_number
|
SELECT id, name, script_content AS code, version_number, runtime
|
||||||
FROM http_functions
|
FROM http_functions
|
||||||
WHERE id = %s AND user_id = %s
|
WHERE id = %s AND user_id = %s
|
||||||
""",
|
""",
|
||||||
@@ -350,6 +350,7 @@ def history(function_id):
|
|||||||
"function_id": function_id,
|
"function_id": function_id,
|
||||||
"http_function": http_function,
|
"http_function": http_function,
|
||||||
"versions": versions,
|
"versions": versions,
|
||||||
|
"runtime": http_function.get("runtime", "node"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if htmx:
|
if htmx:
|
||||||
@@ -359,6 +360,7 @@ def history(function_id):
|
|||||||
return render_template("dashboard/http_functions/history.html", **args)
|
return render_template("dashboard/http_functions/history.html", **args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@http.route("/editor/<int:function_id>", methods=["GET"])
|
@http.route("/editor/<int:function_id>", methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
def editor(function_id):
|
def editor(function_id):
|
||||||
|
|||||||
@@ -561,7 +561,7 @@ def logs(function_id):
|
|||||||
def history(function_id):
|
def history(function_id):
|
||||||
# Fetch the timer function to verify ownership
|
# Fetch the timer function to verify ownership
|
||||||
timer_function = db.execute("""
|
timer_function = db.execute("""
|
||||||
SELECT id, name, code AS script, version_number
|
SELECT id, name, code AS script, version_number, runtime
|
||||||
FROM timer_functions
|
FROM timer_functions
|
||||||
WHERE id = %s AND user_id = %s
|
WHERE id = %s AND user_id = %s
|
||||||
""", [function_id, current_user.id], one=True)
|
""", [function_id, current_user.id], one=True)
|
||||||
@@ -587,7 +587,8 @@ def history(function_id):
|
|||||||
'function_id': function_id,
|
'function_id': function_id,
|
||||||
'timer_function': timer_function,
|
'timer_function': timer_function,
|
||||||
'versions': versions,
|
'versions': versions,
|
||||||
'title': timer_function['name']
|
'title': timer_function['name'],
|
||||||
|
'runtime': timer_function.get('runtime', 'node'),
|
||||||
}
|
}
|
||||||
|
|
||||||
if htmx:
|
if htmx:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const FunctionHistory = {
|
|||||||
vnode.state.rightVersion = versions[0];
|
vnode.state.rightVersion = versions[0];
|
||||||
vnode.state.editor = null;
|
vnode.state.editor = null;
|
||||||
vnode.state.aceDiffer = null;
|
vnode.state.aceDiffer = null;
|
||||||
|
vnode.state.runtime = vnode.attrs.runtime || "node"; // Add runtime support
|
||||||
|
|
||||||
// Listen for theme changes
|
// Listen for theme changes
|
||||||
vnode.state.themeListener = (e) => {
|
vnode.state.themeListener = (e) => {
|
||||||
@@ -152,7 +153,8 @@ const FunctionHistory = {
|
|||||||
if (!vnode.state.editor) {
|
if (!vnode.state.editor) {
|
||||||
vnode.state.editor = ace.edit("editor-history");
|
vnode.state.editor = ace.edit("editor-history");
|
||||||
vnode.state.editor.setTheme(theme);
|
vnode.state.editor.setTheme(theme);
|
||||||
vnode.state.editor.session.setMode("ace/mode/javascript");
|
const editorMode = vnode.state.runtime === "python" ? "ace/mode/python" : "ace/mode/javascript";
|
||||||
|
vnode.state.editor.session.setMode(editorMode);
|
||||||
vnode.state.editor.setReadOnly(true);
|
vnode.state.editor.setReadOnly(true);
|
||||||
} else {
|
} else {
|
||||||
vnode.state.editor.setTheme(theme);
|
vnode.state.editor.setTheme(theme);
|
||||||
@@ -167,9 +169,10 @@ const FunctionHistory = {
|
|||||||
if (vnode.state.aceDiffer) {
|
if (vnode.state.aceDiffer) {
|
||||||
vnode.state.aceDiffer.destroy();
|
vnode.state.aceDiffer.destroy();
|
||||||
}
|
}
|
||||||
|
const diffMode = vnode.state.runtime === "python" ? "ace/mode/python" : "ace/mode/javascript";
|
||||||
vnode.state.aceDiffer = new AceDiff({
|
vnode.state.aceDiffer = new AceDiff({
|
||||||
element: "#diff-container",
|
element: "#diff-container",
|
||||||
mode: "ace/mode/javascript",
|
mode: diffMode,
|
||||||
theme: theme,
|
theme: theme,
|
||||||
left: { content: leftVersion.script, editable: false },
|
left: { content: leftVersion.script, editable: false },
|
||||||
right: { content: rightVersion.script, editable: false },
|
right: { content: rightVersion.script, editable: false },
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ history_url=url_for('http.history', function_id=function_id)) }}
|
|||||||
view: () => m(FunctionHistory, {
|
view: () => m(FunctionHistory, {
|
||||||
versions: {{ versions| tojson | safe }},
|
versions: {{ versions| tojson | safe }},
|
||||||
function_id: {{ function_id }},
|
function_id: {{ function_id }},
|
||||||
restore_url: "{{ url_for('http.restore', function_id=function_id) }}"
|
restore_url: "{{ url_for('http.restore', function_id=function_id) }}",
|
||||||
|
runtime: "{{ runtime }}"
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ history_url=url_for('timer.history', function_id=function_id))
|
|||||||
view: () => m(FunctionHistory, {
|
view: () => m(FunctionHistory, {
|
||||||
versions: {{ versions| tojson | safe }},
|
versions: {{ versions| tojson | safe }},
|
||||||
function_id: {{ function_id }},
|
function_id: {{ function_id }},
|
||||||
restore_url: "{{ url_for('timer.restore', function_id=function_id) }}"
|
restore_url: "{{ url_for('timer.restore', function_id=function_id) }}",
|
||||||
|
runtime: "{{ runtime }}"
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user