Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if image exists before deleting civs for archive items #3116

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$('#ajaxDataTable').on( 'init.dt', function() {
jmsmkn marked this conversation as resolved.
Show resolved Hide resolved
allSelectElements = document.querySelectorAll('[id^="interfaceSelect"]');
allSelectElements.forEach(function(elem) {
elem.addEventListener("change", loadUpdateView);
});
});

function loadUpdateView(source) {
window.location.href = source.target.value
}
4 changes: 3 additions & 1 deletion app/grandchallenge/archives/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def update_archive_item_values(*, archive_item_pk, civ_pks_to_add):
).values_list("pk", flat=True):
civ_pks_to_remove.append(civ_pk)
# for images, check if there are any CIVs with the provided image
if civ.interface.is_image_kind:
# this is necessary to enable updating the interface
# of a given image via the API
if civ.interface.is_image_kind and civ.image:
if instance.values.filter(image=civ.image).exists():
for civ_pk in instance.values.filter(
image=civ.image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ <h2>Items for {{ archive.title }}</h2>
{% block script %}
{{ block.super }}
{% include 'workstations/partials/session-control.html' %}
<script src="{% static 'archives/js/archive_item_update.js' %}"></script>
amickan marked this conversation as resolved.
Show resolved Hide resolved
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ul>
<split></split>

<select class="form-control" onchange="location = this.value;">
<select class="form-control" id="interfaceSelect">
{% for interface in interfaces %}
{% if interface not in object_interfaces %}
<option value="{% url 'archives:item-edit' archive_slug=object.archive.slug pk=object.pk interface_slug=interface.slug %}">Add {{ interface.title }}</option>
Expand Down
26 changes: 16 additions & 10 deletions app/tests/archives_tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,14 @@ def test_archive_item_add_image(
item = ArchiveItemFactory(archive=archive)
editor = UserFactory()
archive.add_editor(editor)
ci = ComponentInterfaceFactory(
ci_img = ComponentInterfaceFactory(
kind=InterfaceKind.InterfaceKindChoices.IMAGE
)
ci_value = ComponentInterfaceFactory(
kind=InterfaceKind.InterfaceKindChoices.BOOL
)
civ_value = ComponentInterfaceValueFactory(interface=ci_value, value=True)
item.values.add(civ_value)
upload = create_upload_from_file(
file_path=RESOURCE_PATH / "image10x10x10.mha",
creator=editor,
Expand All @@ -735,17 +740,18 @@ def test_archive_item_add_image(
method=client.post,
reverse_kwargs={
"pk": item.pk,
"interface_slug": ci.slug,
"interface_slug": ci_img.slug,
"archive_slug": archive.slug,
},
user=editor,
follow=True,
data={
ci.slug: upload.pk,
f"WidgetChoice-{ci.slug}": WidgetChoices.IMAGE_UPLOAD.name,
ci_img.slug: upload.pk,
f"WidgetChoice-{ci_img.slug}": WidgetChoices.IMAGE_UPLOAD.name,
},
)
assert response.status_code == 200
assert item.values.count() == 2
assert "image10x10x10.mha" == item.values.first().image.name
old_civ = item.values.first()

Expand All @@ -757,14 +763,14 @@ def test_archive_item_add_image(
method=client.post,
reverse_kwargs={
"pk": item.pk,
"interface_slug": ci.slug,
"interface_slug": ci_img.slug,
"archive_slug": archive.slug,
},
user=editor,
follow=True,
data={
ci.slug: old_civ.image.pk,
f"WidgetChoice-{ci.slug}": WidgetChoices.IMAGE_SEARCH.name,
ci_img.slug: old_civ.image.pk,
f"WidgetChoice-{ci_img.slug}": WidgetChoices.IMAGE_SEARCH.name,
},
)
assert response.status_code == 200
Expand All @@ -781,14 +787,14 @@ def test_archive_item_add_image(
method=client.post,
reverse_kwargs={
"pk": item.pk,
"interface_slug": ci.slug,
"interface_slug": ci_img.slug,
"archive_slug": archive.slug,
},
user=editor,
follow=True,
data={
ci.slug: image.pk,
f"WidgetChoice-{ci.slug}": WidgetChoices.IMAGE_SEARCH.name,
ci_img.slug: image.pk,
f"WidgetChoice-{ci_img.slug}": WidgetChoices.IMAGE_SEARCH.name,
},
)
assert response.status_code == 200
Expand Down