Update http functions overview page to show functions in searchable nested directory
This commit is contained in:
31
db.py
31
db.py
@@ -57,32 +57,41 @@ class DataBase():
|
|||||||
finally:
|
finally:
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
def get_http_functions_for_user(self, user_id):
|
def get_http_functions_for_user(self, user_id, search_query=None):
|
||||||
http_functions = self.execute(
|
if search_query:
|
||||||
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, runtime FROM http_functions WHERE user_id=%s ORDER by id DESC', [user_id])
|
search_pattern = f"%{search_query}%"
|
||||||
|
http_functions = self.execute(
|
||||||
|
'SELECT id, user_id, NAME, path, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, runtime FROM http_functions WHERE user_id=%s AND (NAME ILIKE %s OR path ILIKE %s) ORDER by id DESC',
|
||||||
|
[user_id, search_pattern, search_pattern]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
http_functions = self.execute(
|
||||||
|
'SELECT id, user_id, NAME, path, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, runtime FROM http_functions WHERE user_id=%s ORDER by id DESC',
|
||||||
|
[user_id]
|
||||||
|
)
|
||||||
return http_functions
|
return http_functions
|
||||||
|
|
||||||
def get_http_function(self, user_id, name):
|
def get_http_function(self, user_id, name):
|
||||||
http_function = self.execute(
|
http_function = self.execute(
|
||||||
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, created_at, runtime FROM http_functions WHERE user_id=%s AND NAME=%s', [user_id, name], one=True)
|
'SELECT id, user_id, NAME, path, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, created_at, runtime FROM http_functions WHERE user_id=%s AND NAME=%s', [user_id, name], one=True)
|
||||||
return http_function
|
return http_function
|
||||||
|
|
||||||
def get_http_function_by_id(self, user_id, http_function_id):
|
def get_http_function_by_id(self, user_id, http_function_id):
|
||||||
http_function = self.execute(
|
http_function = self.execute(
|
||||||
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, created_at, runtime FROM http_functions WHERE user_id=%s AND id=%s', [user_id, http_function_id], one=True)
|
'SELECT id, user_id, NAME, path, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, created_at, runtime FROM http_functions WHERE user_id=%s AND id=%s', [user_id, http_function_id], one=True)
|
||||||
return http_function
|
return http_function
|
||||||
|
|
||||||
def create_new_http_function(self, user_id, name, script_content, environment_info, is_public, log_request, log_response, runtime):
|
def create_new_http_function(self, user_id, name, path, script_content, environment_info, is_public, log_request, log_response, runtime):
|
||||||
self.execute(
|
self.execute(
|
||||||
'INSERT INTO http_functions (user_id, NAME, script_content, environment_info, is_public, log_request, log_response, runtime) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
|
'INSERT INTO http_functions (user_id, NAME, path, script_content, environment_info, is_public, log_request, log_response, runtime) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)',
|
||||||
[user_id, name, script_content, environment_info, is_public, log_request, log_response, runtime],
|
[user_id, name, path, script_content, environment_info, is_public, log_request, log_response, runtime],
|
||||||
commit=True
|
commit=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def edit_http_function(self, user_id, function_id, name, script_content, environment_info, is_public, log_request, log_response, runtime):
|
def edit_http_function(self, user_id, function_id, name, path, script_content, environment_info, is_public, log_request, log_response, runtime):
|
||||||
updated_version = self.execute(
|
updated_version = self.execute(
|
||||||
'UPDATE http_functions SET NAME=%s, script_content=%s, environment_info=%s, is_public=%s, log_request=%s, log_response=%s, runtime=%s WHERE user_id=%s AND id=%s RETURNING version_number',
|
'UPDATE http_functions SET NAME=%s, path=%s, script_content=%s, environment_info=%s, is_public=%s, log_request=%s, log_response=%s, runtime=%s WHERE user_id=%s AND id=%s RETURNING version_number',
|
||||||
[name, script_content, environment_info, is_public, log_request, log_response, runtime, user_id, function_id],
|
[name, path, script_content, environment_info, is_public, log_request, log_response, runtime, user_id, function_id],
|
||||||
commit=True, one=True
|
commit=True, one=True
|
||||||
)
|
)
|
||||||
return updated_version
|
return updated_version
|
||||||
|
|||||||
278
routes/http.py
278
routes/http.py
@@ -7,7 +7,7 @@ from datetime import datetime, timezone, timedelta
|
|||||||
import json
|
import json
|
||||||
from services import create_http_function_view_model, create_http_functions_view_model
|
from services import create_http_function_view_model, create_http_functions_view_model
|
||||||
|
|
||||||
'''
|
"""
|
||||||
CREATE TABLE http_function_versions (
|
CREATE TABLE http_function_versions (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
http_function_id INT NOT NULL,
|
http_function_id INT NOT NULL,
|
||||||
@@ -66,7 +66,7 @@ AFTER INSERT OR UPDATE
|
|||||||
ON http_functions
|
ON http_functions
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE PROCEDURE fn_http_functions_versioning();
|
EXECUTE PROCEDURE fn_http_functions_versioning();
|
||||||
'''
|
"""
|
||||||
|
|
||||||
DEFAULT_SCRIPT = """async (req) => {
|
DEFAULT_SCRIPT = """async (req) => {
|
||||||
console.log(`Method:${req.method}`)
|
console.log(`Method:${req.method}`)
|
||||||
@@ -104,18 +104,52 @@ DEFAULT_PYTHON_SCRIPT = """def main(request, environment):
|
|||||||
return {"body": "Hello from Python!"}
|
return {"body": "Hello from Python!"}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
http = Blueprint('http', __name__)
|
http = Blueprint("http", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
def group_functions_by_path(functions):
|
||||||
|
grouped = {}
|
||||||
|
for function in functions:
|
||||||
|
# Use the explicit path column
|
||||||
|
full_path = function.get("path", "") or ""
|
||||||
|
path_parts = [p for p in full_path.split("/") if p]
|
||||||
|
|
||||||
|
current_level = grouped
|
||||||
|
for part in path_parts:
|
||||||
|
if part not in current_level:
|
||||||
|
current_level[part] = {}
|
||||||
|
current_level = current_level[part]
|
||||||
|
|
||||||
|
function["_is_function"] = True
|
||||||
|
current_level[function["name"]] = function
|
||||||
|
return grouped
|
||||||
|
|
||||||
@http.route("/overview", methods=["GET"])
|
@http.route("/overview", methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
def overview():
|
def overview():
|
||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
http_functions = db.get_http_functions_for_user(user_id)
|
search_query = request.args.get("q", "")
|
||||||
http_functions = create_http_functions_view_model(http_functions)
|
|
||||||
if htmx:
|
http_functions = db.get_http_functions_for_user(user_id, search_query)
|
||||||
return render_block(environment, "dashboard/http_functions/overview.html", "page", http_functions=http_functions)
|
http_functions_view_model = create_http_functions_view_model(http_functions)
|
||||||
return render_template("dashboard/http_functions/overview.html", http_functions=http_functions)
|
grouped_functions = group_functions_by_path(http_functions_view_model)
|
||||||
|
|
||||||
|
if request.headers.get('HX-Target') == 'function-list':
|
||||||
|
return render_block(environment, "dashboard/http_functions/overview.html", "function_list", http_functions=grouped_functions)
|
||||||
|
|
||||||
|
if htmx:
|
||||||
|
return render_block(
|
||||||
|
environment,
|
||||||
|
"dashboard/http_functions/overview.html",
|
||||||
|
"page",
|
||||||
|
http_functions=grouped_functions,
|
||||||
|
search_query=search_query
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"dashboard/http_functions/overview.html",
|
||||||
|
http_functions=grouped_functions,
|
||||||
|
search_query=search_query
|
||||||
|
)
|
||||||
|
|
||||||
@http.route("/new", methods=["GET", "POST"])
|
@http.route("/new", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@@ -123,36 +157,52 @@ def new():
|
|||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
context = {
|
context = {
|
||||||
'user_id': user_id,
|
"user_id": user_id,
|
||||||
'name': 'foo',
|
"name": "foo",
|
||||||
'script': DEFAULT_SCRIPT,
|
"path": "",
|
||||||
'default_python_script': DEFAULT_PYTHON_SCRIPT,
|
"script": DEFAULT_SCRIPT,
|
||||||
'environment_info': DEFAULT_ENVIRONMENT,
|
"default_python_script": DEFAULT_PYTHON_SCRIPT,
|
||||||
'is_public': False,
|
"environment_info": DEFAULT_ENVIRONMENT,
|
||||||
'log_request': True,
|
"is_public": False,
|
||||||
'log_response': False
|
"log_request": True,
|
||||||
|
"log_response": False,
|
||||||
}
|
}
|
||||||
if htmx:
|
if htmx:
|
||||||
return render_block(environment, 'dashboard/http_functions/new.html', 'page', **context)
|
return render_block(
|
||||||
|
environment, "dashboard/http_functions/new.html", "page", **context
|
||||||
|
)
|
||||||
return render_template("dashboard/http_functions/new.html", **context)
|
return render_template("dashboard/http_functions/new.html", **context)
|
||||||
try:
|
try:
|
||||||
name = request.json.get('name')
|
name = request.json.get("name")
|
||||||
script_content = request.json.get('script_content')
|
path = request.json.get("path", "")
|
||||||
environment_info = request.json.get('environment_info')
|
script_content = request.json.get("script_content")
|
||||||
is_public = request.json.get('is_public')
|
environment_info = request.json.get("environment_info")
|
||||||
log_request = request.json.get('log_request')
|
is_public = request.json.get("is_public")
|
||||||
log_response = request.json.get('log_response')
|
log_request = request.json.get("log_request")
|
||||||
runtime = request.json.get('runtime', 'node')
|
log_response = request.json.get("log_response")
|
||||||
|
runtime = request.json.get("runtime", "node")
|
||||||
db.create_new_http_function(user_id, name, script_content, environment_info, is_public, log_request, log_response, runtime)
|
|
||||||
|
|
||||||
return jsonify({
|
db.create_new_http_function(
|
||||||
"status": "success",
|
user_id,
|
||||||
"message": "Http function created successfully"
|
name,
|
||||||
}), 200
|
path,
|
||||||
|
script_content,
|
||||||
|
environment_info,
|
||||||
|
is_public,
|
||||||
|
log_request,
|
||||||
|
log_response,
|
||||||
|
runtime,
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
jsonify(
|
||||||
|
{"status": "success", "message": "Http function created successfully"}
|
||||||
|
),
|
||||||
|
200,
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return { "status": "error", "message": str(e) }
|
return {"status": "error", "message": str(e)}
|
||||||
|
|
||||||
|
|
||||||
@http.route("/edit/<int:function_id>", methods=["POST"])
|
@http.route("/edit/<int:function_id>", methods=["POST"])
|
||||||
@@ -160,20 +210,33 @@ def new():
|
|||||||
def edit(function_id):
|
def edit(function_id):
|
||||||
try:
|
try:
|
||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
name = request.json.get('name')
|
name = request.json.get("name")
|
||||||
script_content = request.json.get('script_content')
|
path = request.json.get("path", "")
|
||||||
environment_info = request.json.get('environment_info')
|
script_content = request.json.get("script_content")
|
||||||
is_public = request.json.get('is_public')
|
environment_info = request.json.get("environment_info")
|
||||||
log_request = request.json.get('log_request')
|
is_public = request.json.get("is_public")
|
||||||
log_response = request.json.get('log_response')
|
log_request = request.json.get("log_request")
|
||||||
runtime = request.json.get('runtime', 'node')
|
log_response = request.json.get("log_response")
|
||||||
|
runtime = request.json.get("runtime", "node")
|
||||||
updated_version = db.edit_http_function(user_id, function_id, name, script_content, environment_info, is_public, log_request, log_response, runtime)
|
|
||||||
|
|
||||||
return { "status": "success", "message": f'{name} updated' }
|
updated_version = db.edit_http_function(
|
||||||
|
user_id,
|
||||||
|
function_id,
|
||||||
|
name,
|
||||||
|
path,
|
||||||
|
script_content,
|
||||||
|
environment_info,
|
||||||
|
is_public,
|
||||||
|
log_request,
|
||||||
|
log_response,
|
||||||
|
runtime,
|
||||||
|
)
|
||||||
|
|
||||||
|
return {"status": "success", "message": f"{name} updated"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return { "status": "error", "message": str(e) }
|
return {"status": "error", "message": str(e)}
|
||||||
|
|
||||||
|
|
||||||
@http.route("/delete/<int:function_id>", methods=["DELETE"])
|
@http.route("/delete/<int:function_id>", methods=["DELETE"])
|
||||||
@login_required
|
@login_required
|
||||||
@@ -182,11 +245,15 @@ def delete(function_id):
|
|||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
|
|
||||||
db.execute(
|
db.execute(
|
||||||
'DELETE FROM http_functions WHERE user_id=%s AND id=%s', [user_id, function_id], commit=True)
|
"DELETE FROM http_functions WHERE user_id=%s AND id=%s",
|
||||||
|
[user_id, function_id],
|
||||||
return { "status": "success", "message": f'Function deleted' }
|
commit=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
return {"status": "success", "message": f"Function deleted"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"status": 'error', "message": str(e)}), 500
|
return jsonify({"status": "error", "message": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
@http.route("/logs/<int:function_id>", methods=["GET"])
|
@http.route("/logs/<int:function_id>", methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
@@ -194,12 +261,27 @@ def logs(function_id):
|
|||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
http_function = db.get_http_function_by_id(user_id, function_id)
|
http_function = db.get_http_function_by_id(user_id, function_id)
|
||||||
if not http_function:
|
if not http_function:
|
||||||
return jsonify({'error': 'Function not found'}), 404
|
return jsonify({"error": "Function not found"}), 404
|
||||||
name = http_function['name']
|
name = http_function["name"]
|
||||||
http_function_invocations = db.get_http_function_invocations(function_id)
|
http_function_invocations = db.get_http_function_invocations(function_id)
|
||||||
if htmx:
|
if htmx:
|
||||||
return render_block(environment, 'dashboard/http_functions/logs.html', 'page', user_id=user_id, function_id=function_id, name=name, http_function_invocations=http_function_invocations)
|
return render_block(
|
||||||
return render_template("dashboard/http_functions/logs.html", user_id=user_id, name=name, function_id=function_id, http_function_invocations=http_function_invocations)
|
environment,
|
||||||
|
"dashboard/http_functions/logs.html",
|
||||||
|
"page",
|
||||||
|
user_id=user_id,
|
||||||
|
function_id=function_id,
|
||||||
|
name=name,
|
||||||
|
http_function_invocations=http_function_invocations,
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"dashboard/http_functions/logs.html",
|
||||||
|
user_id=user_id,
|
||||||
|
name=name,
|
||||||
|
function_id=function_id,
|
||||||
|
http_function_invocations=http_function_invocations,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@http.route("/client/<int:function_id>", methods=["GET"])
|
@http.route("/client/<int:function_id>", methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
@@ -207,49 +289,70 @@ def client(function_id):
|
|||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
http_function = db.get_http_function_by_id(user_id, function_id)
|
http_function = db.get_http_function_by_id(user_id, function_id)
|
||||||
if not http_function:
|
if not http_function:
|
||||||
return jsonify({'error': 'Function not found'}), 404
|
return jsonify({"error": "Function not found"}), 404
|
||||||
|
|
||||||
http_function = create_http_function_view_model(http_function)
|
http_function = create_http_function_view_model(http_function)
|
||||||
if htmx:
|
if htmx:
|
||||||
return render_block(environment, 'dashboard/http_functions/client.html', 'page', function_id=function_id, **http_function)
|
return render_block(
|
||||||
return render_template("dashboard/http_functions/client.html", function_id=function_id, **http_function)
|
environment,
|
||||||
|
"dashboard/http_functions/client.html",
|
||||||
|
"page",
|
||||||
|
function_id=function_id,
|
||||||
|
**http_function,
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"dashboard/http_functions/client.html", function_id=function_id, **http_function
|
||||||
|
)
|
||||||
|
|
||||||
@http.route('/history/<int:function_id>')
|
|
||||||
|
@http.route("/history/<int:function_id>")
|
||||||
@login_required
|
@login_required
|
||||||
def history(function_id):
|
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
|
||||||
FROM http_functions
|
FROM http_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,
|
||||||
|
)
|
||||||
|
|
||||||
if not http_function:
|
if not http_function:
|
||||||
flash('Http function not found', 'error')
|
flash("Http function not found", "error")
|
||||||
return redirect(url_for('http.overview'))
|
return redirect(url_for("http.overview"))
|
||||||
|
|
||||||
# Fetch all versions
|
# Fetch all versions
|
||||||
versions = db.execute("""
|
versions = db.execute(
|
||||||
|
"""
|
||||||
SELECT version_number, script_content AS script, updated_at AS versioned_at
|
SELECT version_number, script_content AS script, updated_at AS versioned_at
|
||||||
FROM http_functions_versions
|
FROM http_functions_versions
|
||||||
WHERE http_function_id = %s
|
WHERE http_function_id = %s
|
||||||
ORDER BY version_number DESC
|
ORDER BY version_number DESC
|
||||||
""", [function_id])
|
""",
|
||||||
|
[function_id],
|
||||||
|
)
|
||||||
|
|
||||||
# Convert datetime objects to ISO format strings
|
# Convert datetime objects to ISO format strings
|
||||||
for version in versions:
|
for version in versions:
|
||||||
version['versioned_at'] = version['versioned_at'].isoformat() if version['versioned_at'] else None
|
version["versioned_at"] = (
|
||||||
|
version["versioned_at"].isoformat() if version["versioned_at"] else None
|
||||||
|
)
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
'user_id': current_user.id,
|
"user_id": current_user.id,
|
||||||
'function_id': function_id,
|
"function_id": function_id,
|
||||||
'http_function': http_function,
|
"http_function": http_function,
|
||||||
'versions': versions
|
"versions": versions,
|
||||||
}
|
}
|
||||||
|
|
||||||
if htmx:
|
if htmx:
|
||||||
return render_block(environment, 'dashboard/http_functions/history.html', 'page', **args)
|
return render_block(
|
||||||
return render_template('dashboard/http_functions/history.html', **args)
|
environment, "dashboard/http_functions/history.html", "page", **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
|
||||||
@@ -257,27 +360,30 @@ def editor(function_id):
|
|||||||
user_id = current_user.id
|
user_id = current_user.id
|
||||||
http_function = db.get_http_function_by_id(user_id, function_id)
|
http_function = db.get_http_function_by_id(user_id, function_id)
|
||||||
if not http_function:
|
if not http_function:
|
||||||
return jsonify({'error': 'Function not found'}), 404
|
return jsonify({"error": "Function not found"}), 404
|
||||||
|
|
||||||
# Create a view model with all necessary data for the editor
|
# Create a view model with all necessary data for the editor
|
||||||
editor_data = {
|
editor_data = {
|
||||||
'id': http_function['id'],
|
"id": http_function["id"],
|
||||||
'name': http_function['name'],
|
"name": http_function["name"],
|
||||||
'script_content': http_function['script_content'],
|
"path": http_function.get("path", ""),
|
||||||
'environment_info': json.dumps(http_function['environment_info'], indent=2),
|
"script_content": http_function["script_content"],
|
||||||
'is_public': http_function['is_public'],
|
"environment_info": json.dumps(http_function["environment_info"], indent=2),
|
||||||
'log_request': http_function['log_request'],
|
"is_public": http_function["is_public"],
|
||||||
'log_response': http_function['log_response'],
|
"log_request": http_function["log_request"],
|
||||||
'version_number': http_function['version_number'],
|
"log_response": http_function["log_response"],
|
||||||
'runtime': http_function.get('runtime', 'node'),
|
"version_number": http_function["version_number"],
|
||||||
'user_id': user_id,
|
"runtime": http_function.get("runtime", "node"),
|
||||||
'function_id': function_id,
|
"user_id": user_id,
|
||||||
|
"function_id": function_id,
|
||||||
# Add new URLs for navigation
|
# Add new URLs for navigation
|
||||||
'cancel_url': url_for('http.overview'),
|
"cancel_url": url_for("http.overview"),
|
||||||
'edit_url': url_for('http.editor', function_id=function_id),
|
"edit_url": url_for("http.editor", function_id=function_id),
|
||||||
}
|
}
|
||||||
|
|
||||||
if htmx:
|
if htmx:
|
||||||
return render_block(environment, "dashboard/http_functions/editor.html", "page", **editor_data)
|
return render_block(
|
||||||
|
environment, "dashboard/http_functions/editor.html", "page", **editor_data
|
||||||
return render_template("dashboard/http_functions/editor.html", **editor_data)
|
)
|
||||||
|
|
||||||
|
return render_template("dashboard/http_functions/editor.html", **editor_data)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ def create_http_function_view_model(http_function):
|
|||||||
"id": http_function['id'],
|
"id": http_function['id'],
|
||||||
"user_id": http_function['user_id'],
|
"user_id": http_function['user_id'],
|
||||||
"name": http_function['name'],
|
"name": http_function['name'],
|
||||||
|
"path": http_function['path'],
|
||||||
|
"runtime": http_function['runtime'],
|
||||||
"script_content": http_function['script_content'],
|
"script_content": http_function['script_content'],
|
||||||
"invoked_count": http_function['invoked_count'],
|
"invoked_count": http_function['invoked_count'],
|
||||||
"environment_info": http_function['environment_info'],
|
"environment_info": http_function['environment_info'],
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ const Editor = {
|
|||||||
|
|
||||||
// Name + version
|
// Name + version
|
||||||
this.name = vnode.attrs.name || "foo";
|
this.name = vnode.attrs.name || "foo";
|
||||||
|
this.path = vnode.attrs.path || "";
|
||||||
this.versionNumber = vnode.attrs.versionNumber || "1";
|
this.versionNumber = vnode.attrs.versionNumber || "1";
|
||||||
this.nameEditing = false;
|
this.nameEditing = false;
|
||||||
|
this.pathEditing = false;
|
||||||
|
|
||||||
// Editor defaults
|
// Editor defaults
|
||||||
this.jsValue = vnode.attrs.jsValue || "";
|
this.jsValue = vnode.attrs.jsValue || "";
|
||||||
@@ -151,6 +153,7 @@ const Editor = {
|
|||||||
try {
|
try {
|
||||||
let payload = {
|
let payload = {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
|
path: this.path,
|
||||||
script_content: this.jsValue,
|
script_content: this.jsValue,
|
||||||
environment_info: this.jsonValue,
|
environment_info: this.jsonValue,
|
||||||
is_public: this.isPublic,
|
is_public: this.isPublic,
|
||||||
@@ -175,6 +178,7 @@ const Editor = {
|
|||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
|
path: this.path,
|
||||||
script_content: this.jsValue,
|
script_content: this.jsValue,
|
||||||
environment_info: this.jsonValue,
|
environment_info: this.jsonValue,
|
||||||
is_public: this.isPublic,
|
is_public: this.isPublic,
|
||||||
@@ -296,6 +300,27 @@ const Editor = {
|
|||||||
},
|
},
|
||||||
[
|
[
|
||||||
m("span", { class: "inline-flex items-center" }, [
|
m("span", { class: "inline-flex items-center" }, [
|
||||||
|
// Path
|
||||||
|
!this.pathEditing
|
||||||
|
? m(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: "font-mono text-gray-500 mr-1",
|
||||||
|
onclick: () => (this.pathEditing = true),
|
||||||
|
},
|
||||||
|
this.path ? `${this.path}/` : "/"
|
||||||
|
)
|
||||||
|
: m("input", {
|
||||||
|
class:
|
||||||
|
"bg-gray-50 border border-gray-300 text-sm rounded-lg p-1.5 dark:bg-gray-700 dark:border-gray-600 w-24 mr-1",
|
||||||
|
value: this.path,
|
||||||
|
placeholder: "path",
|
||||||
|
oninput: (e) => (this.path = e.target.value),
|
||||||
|
onblur: () => (this.pathEditing = false),
|
||||||
|
autofocus: true,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Name
|
||||||
!this.nameEditing
|
!this.nameEditing
|
||||||
? m(
|
? m(
|
||||||
"span",
|
"span",
|
||||||
@@ -348,21 +373,37 @@ const Editor = {
|
|||||||
: null,
|
: null,
|
||||||
|
|
||||||
// If adding a new function
|
// If adding a new function
|
||||||
this.isAdd
|
this.isAdd
|
||||||
? m("div", { class: "w-full" }, [
|
? m("div", { class: "flex space-x-2 w-full" }, [
|
||||||
m(
|
m("div", { class: "w-1/3" }, [
|
||||||
"label",
|
m(
|
||||||
{ class: "block mb-2 text-sm font-medium" },
|
"label",
|
||||||
"Function name"
|
{ class: "block mb-2 text-sm font-medium" },
|
||||||
),
|
"Path"
|
||||||
m("input", {
|
),
|
||||||
type: "text",
|
m("input", {
|
||||||
class: "bg-gray-50 border w-full p-2.5 rounded-lg",
|
type: "text",
|
||||||
placeholder: "foo",
|
class: "bg-gray-50 border w-full p-2.5 rounded-lg",
|
||||||
required: true,
|
placeholder: "api/v1",
|
||||||
value: this.name,
|
value: this.path,
|
||||||
oninput: (e) => (this.name = e.target.value),
|
oninput: (e) => (this.path = e.target.value),
|
||||||
}),
|
}),
|
||||||
|
]),
|
||||||
|
m("div", { class: "w-2/3" }, [
|
||||||
|
m(
|
||||||
|
"label",
|
||||||
|
{ class: "block mb-2 text-sm font-medium" },
|
||||||
|
"Function name"
|
||||||
|
),
|
||||||
|
m("input", {
|
||||||
|
type: "text",
|
||||||
|
class: "bg-gray-50 border w-full p-2.5 rounded-lg",
|
||||||
|
placeholder: "foo",
|
||||||
|
required: true,
|
||||||
|
value: this.name,
|
||||||
|
oninput: (e) => (this.name = e.target.value),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
])
|
])
|
||||||
: null,
|
: null,
|
||||||
])
|
])
|
||||||
|
|||||||
68
templates/dashboard/http_functions/_function_list.html
Normal file
68
templates/dashboard/http_functions/_function_list.html
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
{% macro render_functions(functions, path_prefix='') %}
|
||||||
|
<div class="pl-4">
|
||||||
|
{% for name, children in functions.items() %}
|
||||||
|
{% if children['_is_function'] is not defined %}
|
||||||
|
<details class="group" {% if path_prefix=='' %}open{% endif %}>
|
||||||
|
<summary class="flex items-center gap-2 py-2 cursor-pointer text-gray-700 hover:text-gray-900 font-medium">
|
||||||
|
<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 text-gray-400 group-open:rotate-90 transition-transform">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
|
||||||
|
</svg>
|
||||||
|
<span>{{ name }}</span>
|
||||||
|
</summary>
|
||||||
|
<div class="ml-4 border-l border-gray-200">
|
||||||
|
{{ render_functions(children, path_prefix + name + '/') }}
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
{% else %}
|
||||||
|
{% set function = children %}
|
||||||
|
<div class="flex items-center gap-2 py-2 pl-5 text-gray-800 hover:bg-gray-50 rounded-md">
|
||||||
|
<div class="flex-grow flex items-center gap-2 cursor-pointer"
|
||||||
|
hx-get="{{ url_for('http.editor', function_id=function['id']) }}" hx-target="#container" hx-swap="innerHTML"
|
||||||
|
hx-push-url="true">
|
||||||
|
<span class="font-medium">{{ function.name.split('/')[-1] }}</span>
|
||||||
|
<span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded-full">
|
||||||
|
v{{ function.version_number }}
|
||||||
|
</span>
|
||||||
|
<span class="bg-purple-100 text-purple-800 text-xs font-medium px-2.5 py-0.5 rounded-full uppercase">
|
||||||
|
{{ function.runtime }}
|
||||||
|
</span>
|
||||||
|
<span class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded-full">
|
||||||
|
{{ function.invoked_count }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex-shrink-0 flex items-center gap-2">
|
||||||
|
<button class="p-1 text-gray-400 hover:text-gray-600"
|
||||||
|
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" fill="none" viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<a href="{{ url_for('execute_http_function', user_id=function.user_id, function=function.name) }}"
|
||||||
|
target="_blank" class="p-1 text-gray-400 hover:text-gray-600">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
|
||||||
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path>
|
||||||
|
<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<button class="p-1 text-gray-400 hover:text-gray-600"
|
||||||
|
hx-get="{{ url_for('http.client', 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" fill="none" viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
@@ -23,6 +23,7 @@ history_url=url_for('http.history', function_id=function_id)) }}
|
|||||||
m.mount(document.getElementById("app"), {
|
m.mount(document.getElementById("app"), {
|
||||||
view: () => m(Editor, {
|
view: () => m(Editor, {
|
||||||
name: '{{ name }}',
|
name: '{{ name }}',
|
||||||
|
path: '{{ path }}',
|
||||||
functionId: {{ id }},
|
functionId: {{ id }},
|
||||||
jsValue: {{ script_content | tojson | safe }},
|
jsValue: {{ script_content | tojson | safe }},
|
||||||
jsonValue: {{ environment_info | tojson | safe }},
|
jsonValue: {{ environment_info | tojson | safe }},
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ title='New HTTP Function')
|
|||||||
m.mount(document.getElementById("app"), {
|
m.mount(document.getElementById("app"), {
|
||||||
view: () => m(Editor, {
|
view: () => m(Editor, {
|
||||||
name: '{{ name }}',
|
name: '{{ name }}',
|
||||||
|
path: '{{ path }}',
|
||||||
jsValue: {{ script | tojson | safe }},
|
jsValue: {{ script | tojson | safe }},
|
||||||
pythonValue: {{ default_python_script | tojson | safe }},
|
pythonValue: {{ default_python_script | tojson | safe }},
|
||||||
jsonValue: {{ environment_info | tojson | safe }},
|
jsonValue: {{ environment_info | tojson | safe }},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block page %}
|
{% block page %}
|
||||||
|
|
||||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
<div class="px-4 sm:px-6 lg:px-8 py-8">
|
||||||
<div class="flex items-center mb-6" data-id="51">
|
<div class="flex items-center mb-6" data-id="51">
|
||||||
<h1 class="text-2xl font-bold text-gray-900">HTTP Functions</h1>
|
<h1 class="text-2xl font-bold text-gray-900">HTTP Functions</h1>
|
||||||
<button
|
<button
|
||||||
@@ -16,102 +16,33 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white border border-gray-200 rounded-lg shadow-sm overflow-hidden">
|
<div class="mb-6">
|
||||||
<div class="overflow-x-auto">
|
<input type="text" name="q" placeholder="Search functions..."
|
||||||
<table class="w-full">
|
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
|
||||||
<thead>
|
value="{{ search_query }}" hx-get="{{ url_for('http.overview') }}" hx-trigger="keyup changed delay:500ms"
|
||||||
<tr class="bg-gray-50 border-b border-gray-200">
|
hx-target="#function-list" hx-headers='{"HX-Target": "function-list"}' hx-push-url="true">
|
||||||
<th class="px-6 py-4 text-left text-sm font-semibold text-gray-900">Name</th>
|
</div>
|
||||||
<th class="px-6 py-4 text-left text-sm font-semibold text-gray-900">URL
|
|
||||||
</th>
|
|
||||||
<th class="px-6 py-4 text-left text-sm font-semibold text-gray-900 hidden md:table-cell">Actions
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody class="divide-y divide-gray-200">
|
|
||||||
{% for function in http_functions %}
|
|
||||||
<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.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">
|
|
||||||
#{{ function.invoked_count }}
|
|
||||||
</span>
|
|
||||||
<span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded-full">
|
|
||||||
v{{ function.version_number }}
|
|
||||||
</span>
|
|
||||||
{% if function.is_public %}
|
|
||||||
<span class="text-gray-500">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
|
||||||
stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round"
|
|
||||||
d="M13.5 10.5V6.75a4.5 4.5 0 1 1 9 0v3.75M3.75 21.75h10.5a2.25 2.25 0 0 0 2.25-2.25v-6.75a2.25 2.25 0 0 0-2.25-2.25H3.75a2.25 2.25 0 0 0-2.25 2.25v6.75a2.25 2.25 0 0 0 2.25 2.25Z" />
|
|
||||||
</svg>
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<a href="{{ url_for('execute_http_function', user_id=function.user_id, function=function.name) }}"
|
|
||||||
class="text-blue-600 hover:text-blue-800">
|
|
||||||
{{ url_for('execute_http_function', user_id=function.user_id,
|
|
||||||
function=function.name) }}
|
|
||||||
</a>
|
|
||||||
<button class="ml-2 text-gray-400 hover:text-gray-600">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
|
|
||||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
|
||||||
stroke-linejoin="round">
|
|
||||||
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path>
|
|
||||||
<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 hidden md:table-cell">
|
|
||||||
<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.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"
|
|
||||||
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
|
||||||
</svg>
|
|
||||||
Logs
|
|
||||||
</button>
|
|
||||||
<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.client', 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"
|
|
||||||
d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
||||||
d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
||||||
</svg>
|
|
||||||
Try
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% if http_functions|length == 0 %}
|
<div id="function-list">
|
||||||
<tr>
|
{% block function_list %}
|
||||||
<td colspan="3" class="px-6 py-8 text-center">
|
{% from 'dashboard/http_functions/_function_list.html' import render_functions %}
|
||||||
<p class="text-gray-500 text-lg">No functions found</p>
|
{{ render_functions(http_functions) }}
|
||||||
</td>
|
|
||||||
</tr>
|
{% if http_functions|length == 0 %}
|
||||||
{% endif %}
|
<div class="py-12">
|
||||||
</tbody>
|
<div class="text-center">
|
||||||
</table>
|
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"
|
||||||
|
aria-hidden="true">
|
||||||
|
<path vector-effect="non-scaling-stroke" stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
|
||||||
|
</svg>
|
||||||
|
<h3 class="mt-2 text-lg font-medium text-gray-900">No functions found</h3>
|
||||||
|
<p class="mt-1 text-sm text-gray-500">Get started by creating a new function.</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user