From 34b450ac0fad6160061dcc17edc167ef11052e94 Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Thu, 21 Aug 2025 13:42:22 -0700 Subject: [PATCH] add the changes --- viewer/pages/qc.py | 9 +++- viewer/pages/user.py | 71 +++++++++++++++++++----------- viewer/templates/customize_qc.html | 61 +++++++++++++++++-------- 3 files changed, 96 insertions(+), 45 deletions(-) diff --git a/viewer/pages/qc.py b/viewer/pages/qc.py index 27ba04dd2..082e50fea 100644 --- a/viewer/pages/qc.py +++ b/viewer/pages/qc.py @@ -2595,15 +2595,22 @@ def select_test(): len(stageInfo["stage_flow"]) - 1, stageInfo["stage_flow"].index(current_stage) + 1, ) + + # Get disabled stages from the QC configuration + disabled_tests = stageInfo.get("disabled_tests", {}) + if request.form.get("transitionToAlternative") == "enable": next_stages_required = ( - stage for stage in stageInfo["stage_flow"][next_stage_index:] + stage + for stage in stageInfo["stage_flow"][next_stage_index:] + if not disabled_tests.get(stage, {}).get("disabled", 0) ) else: next_stages_required = ( stage for stage in stageInfo["stage_flow"][next_stage_index:] if stage not in stageInfo["alternatives"] + and not disabled_tests.get(stage, {}).get("disabled", 0) ) try: next_stage = next(next_stages_required) diff --git a/viewer/pages/user.py b/viewer/pages/user.py index 6764ef71c..176401e5c 100755 --- a/viewer/pages/user.py +++ b/viewer/pages/user.py @@ -30,6 +30,7 @@ from functions.common import ( TMP_DIR, args, clear_message, + component_type_code_map, create_message, emit_message, format_messages, @@ -1127,35 +1128,48 @@ def delete_message(message_id): return redirect(pre_url) -@user_api.route("/customize_qc", methods=["POST", "GET"]) +@user_api.route("/customize_qc", methods=["GET"]) def customize_qc(): if not session.get("logged_in"): return render_template("401.html") - input_step = request.form.get("input_step", "select_ctype") + # Get component types and create a mapping for the dropdown + ctypes_data = [] + for ctype in userdb.componentType.find({}): + name = ctype.get("name") + # Find the corresponding code from the mapping + code = None + for key, value in component_type_code_map.items(): + if value == name or key == name.lower().replace(" ", "_"): + code = key + break + if code: + ctypes_data.append({"name": name, "code": code}) - if input_step == "select_ctype": - ctypes = [ctype.get("name") for ctype in list(userdb.componentType.find({}))] - return render_template( - "customize_qc.html", ctypes=ctypes, input_step=input_step - ) + return render_template( + "customize_qc.html", ctypes_data=ctypes_data, input_step="select_ctype" + ) + + +@user_api.route("/customize_qc/", methods=["GET", "POST"]) +def customize_qc_component(component_type): + if not session.get("logged_in"): + return render_template("401.html") - if input_step == "user_input": - selected_ctype = request.form.get("selected_ctype", None) - stage_doc = userdb.QC.stages.find_one({"name": selected_ctype}) + # Find the stage document using the component type code + stage_doc = userdb.QC.stages.find_one( + {"code": component_type_code_map.get(component_type, component_type)} + ) + if not stage_doc: return render_template( - "customize_qc.html", - selected_ctype=selected_ctype, - stage_doc=stage_doc, - input_step=input_step, - ) + "error.html", txt=f"Component type '{component_type}' not found" + ), 404 - if input_step == "submit": - selected_ctype = request.form.get("selected_ctype", None) - stage_doc = userdb.QC.stages.find_one({"name": selected_ctype}) + # Handle POST requests for form submission + if request.method == "POST": disable_doc = stage_doc.get("disabled_tests", {}) - for stage, tests in stage_doc.get("stage_test").items(): + for stage, tests in stage_doc.get("stage_test", {}).items(): if request.form.get(f"enable_{stage}") is None: if stage not in disable_doc: disable_doc[stage] = {"disabled": 1, "tests": []} @@ -1184,13 +1198,18 @@ def customize_qc(): {"_id": stage_doc.get("_id")}, {"$set": {"disabled_tests": disable_doc}} ) - return render_template( - "customize_qc.html", - selected_ctype=selected_ctype, - stage_doc=stage_doc, - input_step="user_input", + # Redirect to the GET version to show updated state + return redirect( + url_for("user_api.customize_qc_component", component_type=component_type) ) + # Handle GET requests - show the configuration form + selected_ctype_display = stage_doc.get("name", component_type) + return render_template( - "error.html", txt="user_api.dustomize_qc(): Invalid state" - ), 400 + "customize_qc.html", + selected_ctype=selected_ctype_display, + component_type=component_type, + stage_doc=stage_doc, + input_step="user_input", + ) diff --git a/viewer/templates/customize_qc.html b/viewer/templates/customize_qc.html index 08dd52bfa..73a4af1f3 100644 --- a/viewer/templates/customize_qc.html +++ b/viewer/templates/customize_qc.html @@ -50,21 +50,35 @@
-
+ {% if input_step == "select_ctype" %}

- {% if input_step == "select_ctype" %} - -
- - -
- {% elif input_step == "user_input" %} + +
+ +
+
+ {% else %} + +

+

Configuring {{ stage_doc["name"] }} QC Menu

{% set stages = stage_doc["stage_flow"] %} @@ -134,12 +148,11 @@
- - +
- {% endif %} -
-
+
+ + {% endif %}
@@ -153,3 +166,15 @@ {% endblock %} + +{% block javascript %} + +{% endblock %} -- GitLab