From 7917449029aa2c39dd206932f5450a539ab658eb Mon Sep 17 00:00:00 2001 From: ChristopherSpelt Date: Wed, 4 Dec 2024 12:48:15 +0100 Subject: [PATCH] Added file delete --- .vscode/launch.json | 4 ++- amt/api/forms/organization.py | 2 ++ amt/api/routes/algorithm.py | 18 +++++++++--- amt/site/static/ts/amt.ts | 2 +- amt/site/templates/macros/form_macros.html.j2 | 29 ++++++++++++++----- tests/api/routes/test_algorithm.py | 8 ++++- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e78cc94f..18d50b42 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,7 +21,9 @@ "DEBUG": "True", "AUTO_CREATE_SCHEMA": "True", "ENVIRONMENT": "local", - "LOGGING_LEVEL": "DEBUG" + "LOGGING_LEVEL": "DEBUG", + "OIDC_CLIENT_SECRET": "uIeFiKFazNEIbpJ3wzj0lZLLSJXefeld", + "OIDC_CLIENT_ID": "AMT" } }, { diff --git a/amt/api/forms/organization.py b/amt/api/forms/organization.py index 67785aad..6b75686c 100644 --- a/amt/api/forms/organization.py +++ b/amt/api/forms/organization.py @@ -16,6 +16,7 @@ def get_organization_form(id: str, translations: NullTranslations) -> WebForm: placeholder=_("Name of the organization"), attributes={"onkeyup": "amt.generate_slug('" + id + "name', '" + id + "slug')"}, group="1", + required=True, ), WebFormField( type=WebFormFieldType.TEXT, @@ -24,6 +25,7 @@ def get_organization_form(id: str, translations: NullTranslations) -> WebForm: label=_("Slug"), placeholder=_("The slug for this organization"), group="1", + required=True, ), WebFormSearchField( name="user_ids", diff --git a/amt/api/routes/algorithm.py b/amt/api/routes/algorithm.py index ad841c46..8f899114 100644 --- a/amt/api/routes/algorithm.py +++ b/amt/api/routes/algorithm.py @@ -545,19 +545,29 @@ async def update_measure_value( measure_state: Annotated[str, Form()], measure_value: Annotated[str | None, Form()] = None, measure_links: Annotated[list[str] | None, Form()] = None, + existing_file_names: Annotated[list[str] | None, Form()] = None, measure_files: Annotated[list[UploadFile] | None, File()] = None, ) -> HTMLResponse: algorithm = await get_algorithm_or_error(algorithm_id, algorithms_service, request) measure_task = find_measure_task(algorithm.system_card, measure_urn) + + # Update measure state measure_task.state = measure_state # measure_update.measure_state # pyright: ignore [reportOptionalMemberAccess] + + # Update measure value if measure_value: - measure_task.value = ( - measure_value # measure_update.measure_value # pyright: ignore [reportOptionalMemberAccess] + measure_task.value = ( # measure_update.measure_value # pyright: ignore [reportOptionalMemberAccess] + measure_value ) + + # Update measure links measure_task.links = [link for link in measure_links if link] if measure_links else [] # pyright: ignore [reportOptionalMemberAccess] - new_files = [file.filename for file in measure_files if file and file.filename] if measure_files else [] - measure_task.files.extend(new_files) # pyright: ignore [reportOptionalMemberAccess] + + # Update measure files + measure_task.files = existing_file_names if existing_file_names else [] # pyright: ignore [reportOptionalMemberAccess] + if measure_files: + measure_task.files.extend([file.filename for file in measure_files if file and file.filename]) # pyright: ignore [reportOptionalMemberAccess] # update for the linked requirements the state based on all it's measures requirement_tasks = await find_requirement_tasks_by_measure_urn(algorithm.system_card, measure_urn) diff --git a/amt/site/static/ts/amt.ts b/amt/site/static/ts/amt.ts index d7b6bf98..af31638d 100644 --- a/amt/site/static/ts/amt.ts +++ b/amt/site/static/ts/amt.ts @@ -261,7 +261,7 @@ export function getFiles(element: HTMLInputElement, target_id: string) { for (const file of element.files) { const li = document.createElement("li"); li.className = "rvo-item-list__item"; - li.innerText = file.name; + li.textContent = file.name; list.appendChild(li); } } diff --git a/amt/site/templates/macros/form_macros.html.j2 b/amt/site/templates/macros/form_macros.html.j2 index 80474ec9..7e4a5131 100644 --- a/amt/site/templates/macros/form_macros.html.j2 +++ b/amt/site/templates/macros/form_macros.html.j2 @@ -78,7 +78,7 @@
+ class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }} {% if field.description %}
{{ field.description }}
@@ -107,7 +107,7 @@
+ class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }} {% if field.description %}
{{ field.description }}
{% endif %}
@@ -126,7 +126,22 @@
    - {% for file in field.default_value %}
  • {{ file }}
  • {% endfor %} + {% for file in field.default_value %} +
  • +
    + + {{ file }} + + + Delete + +
    +
  • + {% endfor %}
@@ -140,7 +155,7 @@
+ class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }} {% if field.description %}
{{ field.description }}
{% endif %}
@@ -154,7 +169,7 @@
+ class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }} {% if field.description %}
{{ field.description }}
{% endif %}
@@ -209,7 +224,7 @@
+ class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }} {% if field.description %}
{{ field.description }}
{% endif %}
@@ -222,7 +237,7 @@ class="utrecht-form-field utrecht-form-field--text rvo-form-field">
+ class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }} {% if field.description %}
{{ field.description }}
{% endif %}
diff --git a/tests/api/routes/test_algorithm.py b/tests/api/routes/test_algorithm.py index 6589fa2a..52b146f9 100644 --- a/tests/api/routes/test_algorithm.py +++ b/tests/api/routes/test_algorithm.py @@ -570,7 +570,13 @@ async def test_update_measure_value(client: AsyncClient, mocker: MockFixture, db # happy flow response = await client.post( "/algorithm/1/measure/urn:nl:ak:mtr:dat-01", - json={"measure_update": MeasureUpdate(measure_state="done", measure_value="something").model_dump()}, + data={ + "measure_state": "done", + "measure_value": "something", + "measure_links": [], + "existing_file_names": [], + "measure_files": [], + }, headers={"X-CSRF-Token": "1"}, ) assert response.status_code == 200