Only delete selected data types from gallery button.

This commit is contained in:
Julian Stirling 2026-06-24 11:24:41 +01:00
parent a5828fbf41
commit c4ae7f7c90
3 changed files with 26 additions and 9 deletions

View file

@ -45,7 +45,8 @@ class GalleryThing(lt.Thing):
all_ofm_things: Mapping[str, OFMThing] = lt.thing_slot()
_gallery_providing_things: Optional[Mapping[str, GalleryCompatibleThing]] = None
_card_types: Optional[Mapping[str, GalleryCompatibleThing]] = None
_card_types: Optional[list[str]] = None
_card_type_map: dict[str, str] = {}
@property
def gallery_providing_things(self) -> Mapping[str, GalleryCompatibleThing]:
@ -101,6 +102,7 @@ class GalleryThing(lt.Thing):
card_type = props["card_type"]["const"]
if card_type not in card_types:
card_types.append(card_type)
self._card_type_map[thing.name] = card_type
self._card_types = card_types
@ -133,10 +135,12 @@ class GalleryThing(lt.Thing):
return data_list
@lt.action
def delete_all_data(self) -> None:
"""Delete all the gallery data on this microscope."""
def delete_all_data(self, card_types: list[str]) -> None:
"""Delete all the gallery data on this microscope with the given card types."""
for thing in self.gallery_providing_things.values():
try:
thing.delete_all_gallery_items()
except Exception as e:
self.logger.exception(e)
thing_card_type = self._card_type_map.get(thing.name)
if thing_card_type in card_types:
try:
thing.delete_all_gallery_items()
except Exception as e:
self.logger.exception(e)

View file

@ -267,6 +267,7 @@ export default {
#container-left {
overflow: auto;
scrollbar-gutter: stable;
background-color: rgba(180, 180, 180, 0.025);
width: 100%;
height: 100%;

View file

@ -1,5 +1,5 @@
<template>
<div ref="galleryDisplay" class="galleryDisplay uk-padding uk-padding-remove-top">
<div ref="galleryDisplay" class="gallery-display uk-padding uk-padding-remove-top">
<!-- Gallery nav bar -->
<nav class="gallery-navbar uk-navbar-container uk-navbar-transparent" uk-navbar="mode: click">
<!-- Right side buttons -->
@ -32,11 +32,13 @@
thing="gallery"
action="delete_all_data"
submit-label="Delete All"
:submit-data="{ card_types: selectedCardTypes }"
:is-disabled="totalPages == 0"
:can-terminate="true"
:button-primary="false"
:modal-progress="true"
:requires-confirmation="true"
:confirmation-message="'<p>Are you sure you want to delete all gallery data from the microscope?</p><p>This is <b>irreversible</b>!</p>'"
:confirmation-message="deleteAllConfirmationMessage"
@error="modalError"
/>
</div>
@ -131,6 +133,16 @@ export default {
const start = (this.currentPage - 1) * this.itemsPerPage;
return (this.filtered_items || []).slice(start, start + this.itemsPerPage);
},
deleteAllConfirmationMessage() {
return `
<p>Are you sure you want to delete all gallery data with the following types</p>
<ul>
${this.selectedCardTypes.map((type) => `<li>${type}</li>`).join("\n")}
</ul>
<p>from the microscope?</p>
<p>This is <b>irreversible</b>!</p>
`;
},
},
watch: {