forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualizationFrame.vue
More file actions
130 lines (113 loc) · 3.32 KB
/
VisualizationFrame.vue
File metadata and controls
130 lines (113 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { onBeforeRouteLeave } from "vue-router/composables";
import { withPrefix } from "@/utils/redirect";
import LoadingSpan from "@/components/LoadingSpan.vue";
const emit = defineEmits(["load"]);
export interface Props {
datasetId?: string;
visualization: string;
visualizationId?: string;
}
const props = defineProps<Props>();
const isLoading = ref(true);
const hasUnsavedChanges = ref(false);
const iframeRef = ref<HTMLIFrameElement | null>(null);
const srcWithRoot = computed(() => {
let url = "";
if (props.visualizationId) {
url = `/plugins/visualizations/${props.visualization}/saved?id=${props.visualizationId}`;
} else {
const query = props.datasetId ? `?dataset_id=${props.datasetId}` : "";
url = `/plugins/visualizations/${props.visualization}/show${query}`;
}
return withPrefix(url);
});
function handleLoad() {
isLoading.value = false;
emit("load");
setupChangeDetection();
}
function setupChangeDetection() {
const iframe = iframeRef.value;
if (!iframe?.contentWindow) {
return;
}
setTimeout(() => {
try {
const iframeDoc = iframe.contentDocument;
if (!iframeDoc) {
return;
}
const markAsChanged = () => {
if (!hasUnsavedChanges.value) {
hasUnsavedChanges.value = true;
}
};
// Monitor DOM changes (skip initial load)
setTimeout(() => {
const observer = new MutationObserver(() => markAsChanged());
observer.observe(iframeDoc.body, {
childList: true,
subtree: true,
characterData: true,
});
}, 2000);
// Monitor user input
["input", "change", "keyup", "paste"].forEach((type) => {
iframeDoc.addEventListener(type, markAsChanged, true);
});
} catch (e) {
console.warn("Cannot monitor iframe for changes:", e);
}
}, 1000);
}
onBeforeRouteLeave((to, from, next) => {
if (hasUnsavedChanges.value && !window.confirm("Unsaved changes will be lost. Continue?")) {
next(false);
} else {
next();
}
});
onMounted(() => {
window.addEventListener("beforeunload", (e) => {
if (hasUnsavedChanges.value) {
e.preventDefault();
e.returnValue = "";
}
});
});
</script>
<template>
<div class="position-relative h-100 overflow-hidden">
<div v-if="isLoading" class="iframe-loading bg-light">
<LoadingSpan message="Loading preview" />
</div>
<iframe
id="galaxy_visualization"
ref="iframeRef"
:src="srcWithRoot"
class="center-frame"
frameborder="0"
title="galaxy visualization frame"
width="100%"
height="100%"
@load="handleLoad" />
</div>
</template>
<style>
.iframe-loading {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 10;
opacity: 0.9;
pointer-events: none;
}
</style>