Add services dropdown with operations panel

This commit is contained in:
2026-07-23 11:42:30 +04:00
parent 6a84257533
commit 6b098509e9
3 changed files with 111 additions and 22 deletions
+21 -2
View File
@@ -1,7 +1,8 @@
from flask import Blueprint, current_app, render_template, request, make_response
from flask import Blueprint, current_app, render_template, request, make_response, jsonify
from api.http_client import HttpClient
from operations.get_instances import get_organization
from operations.get_services import get_services, get_service_detail
bp = Blueprint("main", __name__)
@@ -40,6 +41,7 @@ def index():
resp.status_code = 302
return resp
services = []
if active_token:
try:
client = HttpClient(
@@ -47,10 +49,27 @@ def index():
active_token,
)
org = get_organization(client)
raw = get_services(client)
services = sorted(raw, key=lambda s: (s.get("svcId", 0), s.get("svc", "")))
except Exception as e:
error = str(e)
return render_template("index.html",
organization=org, error=error,
env_token_masked=_mask(env_token),
has_user_token=bool(user_token))
has_user_token=bool(user_token),
services=services)
@bp.route("/api/operations/<int:svc_id>")
def api_operations(svc_id):
env_token = current_app.config["NUBES_API_TOKEN"]
user_token = request.cookies.get("token") or ""
active_token = user_token or env_token
try:
client = HttpClient(current_app.config["NUBES_API_ENDPOINT"], active_token)
detail = get_service_detail(client, svc_id)
ops = detail.get("operations", [])
return jsonify({"svc": detail.get("svc", ""), "operations": ops})
except Exception as e:
return jsonify({"error": str(e)}), 500