Skip to content

Commit 2671afc

Browse files
Iframe: add support for external API
1 parent cfb0f4a commit 2671afc

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/components/widgets/IFrame.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<teleport to=".widgets-view">
44
<iframe
55
v-show="iframe_loaded"
6+
ref="iframe"
67
:src="widget.options.source"
78
:style="iframeStyle"
89
frameborder="0"
@@ -58,14 +59,16 @@ import { computed, defineProps, onBeforeMount, ref, toRefs, watch } from 'vue'
5859
5960
import { defaultBlueOsAddress } from '@/assets/defaults'
6061
import Snackbar from '@/components/Snackbar.vue'
62+
import { listenDataLakeVariable } from '@/libs/actions/data-lake'
6163
import { isValidURL } from '@/libs/utils'
6264
import { useAppInterfaceStore } from '@/stores/appInterface'
6365
import { useWidgetManagerStore } from '@/stores/widgetManager'
6466
import type { Widget } from '@/types/widgets'
67+
6568
const interfaceStore = useAppInterfaceStore()
6669
6770
const widgetStore = useWidgetManagerStore()
68-
71+
const iframe = ref()
6972
const props = defineProps<{
7073
/**
7174
* Widget reference
@@ -97,10 +100,24 @@ const updateURL = (): void => {
97100
}
98101
99102
onBeforeMount(() => {
103+
window.addEventListener(
104+
'message',
105+
(event) => {
106+
if (event.data.type !== 'cockpit:listenToDatalakeVariables') {
107+
return
108+
}
109+
const { variable } = event.data
110+
console.log('asked to listen to ', variable)
111+
listenDataLakeVariable(variable, (value) => {
112+
iframe.value.contentWindow.postMessage({ type: 'cockpit:datalakeVariable', variable, value }, '*')
113+
})
114+
},
115+
false
116+
)
117+
100118
if (Object.keys(widget.value.options).length !== 0) {
101119
return
102120
}
103-
104121
widget.value.options = {
105122
source: defaultBlueOsAddress,
106123
}

0 commit comments

Comments
 (0)