Further refactor, still need to cleanup db.py

This commit is contained in:
Peter Stockings
2025-07-21 23:25:25 +10:00
parent 2ec44252bb
commit f55f50d0dc
11 changed files with 130 additions and 389 deletions

View File

@@ -33,10 +33,9 @@
Home
</a><a
class="flex items-center gap-3 rounded-lg px-3 py-2 text-gray-500 transition-all hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-50 cursor-pointer"
data-id="15" hx-get="{{ url_for('http.dashboard_http_functions') }}" hx-target="#container"
hx-swap="innerHTML" hx-push-url="true"><svg xmlns="http://www.w3.org/2000/svg" width="18"
height="18" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
class="size-6">
data-id="15" hx-get="{{ url_for('http.overview') }}" hx-target="#container" hx-swap="innerHTML"
hx-push-url="true"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="none"
viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="M12 21a9.004 9.004 0 0 0 8.716-6.747M12 21a9.004 9.004 0 0 1-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 0 1 7.843 4.582M12 3a8.997 8.997 0 0 0-7.843 4.582m15.686 0A11.953 11.953 0 0 1 12 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0 1 21 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0 1 12 16.5c-3.162 0-6.133-.815-8.716-2.247m0 0A9.015 9.015 0 0 1 3 12c0-1.605.42-3.113 1.157-4.418" />
</svg>

View File

@@ -270,7 +270,7 @@
class="inline-flex items-center justify-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors duration-200">
View Timer Functions
</a>
<a href="{{ url_for('http.dashboard_http_functions') }}"
<a href="{{ url_for('http.overview') }}"
class="inline-flex items-center justify-center px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white font-medium rounded-lg transition-colors duration-200">
View HTTP Functions
</a>

View File

@@ -8,10 +8,10 @@ show_edit_form=True,
show_logs=True,
show_client=True,
show_history=True,
edit_url=url_for('http.http_function_editor', function_id=function_id),
cancel_url=url_for('http.dashboard_http_functions'),
logs_url=url_for('http.get_http_function_logs', function_id=function_id),
history_url=url_for('http.get_http_function_history', function_id=function_id)) }}
edit_url=url_for('http.editor', function_id=function_id),
cancel_url=url_for('http.overview'),
logs_url=url_for('http.logs', function_id=function_id),
history_url=url_for('http.history', function_id=function_id)) }}
<div class="mx-auto w-full pt-4" id="client-u{{ user_id }}-f{{ function_id }}">
</div>

View File

@@ -10,8 +10,8 @@ show_client=True,
show_history=True,
edit_url=edit_url,
cancel_url=cancel_url,
logs_url=url_for('http.get_http_function_logs', function_id=function_id),
history_url=url_for('http.get_http_function_history', function_id=function_id)) }}
logs_url=url_for('http.logs', function_id=function_id),
history_url=url_for('http.history', function_id=function_id)) }}
<div id="app" class="p-1">
@@ -33,8 +33,9 @@ history_url=url_for('http.get_http_function_history', function_id=function_id))
logResponse: {{ log_response | tojson }},
versionNumber: {{ version_number }},
executeUrl: "{{ url_for('execute_code', playground='true') }}",
saveUrl: "{{ url_for('http.api_update_http_function', function_id=id) if id else url_for('http.api_create_http_function') }}",
deleteUrl: "{{ url_for('http.api_delete_http_function', function_id=id) if id else '' }}",
saveUrl: "{{ url_for('http.edit', function_id=id) if id else url_for('http.new') }}",
deleteUrl: "{{ url_for('http.delete', function_id=id) if id else '' }}",
cancelUrl: "{{ url_for('http.overview') }}",
showDeleteButton: true
})
})

View File

