|
3 | 3 | <teleport to=".widgets-view"> |
4 | 4 | <iframe |
5 | 5 | v-show="iframe_loaded" |
| 6 | + ref="iframe" |
6 | 7 | :src="widget.options.source" |
7 | 8 | :style="iframeStyle" |
8 | 9 | frameborder="0" |
@@ -58,14 +59,16 @@ import { computed, defineProps, onBeforeMount, ref, toRefs, watch } from 'vue' |
58 | 59 |
|
59 | 60 | import { defaultBlueOsAddress } from '@/assets/defaults' |
60 | 61 | import Snackbar from '@/components/Snackbar.vue' |
| 62 | +import { listenDataLakeVariable } from '@/libs/actions/data-lake' |
61 | 63 | import { isValidURL } from '@/libs/utils' |
62 | 64 | import { useAppInterfaceStore } from '@/stores/appInterface' |
63 | 65 | import { useWidgetManagerStore } from '@/stores/widgetManager' |
64 | 66 | import type { Widget } from '@/types/widgets' |
| 67 | +
|
65 | 68 | const interfaceStore = useAppInterfaceStore() |
66 | 69 |
|
67 | 70 | const widgetStore = useWidgetManagerStore() |
68 | | -
|
| 71 | +const iframe = ref() |
69 | 72 | const props = defineProps<{ |
70 | 73 | /** |
71 | 74 | * Widget reference |
@@ -97,10 +100,24 @@ const updateURL = (): void => { |
97 | 100 | } |
98 | 101 |
|
99 | 102 | 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 | +
|
100 | 118 | if (Object.keys(widget.value.options).length !== 0) { |
101 | 119 | return |
102 | 120 | } |
103 | | -
|
104 | 121 | widget.value.options = { |
105 | 122 | source: defaultBlueOsAddress, |
106 | 123 | } |
|
0 commit comments