diff --git a/client/src/components/History/Multiple/MultipleViewList.vue b/client/src/components/History/Multiple/MultipleViewList.vue index c00903183edc..9f6057e99f30 100644 --- a/client/src/components/History/Multiple/MultipleViewList.vue +++ b/client/src/components/History/Multiple/MultipleViewList.vue @@ -3,12 +3,19 @@ import { computed, type Ref, ref } from "vue"; //@ts-ignore missing typedefs import VirtualList from "vue-virtual-scroll-list"; +import { copyDataset } from "@/components/Dataset/services"; import { useAnimationFrameResizeObserver } from "@/composables/sensors/animationFrameResizeObserver"; import { useAnimationFrameScroll } from "@/composables/sensors/animationFrameScroll"; +import { Toast } from "@/composables/toast"; import type { HistorySummary } from "@/stores/historyStore"; +import { useHistoryStore } from "@/stores/historyStore"; +import localize from "@/utils/localization"; +import HistoryDropZone from "../CurrentHistory/HistoryDropZone.vue"; import MultipleViewItem from "./MultipleViewItem.vue"; +const historyStore = useHistoryStore(); + const props = withDefaults( defineProps<{ histories: HistorySummary[]; @@ -30,6 +37,47 @@ useAnimationFrameResizeObserver(scrollContainer, ({ clientSize, scrollSize }) => const scrolledLeft = computed(() => !isScrollable.value || arrived.left); const scrolledRight = computed(() => !isScrollable.value || arrived.right); + +const showDropZone = ref(false); +const historyPickerText = computed(() => + showDropZone.value ? localize("Create new history with this item") : localize("Select histories") +); +const processingDrop = ref(false); +async function onDrop(evt: any) { + if (processingDrop.value) { + showDropZone.value = false; + return; + } + processingDrop.value = true; + showDropZone.value = false; + let data: any; + try { + data = JSON.parse(evt.dataTransfer.getData("text"))[0]; + } catch (error) { + // this was not a valid object for this dropzone, ignore + } + if (data) { + await historyStore.createNewHistory(); + const currentHistoryId = historyStore.currentHistoryId; + const dataSource = data.history_content_type === "dataset" ? "hda" : "hdca"; + if (currentHistoryId) { + await copyDataset(data.id, currentHistoryId, data.history_content_type, dataSource) + .then(() => { + if (data.history_content_type === "dataset") { + Toast.info(localize("Dataset copied to new history")); + } else { + Toast.info(localize("Collection copied to new history")); + } + historyStore.loadHistoryById(currentHistoryId); + }) + .catch((error) => { + Toast.error(error); + }); + historyStore.pinHistory(currentHistoryId); + } + processingDrop.value = false; + } +}