@@ -8,196 +8,17 @@ show_edit_form=True,
show_logs=True,
show_client=True,
show_history=True,
edit_url=url_for('http.http_function_editor', function_id=function_id),
cancel_url=url_for('http.dashboard_http_functions'),
logs_url=url_for('http.get_http_function_logs', function_id=function_id),
history_url=url_for('http.get_http_function_history', function_id=function_id)) }}
<!-- Timeline -->
<div>
{% if http_function.version_number > 1 %}
{% for entry in http_function_history %}
<!-- Item -->
<div class="flex gap-x-3">
<!-- Left Content -->
<div class="w-24 text-end">
<span class="text-xs text-gray-500">{{ entry.updated_at.strftime('%b %d %Y %I:%M %p').lstrip("0").replace("
0", " ") }}
</span>
</div>
<!-- End Left Content -->
<!-- Icon -->
<div
class="relative last:after:hidden after:absolute after:top-7 after:bottom-0 after:start-3.5 after:w-px after:-translate-x-[0.5px] after:bg-gray-200">
<div class="relative z-10 size-7 flex justify-center items-center">
<div class="size-2 rounded-full bg-gray-400"></div>
</div>
</div>
<!-- End Icon -->
<!-- Right Content -->
<div class="grow pt-0.5 pb-4 cursor-pointer">
<h3 class="flex gap-x-1.5 font-semibold text-gray-800">
v{{ entry.version_number }}
</h3>
<p class="mt-1 text-sm text-gray-600">
</p>
<button type="button"
class="mt-1 -ms-1 p-1 inline-flex items-center gap-x-2 text-xs rounded-lg border border-transparent text-gray-500 hover:bg-gray-100 disabled:opacity-50 disabled:pointer-events-none">
Revert
</button>
</div>
<!-- End Right Content -->
</div>
<div class="block">
<div id="diff_{{ entry.version_id }}" class="relative h-80"></div>
</div>
<script>
(function () {
// Assigning JSON content to a JavaScript variable
var preContent = '{{ entry.pre | tojson | safe }}';
var postContent = '{{ entry.post | tojson | safe }}';
var aceDiffer = new AceDiff({
element: '#diff_{{ entry.version_id }}',
mode: "ace/mode/javascript",
left: {
content: preContent,
editable: false,
},
right: {
content: postContent,
editable: false,
},
});
// Retrieve the individual editors
var editors = aceDiffer.getEditors();
// Set the maxLines property on each editor
editors.left.setOptions({
maxLines: 20, // Set the maximum number of lines
autoScrollEditorIntoView: true,
});
editors.left.session.setOption("useWorker", false);
editors.right.setOptions({
maxLines: 20, // Set the maximum number of lines
autoScrollEditorIntoView: true,
});
editors.right.session.setOption("useWorker", false);
})();
</script>
<!-- End Item -->
{% endfor %}
<!-- Item -->
<div class="flex gap-x-3">
<!-- Left Content -->
<div class="w-24 text-end">
<span class="text-xs text-gray-500">{{ http_function.created_at.strftime('%b %d %Y %I:%M
%p').lstrip("0").replace("
0", " ") }}
</span>
</div>
<!-- End Left Content -->
<!-- Icon -->
<div
class="relative last:after:hidden after:absolute after:top-7 after:bottom-0 after:start-3.5 after:w-px after:-translate-x-[0.5px] after:bg-gray-200">
<div class="relative z-10 size-7 flex justify-center items-center">
<div class="size-2 rounded-full bg-gray-400"></div>
</div>
</div>
<!-- End Icon -->
<!-- Right Content -->
<div class="grow pt-0.5 pb-4 cursor-pointer">
<h3 class="flex gap-x-1.5 font-semibold text-gray-800">
v1
</h3>
<p class="mt-1 text-sm text-gray-600">
</p>
<button type="button"
class="mt-1 -ms-1 p-1 inline-flex items-center gap-x-2 text-xs rounded-lg border border-transparent text-gray-500 hover:bg-gray-100 disabled:opacity-50 disabled:pointer-events-none">
Revert
</button>
</div>
<!-- End Right Content -->
</div>
<div id="diff_1_editor" class="relative rounded-lg shadow-lg p-4 text-opacity-0">{{ original_script }}</div>
<script>
var editor = ace.edit("diff_1_editor");
editor.setOptions({
maxLines: 100
});
editor.setTheme("ace/theme/github_dark");
editor.session.setMode("ace/mode/javascript");
editor.session.$worker.send("changeOptions", [{ asi: true }]);
</script>
<!-- End Item -->
{% else %}
<!-- Item -->
<div class="flex gap-x-3">
<!-- Left Content -->
<div class="w-24 text-end">
<span class="text-xs text-gray-500">{{ http_function.created_at.strftime('%b %d %Y %I:%M
%p').lstrip("0").replace("
0", " ") }}
</span>
</div>
<!-- End Left Content -->
<!-- Icon -->
<div
class="relative last:after:hidden after:absolute after:top-7 after:bottom-0 after:start-3.5 after:w-px after:-translate-x-[0.5px] after:bg-gray-200">
<div class="relative z-10 size-7 flex justify-center items-center">
<div class="size-2 rounded-full bg-gray-400"></div>
</div>
</div>
<!-- End Icon -->
<!-- Right Content -->
<div class="grow pt-0.5 pb-4 cursor-pointer">
<h3 class="flex gap-x-1.5 font-semibold text-gray-800">
v1
</h3>
<p class="mt-1 text-sm text-gray-600">
</p>
<button type="button"
class="mt-1 -ms-1 p-1 inline-flex items-center gap-x-2 text-xs rounded-lg border border-transparent text-gray-500 hover:bg-gray-100 disabled:opacity-50 disabled:pointer-events-none">
Revert
</button>
</div>
<!-- End Right Content -->
</div>
<div id="diff_1_editor" class="relative rounded-lg shadow-lg p-4 text-opacity-0">{{ original_script }}</div>
<script>
var editor = ace.edit("diff_1_editor");
editor.setOptions({
maxLines: 100,
readOnly: true, // Disable editing
highlightActiveLine: false, // Optionally, disable highlighting the active line
highlightGutterLine: false // Optionally, disable highlighting the gutter line
});
editor.setTheme("ace/theme/github_dark");
editor.session.setMode("ace/mode/javascript");
</script>
<!-- End Item -->
{% endif %}
</div>
<!-- End Timeline -->
edit_url=url_for('http.editor', function_id=function_id),
cancel_url=url_for('http.overview'),
logs_url=url_for('http.logs', function_id=function_id),
history_url=url_for('http.history', function_id=function_id)) }}
<div id="version-diff"></div>
<script>
// Mount the Mithril component with versions as an attribute
m.mount(document.getElementById("version-diff"), {
view: () => m(DiffView, { versions: {{ versions| tojson }} })
});
</script>
{% endblock %}

View File

@@ -8,10 +8,10 @@ show_edit_form=True,
show_logs=True,
show_client=True,
show_history=True,
edit_url=url_for('http.http_function_editor', function_id=function_id),
cancel_url=url_for('http.dashboard_http_functions'),
logs_url=url_for('http.get_http_function_logs', function_id=function_id),
history_url=url_for('http.get_http_function_history', function_id=function_id)) }}
edit_url=url_for('http.editor', function_id=function_id),
cancel_url=url_for('http.overview'),
logs_url=url_for('http.logs', function_id=function_id),
history_url=url_for('http.history', function_id=function_id)) }}
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">

