From 26cd18961309aa6d46f44459d7ac5154999c37a6 Mon Sep 17 00:00:00 2001 From: Satont Date: Wed, 20 Sep 2023 00:16:58 +0300 Subject: [PATCH] feat: add javascript support for `dashboard`/`overlays` --- .../src/components/registry/overlays/edit.vue | 23 +++++++++++++--- .../registry/overlays/layers/html.vue | 26 +++++++++++++++---- .../registry/overlays/layers/htmlForm.vue | 10 +++++++ .../registry/overlays/newSelector.vue | 7 ++++- .../overlays/src/components/htmlLayer.vue | 12 ++++++++- frontend/overlays/src/sockets/overlays.ts | 1 + 6 files changed, 68 insertions(+), 11 deletions(-) diff --git a/frontend/dashboard/src/components/registry/overlays/edit.vue b/frontend/dashboard/src/components/registry/overlays/edit.vue index 8ca725130..219237697 100644 --- a/frontend/dashboard/src/components/registry/overlays/edit.vue +++ b/frontend/dashboard/src/components/registry/overlays/edit.vue @@ -163,8 +163,10 @@ const innerWidth = computed(() => window.innerWidth); :index="index" :text="layer.settings?.htmlOverlayHtml ?? ''" :css="layer.settings?.htmlOverlayCss ?? ''" + :js="layer.settings?.htmlOverlayJs ?? ''" :periodicallyRefetchData="layer.periodicallyRefetchData" /> + window.innerWidth);
- + {{ t('sharedButtons.save') }} - + {{ t('overlays.copyOverlayLink') }} - + @@ -234,6 +245,7 @@ const innerWidth = computed(() => window.innerWidth); :key="index" v-model:html="formValue.layers[index].settings!.htmlOverlayHtml" v-model:css="formValue.layers[index].settings!.htmlOverlayCss" + v-model:js="formValue.layers[index].settings!.htmlOverlayJs" v-model:pollInterval="formValue.layers[index].settings!.htmlOverlayHtmlDataPollSecondsInterval" v-model:periodicallyRefetchData="formValue.layers[index].periodicallyRefetchData" :isFocused="currentlyFocused === index" @@ -247,7 +259,10 @@ const innerWidth = computed(() => window.innerWidth);
- + import { useIntervalFn } from '@vueuse/core'; -import { ref, watch } from 'vue'; +import { ref, watch, nextTick, computed } from 'vue'; import { useOverlaysParseHtml } from '@/api/registry'; @@ -14,6 +14,7 @@ const props = defineProps<{ height: number; text: string; css: string; + js: string periodicallyRefetchData: boolean, }>(); @@ -26,6 +27,24 @@ const { pause, resume } = useIntervalFn(async () => { exampleValue.value = data ?? ''; }, 1000, { immediate: true, immediateCallback: true }); +const executeFunc = computed(() => { + return new Function(`${props.js}; onDataUpdate();`); +}); + +watch(exampleValue, async () => { + await nextTick(); + // calling user defined function + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + executeFunc.value?.(); +}); + +const componentKey = ref(0); + +watch(() => props.js, async () => { + componentKey.value += 1; +}, { immediate: true }); + watch(props, (p) => { const v = p.periodicallyRefetchData; @@ -53,10 +72,7 @@ watch(props, (p) => { }` }} +
- - diff --git a/frontend/dashboard/src/components/registry/overlays/layers/htmlForm.vue b/frontend/dashboard/src/components/registry/overlays/layers/htmlForm.vue index aaca245e4..b7ac08760 100644 --- a/frontend/dashboard/src/components/registry/overlays/layers/htmlForm.vue +++ b/frontend/dashboard/src/components/registry/overlays/layers/htmlForm.vue @@ -28,6 +28,7 @@ defineEmits<{ const html = defineModel('html'); const css = defineModel('css'); +const js = defineModel('js'); const pollInterval = defineModel('pollInterval', { default: 5 }); const periodicallyRefetchData = defineModel('periodicallyRefetchData'); @@ -127,6 +128,15 @@ const { t } = useI18n(); language="css" /> + + + +
diff --git a/frontend/dashboard/src/components/registry/overlays/newSelector.vue b/frontend/dashboard/src/components/registry/overlays/newSelector.vue index 4a2c0004a..191c2a441 100644 --- a/frontend/dashboard/src/components/registry/overlays/newSelector.vue +++ b/frontend/dashboard/src/components/registry/overlays/newSelector.vue @@ -29,7 +29,12 @@ const { t } = useI18n(); htmlOverlayCss: '.text { color: red }', htmlOverlayHtml: `$(stream.uptime)`, htmlOverlayHtmlDataPollSecondsInterval: 5, - htmlOverlayJs: '' + htmlOverlayJs: ` +// will be triggered, when new overlay data comes from backend +function onDataUpdate() { + console.log('updated') +} + ` }, createdAt: '', overlayId: '', diff --git a/frontend/overlays/src/components/htmlLayer.vue b/frontend/overlays/src/components/htmlLayer.vue index 434596e8b..8f7d6dd92 100644 --- a/frontend/overlays/src/components/htmlLayer.vue +++ b/frontend/overlays/src/components/htmlLayer.vue @@ -1,12 +1,22 @@