Skip to content

Commit

Permalink
Added file delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherSpelt committed Dec 4, 2024
1 parent bb39964 commit 7917449
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions amt/api/forms/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
18 changes: 14 additions & 4 deletions amt/api/routes/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion amt/site/static/ts/amt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
29 changes: 22 additions & 7 deletions amt/site/templates/macros/form_macros.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<div class="rvo-form-field__label">
<label id="label-{{ prefix }}{{ field.name }}"
for="{{ prefix }}{{ field.name }}"
class="rvo-label{% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
{% if field.description %}
<div id="description-{{ prefix }}{{ field.name }}"
class="utrecht-form-field-description">{{ field.description }}</div>
Expand Down Expand Up @@ -107,7 +107,7 @@
<div class="rvo-form-field__label">
<label id="label-{{ prefix }}{{ field.name }}"
for="{{ prefix }}{{ field.name }}"
class="rvo-label{% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
{% if field.description %}<div class="utrecht-form-field-description">{{ field.description }}</div>{% endif %}
</div>
<div id="error-{{ field.name }}" class="htmx-error-oob"></div>
Expand All @@ -126,7 +126,22 @@
<div class="rvo-form-field__label">
<label class="rvo-label" id="fieldId-label" for="fieldId">{% trans %}Saved files{% endtrans %}</label>
<ul class="rvo-item-list" id="files-output">
{% for file in field.default_value %}<li class="rvo-item-list__item">{{ file }}</li>{% endfor %}
{% for file in field.default_value %}
<li class="rvo-item-list__item">
<div class="rvo-layout-row rvo-layout-gap--md">
<input type="hidden" name="existing_file_names" value="{{ file }}">
<span>{{ file }}</span>
<a id="saved-file-delete"
class="rvo-link rvo-link--normal rvo-link--no-underline rvo-link--with-icon"
onclick="this.parentNode.parentNode.remove()">
<span class="utrecht-icon rvo-icon rvo-icon-verwijderen rvo-icon--md rvo-icon--hemelblauw rvo-link__icon--before"
role="img"
aria-label="Delete"></span>
Delete
</a>
</div>
</li>
{% endfor %}
</ul>
</div>
</div>
Expand All @@ -140,7 +155,7 @@
<div class="rvo-form-field__label">
<label id="label-{{ prefix }}{{ field.name }}"
for="{{ prefix }}{{ field.name }}"
class="rvo-label{% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
{% if field.description %}<div class="utrecht-form-field-description">{{ field.description }}</div>{% endif %}
</div>
<div id="error-{{ field.name }}" class="htmx-error-oob"></div>
Expand All @@ -154,7 +169,7 @@
<div class="rvo-form-field__label">
<label id="label-{{ prefix }}{{ field.name }}"
for="{{ prefix }}{{ field.name }}"
class="rvo-label{% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
{% if field.description %}<div class="utrecht-form-field-description">{{ field.description }}</div>{% endif %}
</div>
<div id="error-{{ field.name }}" class="htmx-error-oob"></div>
Expand Down Expand Up @@ -209,7 +224,7 @@
<div class="rvo-form-field__label">
<label id="label-{{ prefix }}{{ field.name }}"
for="{{ prefix }}{{ field.name }}"
class="rvo-label{% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
{% if field.description %}<div class="utrecht-form-field-description">{{ field.description }}</div>{% endif %}
</div>
<div id="error-{{ field.name }}" class="htmx-error-oob"></div>
Expand All @@ -222,7 +237,7 @@
class="utrecht-form-field utrecht-form-field--text rvo-form-field">
<div class="rvo-form-field__label">
<label id="label-{{ prefix }}{{ field.name }}"
class="rvo-label{% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
class="rvo-label {% if field.required %}rvo-label--required{% endif %}">{{ field.label }}</label>
{% if field.description %}<div class="utrecht-form-field-description">{{ field.description }}</div>{% endif %}
</div>
<div id="error-{{ field.name }}" class="htmx-error-oob"></div>
Expand Down
8 changes: 7 additions & 1 deletion tests/api/routes/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7917449

Please sign in to comment.