Skip to content

Commit

Permalink
Iframe: add support for external API
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed Dec 17, 2024
1 parent cfb0f4a commit 2671afc
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/widgets/IFrame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<teleport to=".widgets-view">
<iframe
v-show="iframe_loaded"
ref="iframe"
:src="widget.options.source"
:style="iframeStyle"
frameborder="0"
Expand Down Expand Up @@ -58,14 +59,16 @@ import { computed, defineProps, onBeforeMount, ref, toRefs, watch } from 'vue'
import { defaultBlueOsAddress } from '@/assets/defaults'
import Snackbar from '@/components/Snackbar.vue'
import { listenDataLakeVariable } from '@/libs/actions/data-lake'
import { isValidURL } from '@/libs/utils'
import { useAppInterfaceStore } from '@/stores/appInterface'
import { useWidgetManagerStore } from '@/stores/widgetManager'
import type { Widget } from '@/types/widgets'
const interfaceStore = useAppInterfaceStore()
const widgetStore = useWidgetManagerStore()
const iframe = ref()
const props = defineProps<{
/**
* Widget reference
Expand Down Expand Up @@ -97,10 +100,24 @@ const updateURL = (): void => {
}
onBeforeMount(() => {
window.addEventListener(
'message',
(event) => {
if (event.data.type !== 'cockpit:listenToDatalakeVariables') {
return
}
const { variable } = event.data
console.log('asked to listen to ', variable)
listenDataLakeVariable(variable, (value) => {
iframe.value.contentWindow.postMessage({ type: 'cockpit:datalakeVariable', variable, value }, '*')
})
},
false
)
if (Object.keys(widget.value.options).length !== 0) {
return
}
widget.value.options = {
source: defaultBlueOsAddress,
}
Expand Down

0 comments on commit 2671afc

Please sign in to comment.