View File

@@ -9,8 +9,8 @@ show_refresh=False,
show_logs=False,
show_client=False,
show_link=False,
dashboardUrl=url_for('http.dashboard_http_functions'),
cancel_url=url_for('http.dashboard_http_functions'),
dashboardUrl=url_for('http.overview'),
cancel_url=url_for('http.overview'),
title='New HTTP Function')
}}
@@ -32,9 +32,9 @@ title='New HTTP Function')
logRequest: {{ log_request | tojson }},
logResponse: {{ log_response | tojson }},
executeUrl: "{{ url_for('execute_code', playground='true') }}",
saveUrl: "{{ url_for('http.api_create_http_function') }}",
saveUrl: "{{ url_for('http.new') }}",
showDeleteButton: false,
dashboardUrl: "{{ url_for('http.dashboard_http_functions') }}"
dashboardUrl: "{{ url_for('http.overview') }}"
})
})
</script>

View File

@@ -7,8 +7,7 @@
<h1 class="text-2xl font-bold text-gray-900">HTTP Functions</h1>
<button
class="inline-flex items-center px-4 py-2 ml-auto bg-green-600 hover:bg-green-700 text-white font-medium rounded-lg transition-colors duration-200"
hx-get="{{ url_for('http.get_http_function_add_form') }}" hx-target="#container" hx-swap="innerHTML"
hx-push-url="true">
hx-get="{{ url_for('http.new') }}" hx-target="#container" hx-swap="innerHTML" hx-push-url="true">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-5 h-5 mr-2">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"></path>
@@ -34,8 +33,8 @@
<tr class="hover:bg-gray-50">
<td class="px-6 py-4">
<div class="flex items-center gap-2 cursor-pointer"
hx-get="{{ url_for('http.http_function_editor', function_id=function.id) }}"
hx-target="#container" hx-swap="innerHTML" hx-push-url="true">
hx-get="{{ url_for('http.editor', function_id=function.id) }}" hx-target="#container"
hx-swap="innerHTML" hx-push-url="true">
<span class="font-medium text-gray-900">{{ function.name }}</span>
<span
class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded-full">
@@ -76,8 +75,8 @@
<div class="flex gap-3">
<button
class="inline-flex items-center px-3 py-1.5 text-sm font-medium text-indigo-700 bg-indigo-50 rounded-md hover:bg-indigo-100 transition-colors duration-200"
hx-get="{{ url_for('http.get_http_function_logs', function_id=function.id) }}"
hx-target="#container" hx-swap="innerHTML" hx-push-url="true">
hx-get="{{ url_for('http.logs', function_id=function.id) }}" hx-target="#container"
hx-swap="innerHTML" hx-push-url="true">
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 mr-1.5" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"