From a34a000b43089dcbcd843c3857eb79b0586df601 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl <rafael.lehmkuhl93@gmail.com> Date: Fri, 13 Dec 2024 15:58:25 -0300 Subject: [PATCH] data-lake: Rename "CockpitActionVariable" to "DataLakeVariable" --- src/components/ElementConfigPanel.vue | 94 ++++++++++--------- src/components/MiniWidgetInstantiator.vue | 12 +-- .../configuration/HttpRequestActionConfig.vue | 4 +- .../custom-widget-elements/Checkbox.vue | 24 ++--- .../custom-widget-elements/Dial.vue | 24 ++--- .../custom-widget-elements/Dropdown.vue | 24 ++--- .../custom-widget-elements/Label.vue | 18 ++-- .../custom-widget-elements/Slider.vue | 24 ++--- .../custom-widget-elements/Switch.vue | 24 ++--- src/components/widgets/Plotter.vue | 16 ++-- src/libs/actions/data-lake.ts | 69 +++++++------- src/libs/actions/http-request.ts | 8 +- src/libs/actions/mavlink-message-actions.ts | 6 +- src/libs/cosmos.ts | 60 ++++++------ src/stores/omniscientLogger.ts | 12 +-- src/stores/widgetManager.ts | 8 +- src/types/widgets.ts | 14 +-- 17 files changed, 216 insertions(+), 225 deletions(-) diff --git a/src/components/ElementConfigPanel.vue b/src/components/ElementConfigPanel.vue index 747db14dd..336ea85fa 100644 --- a/src/components/ElementConfigPanel.vue +++ b/src/components/ElementConfigPanel.vue @@ -246,33 +246,35 @@ <div class="flex w-full justify-between items-center h-[40px] border-b-[1px] border-[#FFFFFF33]"> <p class="text-center w-full text-sm">Action URL parameter</p> <v-btn - v-if="openNewActionVariableForm === false && currentElement.options.actionVariable?.name === undefined" + v-if=" + openNewDataLakeVariableForm === false && currentElement.options.dataLakeVariable?.name === undefined + " variant="elevated" class="bg-[#3B78A8] mr-[13px]" size="x-small" - @click="openNewActionVariableForm = true" + @click="openNewDataLakeVariableForm = true" >create</v-btn > </div> </template> - <template v-if="openNewActionVariableForm || currentElement.options.actionVariable?.name"> + <template v-if="openNewDataLakeVariableForm || currentElement.options.dataLakeVariable?.name"> <div class="flex justify-between items-center h-[40px] w-full border-b-[1px] border-[#FFFFFF33]" - :class="{ 'border-[1px] border-red-700': actionVariableError.includes('This name is already in use') }" + :class="{ 'border-[1px] border-red-700': dataLakeVariableError.includes('This name is already in use') }" > <p class="ml-1 text-[14px]">Name</p> - <input v-model="futureActionVariable.name" type="text" class="p-2 bg-[#FFFFFF11] w-[123px]" /> + <input v-model="futureDataLakeVariable.name" type="text" class="p-2 bg-[#FFFFFF11] w-[123px]" /> </div> <div class="flex justify-between items-center h-[40px] w-full border-b-[1px] border-[#FFFFFF33]"> <p class="ml-1 text-[14px]">Description</p> - <input v-model="futureActionVariable.description" type="text" class="p-2 bg-[#FFFFFF11] w-[123px]" /> + <input v-model="futureDataLakeVariable.description" type="text" class="p-2 bg-[#FFFFFF11] w-[123px]" /> </div> <div class="flex w-full justify-end"> <v-btn variant="text" size="x-small" class="mr-[15px] mt-2" - :disabled="currentElement.options.actionVariable === undefined" + :disabled="currentElement.options.dataLakeVariable === undefined" @click="deleteParameterFromDataLake" >delete</v-btn > @@ -281,11 +283,11 @@ size="x-small" class="bg-[#3B78A8] mr-1 mt-2" :class="{ - 'opacity-10': futureActionVariable.name === '', + 'opacity-10': futureDataLakeVariable.name === '', }" - :disabled="futureActionVariable.name === ''" + :disabled="futureDataLakeVariable.name === ''" @click="saveOrUpdateParameter" - >{{ currentElement.options.actionVariable === undefined ? 'save' : 'update' }}</v-btn + >{{ currentElement.options.dataLakeVariable === undefined ? 'save' : 'update' }}</v-btn > </div> </template> @@ -306,10 +308,10 @@ </template> </div> <div - v-if="actionVariableError.length > 0" + v-if="dataLakeVariableError.length > 0" class="flex justify-center items-center text-[14px] text-center h-[30px] bg-red-800 rounded-lg" > - <p v-for="message in actionVariableError" :key="message">• {{ message }}</p> + <p v-for="message in dataLakeVariableError" :key="message">• {{ message }}</p> </div> </template> </ExpansiblePanel> @@ -322,22 +324,22 @@ import { computed, onMounted, reactive, ref, watch } from 'vue' import ExpansiblePanel from '@/components/ExpansiblePanel.vue' import { useSnackbar } from '@/composables/snackbar' import { - createCockpitActionVariable, - deleteCockpitActionVariable, - getCockpitActionVariableInfo, - updateCockpitActionVariableInfo, + createDataLakeVariable, + deleteDataLakeVariable, + getDataLakeVariableInfo, + updateDataLakeVariableInfo, } from '@/libs/actions/data-lake' import { getAllHttpRequestActionConfigs, HttpRequestActionConfig } from '@/libs/actions/http-request' import { useAppInterfaceStore } from '@/stores/appInterface' import { useWidgetManagerStore } from '@/stores/widgetManager' -import { CockpitActionVariable, CustomWidgetElement, CustomWidgetElementType } from '@/types/widgets' +import { CustomWidgetElement, CustomWidgetElementType, DataLakeVariable } from '@/types/widgets' const widgetStore = useWidgetManagerStore() const interfaceStore = useAppInterfaceStore() const { showSnackbar } = useSnackbar() const currentElement = ref<CustomWidgetElement | undefined>(widgetStore.elementToShowOnDrawer) -const defaultActionVariable: CockpitActionVariable = { +const defaultDataLakeVariable: DataLakeVariable = { id: '', name: '', type: currentElement.value?.options.variableType, @@ -345,22 +347,22 @@ const defaultActionVariable: CockpitActionVariable = { } const availableCockpitActions = reactive<Record<string, HttpRequestActionConfig>>({}) -const futureActionVariable = ref<CockpitActionVariable>(defaultActionVariable) -const openNewActionVariableForm = ref(false) +const futureDataLakeVariable = ref<DataLakeVariable>(defaultDataLakeVariable) +const openNewDataLakeVariableForm = ref(false) const isOptionsMenuOpen = ref<{ [key: number]: boolean }>({}) -const actionVariableError = ref<string[]>([]) +const dataLakeVariableError = ref<string[]>([]) watch( () => widgetStore.elementToShowOnDrawer, (newValue) => { currentElement.value = newValue - futureActionVariable.value = newValue?.options.actionVariable || { + futureDataLakeVariable.value = newValue?.options.dataLakeVariable || { id: '', name: '', type: currentElement.value?.options.variableType, description: '', } - openNewActionVariableForm.value = false + openNewDataLakeVariableForm.value = false if (newValue && newValue.hash) { widgetStore.miniWidgetManagerVars(newValue.hash).configMenuOpen = false } @@ -377,16 +379,16 @@ const showActionExistsError = (): void => { message: 'Variable name already exists', variant: 'error', }) - actionVariableError.value.push('This name is already in use') + dataLakeVariableError.value.push('This name is already in use') setTimeout(() => { - actionVariableError.value.splice(0, 1) + dataLakeVariableError.value.splice(0, 1) }, 3000) } const deleteParameterFromDataLake = async (): Promise<void> => { - if (currentElement.value?.options.actionVariable?.name) { + if (currentElement.value?.options.dataLakeVariable?.name) { try { - await deleteCockpitActionVariable(currentElement.value.options.actionVariable) + await deleteDataLakeVariable(currentElement.value.options.dataLakeVariable) showSnackbar({ message: 'Action variable deleted', variant: 'success', @@ -397,37 +399,37 @@ const deleteParameterFromDataLake = async (): Promise<void> => { variant: 'error', }) } - futureActionVariable.value.name = '' - futureActionVariable.value = defaultActionVariable - currentElement.value.options.actionVariable = undefined - openNewActionVariableForm.value = false + futureDataLakeVariable.value.name = '' + futureDataLakeVariable.value = defaultDataLakeVariable + currentElement.value.options.dataLakeVariable = undefined + openNewDataLakeVariableForm.value = false } } const saveOrUpdateParameter = (): void => { - let newCockpitActionVariable = { - id: futureActionVariable.value?.id === '' ? futureActionVariable.value?.name : futureActionVariable.value?.id, - name: futureActionVariable.value?.name, + let newDataLakeVariable = { + id: futureDataLakeVariable.value?.id === '' ? futureDataLakeVariable.value?.name : futureDataLakeVariable.value?.id, + name: futureDataLakeVariable.value?.name, type: currentElement.value?.options.variableType, - description: futureActionVariable.value?.description, + description: futureDataLakeVariable.value?.description, } if ( currentElement.value && - futureActionVariable.value && - currentElement.value.options.actionVariable?.name === undefined // Knows that it's a new input element being named + futureDataLakeVariable.value && + currentElement.value.options.dataLakeVariable?.name === undefined // Knows that it's a new input element being named ) { - if (getCockpitActionVariableInfo(newCockpitActionVariable.id) !== undefined) { + if (getDataLakeVariableInfo(newDataLakeVariable.id) !== undefined) { showActionExistsError() return } - createCockpitActionVariable(newCockpitActionVariable) - currentElement.value.options.actionVariable = newCockpitActionVariable + createDataLakeVariable(newDataLakeVariable) + currentElement.value.options.dataLakeVariable = newDataLakeVariable return } - if (futureActionVariable.value && currentElement.value?.options.actionVariable?.name) { - newCockpitActionVariable.id = currentElement.value.options.actionVariable.id - updateCockpitActionVariableInfo(newCockpitActionVariable) - currentElement.value.options.actionVariable = newCockpitActionVariable + if (futureDataLakeVariable.value && currentElement.value?.options.dataLakeVariable?.name) { + newDataLakeVariable.id = currentElement.value.options.dataLakeVariable.id + updateDataLakeVariableInfo(newDataLakeVariable) + currentElement.value.options.dataLakeVariable = newDataLakeVariable } } @@ -509,8 +511,8 @@ const loadSavedActions = (): void => { } onMounted(() => { - if (currentElement.value?.options.actionVariable?.name) { - futureActionVariable.value = currentElement.value?.options.actionVariable + if (currentElement.value?.options.dataLakeVariable?.name) { + futureDataLakeVariable.value = currentElement.value?.options.dataLakeVariable } loadSavedActions() }) diff --git a/src/components/MiniWidgetInstantiator.vue b/src/components/MiniWidgetInstantiator.vue index 6acc253e8..70c7857cb 100644 --- a/src/components/MiniWidgetInstantiator.vue +++ b/src/components/MiniWidgetInstantiator.vue @@ -5,7 +5,7 @@ <script setup lang="ts"> import { defineAsyncComponent, onMounted, toRefs } from 'vue' -import { createCockpitActionVariable, getCockpitActionVariableInfo } from '@/libs/actions/data-lake' +import { createDataLakeVariable, getDataLakeVariableInfo } from '@/libs/actions/data-lake' import { useWidgetManagerStore } from '@/stores/widgetManager' import { type MiniWidget, CustomWidgetElement } from '@/types/widgets' @@ -37,13 +37,13 @@ const componentFromType = (componentType: string): ReturnType<typeof defineAsync const registerCockpitActions = (): void => { if ( - miniWidget.value.options.actionVariable && - getCockpitActionVariableInfo(miniWidget.value.options.actionVariable.id) !== undefined + miniWidget.value.options.dataLakeVariable && + getDataLakeVariableInfo(miniWidget.value.options.dataLakeVariable.id) !== undefined ) return - if (miniWidget.value.options.actionVariable) { - createCockpitActionVariable( - miniWidget.value.options.actionVariable, + if (miniWidget.value.options.dataLakeVariable) { + createDataLakeVariable( + miniWidget.value.options.dataLakeVariable, widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) ) } diff --git a/src/components/configuration/HttpRequestActionConfig.vue b/src/components/configuration/HttpRequestActionConfig.vue index f1f757334..4a9facc55 100644 --- a/src/components/configuration/HttpRequestActionConfig.vue +++ b/src/components/configuration/HttpRequestActionConfig.vue @@ -306,7 +306,7 @@ import { computed, onMounted, reactive, ref } from 'vue' import ExpansiblePanel from '@/components/ExpansiblePanel.vue' import { openSnackbar } from '@/composables/snackbar' -import { getAllCockpitActionVariablesInfo } from '@/libs/actions/data-lake' +import { getAllDataLakeVariablesInfo } from '@/libs/actions/data-lake' import { availableHttpRequestMethods, deleteHttpRequestActionConfig, @@ -355,7 +355,7 @@ const headerDialog = ref({ const paramValueOptions = computed(() => { const options = [{ title: 'Fixed (specify below)', value: 'fixed' }] - const availableInputParameters = getAllCockpitActionVariablesInfo() + const availableInputParameters = getAllDataLakeVariablesInfo() Object.values(availableInputParameters).forEach((parameter) => { options.push({ title: parameter.id, value: parameter.id }) }) diff --git a/src/components/custom-widget-elements/Checkbox.vue b/src/components/custom-widget-elements/Checkbox.vue index 91e9a2f7e..2e326ea4f 100644 --- a/src/components/custom-widget-elements/Checkbox.vue +++ b/src/components/custom-widget-elements/Checkbox.vue @@ -28,10 +28,10 @@ import { onMounted, onUnmounted, ref, toRefs, watch } from 'vue' import { - deleteCockpitActionVariable, - listenCockpitActionVariable, - setCockpitActionVariableData, - unlistenCockpitActionVariable, + deleteDataLakeVariable, + listenDataLakeVariable, + setDataLakeVariableData, + unlistenDataLakeVariable, } from '@/libs/actions/data-lake' import { useWidgetManagerStore } from '@/stores/widgetManager' import { CustomWidgetElementOptions, CustomWidgetElementType } from '@/types/widgets' @@ -51,8 +51,8 @@ const isChecked = ref(false) const handleToggleAction = (): void => { if (widgetStore.editingMode) return widgetStore.setMiniWidgetLastValue(miniWidget.value.hash, isChecked.value) - if (miniWidget.value.options.actionVariable) { - setCockpitActionVariableData(miniWidget.value.options.actionVariable.name, isChecked.value) + if (miniWidget.value.options.dataLakeVariable) { + setDataLakeVariableData(miniWidget.value.options.dataLakeVariable.name, isChecked.value) } } @@ -79,11 +79,11 @@ onMounted(() => { color: '#FFFFFF', }, variableType: 'boolean', - actionVariable: undefined, + dataLakeVariable: undefined, }) } - if (miniWidget.value.options.actionVariable) { - listenCockpitActionVariable(miniWidget.value.options.actionVariable.name, (value) => { + if (miniWidget.value.options.dataLakeVariable) { + listenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name, (value) => { isChecked.value = value as boolean }) isChecked.value = widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) as boolean @@ -91,9 +91,9 @@ onMounted(() => { }) onUnmounted(() => { - if (miniWidget.value.options.actionVariable) { - unlistenCockpitActionVariable(miniWidget.value.options.actionVariable.name) - deleteCockpitActionVariable(miniWidget.value.options.actionVariable.id) + if (miniWidget.value.options.dataLakeVariable) { + unlistenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name) + deleteDataLakeVariable(miniWidget.value.options.dataLakeVariable.id) } }) </script> diff --git a/src/components/custom-widget-elements/Dial.vue b/src/components/custom-widget-elements/Dial.vue index 3fa8e19ff..a1c454611 100644 --- a/src/components/custom-widget-elements/Dial.vue +++ b/src/components/custom-widget-elements/Dial.vue @@ -38,10 +38,10 @@ import { computed, onMounted, onUnmounted, ref, toRefs, watch } from 'vue' import { - deleteCockpitActionVariable, - listenCockpitActionVariable, - setCockpitActionVariableData, - unlistenCockpitActionVariable, + deleteDataLakeVariable, + listenDataLakeVariable, + setDataLakeVariableData, + unlistenDataLakeVariable, } from '@/libs/actions/data-lake' import { useWidgetManagerStore } from '@/stores/widgetManager' import { CustomWidgetElementOptions, CustomWidgetElementType } from '@/types/widgets' @@ -102,11 +102,11 @@ onMounted(() => { notchColor: '#303030aa', }, variableType: 'number', - actionVariable: undefined, + dataLakeVariable: undefined, }) } - if (miniWidget.value.options.actionVariable) { - listenCockpitActionVariable(miniWidget.value.options.actionVariable?.name, (value) => { + if (miniWidget.value.options.dataLakeVariable) { + listenDataLakeVariable(miniWidget.value.options.dataLakeVariable?.name, (value) => { setDialValue(value as number) }) const initialValue = widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) @@ -165,10 +165,10 @@ const startDrag = (event: MouseEvent): void => { potentiometerValue.value = ((newRotationAngle + 150) / rotationRange) * valueRange + miniWidget.value.options.layout?.minValue - if (miniWidget.value.options.actionVariable) { + if (miniWidget.value.options.dataLakeVariable) { if (widgetStore.editingMode) return widgetStore.setMiniWidgetLastValue(miniWidget.value.hash, Math.round(potentiometerValue.value)) - setCockpitActionVariableData(miniWidget.value.options.actionVariable.name, Math.round(potentiometerValue.value)) + setDataLakeVariableData(miniWidget.value.options.dataLakeVariable.name, Math.round(potentiometerValue.value)) } } @@ -182,9 +182,9 @@ const startDrag = (event: MouseEvent): void => { } onUnmounted(() => { - if (miniWidget.value.options.actionVariable) { - unlistenCockpitActionVariable(miniWidget.value.options.actionVariable.name) - deleteCockpitActionVariable(miniWidget.value.options.actionVariable.id) + if (miniWidget.value.options.dataLakeVariable) { + unlistenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name) + deleteDataLakeVariable(miniWidget.value.options.dataLakeVariable.id) } }) </script> diff --git a/src/components/custom-widget-elements/Dropdown.vue b/src/components/custom-widget-elements/Dropdown.vue index 7b0f49bc8..20220a7ca 100644 --- a/src/components/custom-widget-elements/Dropdown.vue +++ b/src/components/custom-widget-elements/Dropdown.vue @@ -34,10 +34,10 @@ import { computed, onMounted, onUnmounted, ref, toRefs, watch } from 'vue' import { - deleteCockpitActionVariable, - listenCockpitActionVariable, - setCockpitActionVariableData, - unlistenCockpitActionVariable, + deleteDataLakeVariable, + listenDataLakeVariable, + setDataLakeVariableData, + unlistenDataLakeVariable, } from '@/libs/actions/data-lake' import { useWidgetManagerStore } from '@/stores/widgetManager' import { CustomWidgetElementOptions, CustomWidgetElementType, SelectorOption } from '@/types/widgets' @@ -92,8 +92,8 @@ const handleSelection = (value: string | number | boolean): void => { selectedValue.value = value - if (miniWidget.value.options.actionVariable) { - setCockpitActionVariableData(miniWidget.value.options.actionVariable.id, value) + if (miniWidget.value.options.dataLakeVariable) { + setDataLakeVariableData(miniWidget.value.options.dataLakeVariable.id, value) } widgetStore.setMiniWidgetLastValue(miniWidget.value.hash, selected.value) } @@ -108,11 +108,11 @@ onMounted(() => { width: 168, }, variableType: 'string', - actionVariable: undefined, + dataLakeVariable: undefined, }) } - if (miniWidget.value.options.actionVariable) { - listenCockpitActionVariable(miniWidget.value.options.actionVariable.name, (value) => { + if (miniWidget.value.options.dataLakeVariable) { + listenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name, (value) => { selectedOption.value = options.value.find((option) => option.value === value) }) const storedValue = widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) @@ -124,9 +124,9 @@ onMounted(() => { }) onUnmounted(() => { - if (miniWidget.value.options.actionVariable) { - unlistenCockpitActionVariable(miniWidget.value.options.actionVariable.name) - deleteCockpitActionVariable(miniWidget.value.options.actionVariable.id) + if (miniWidget.value.options.dataLakeVariable) { + unlistenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name) + deleteDataLakeVariable(miniWidget.value.options.dataLakeVariable.id) } }) </script> diff --git a/src/components/custom-widget-elements/Label.vue b/src/components/custom-widget-elements/Label.vue index 25ffdb2d6..514c9491e 100644 --- a/src/components/custom-widget-elements/Label.vue +++ b/src/components/custom-widget-elements/Label.vue @@ -27,11 +27,7 @@ <script setup lang="ts"> import { onMounted, onUnmounted, toRefs, watch } from 'vue' -import { - deleteCockpitActionVariable, - listenCockpitActionVariable, - unlistenCockpitActionVariable, -} from '@/libs/actions/data-lake' +import { deleteDataLakeVariable, listenDataLakeVariable, unlistenDataLakeVariable } from '@/libs/actions/data-lake' import { useWidgetManagerStore } from '@/stores/widgetManager' import { CustomWidgetElementOptions, CustomWidgetElementType } from '@/types/widgets' @@ -72,11 +68,11 @@ onMounted(() => { align: 'center', }, variableType: 'string', - actionVariable: undefined, + dataLakeVariable: undefined, }) } - if (props.miniWidget.options.actionVariable) { - listenCockpitActionVariable(props.miniWidget.options.actionVariable?.name, (value) => { + if (props.miniWidget.options.dataLakeVariable) { + listenDataLakeVariable(props.miniWidget.options.dataLakeVariable?.name, (value) => { miniWidget.value.options.text = value as string }) miniWidget.value.options.text = widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) as string @@ -84,9 +80,9 @@ onMounted(() => { }) onUnmounted(() => { - if (miniWidget.value.options.actionVariable) { - unlistenCockpitActionVariable(miniWidget.value.options.actionVariable.name) - deleteCockpitActionVariable(miniWidget.value.options.actionVariable.id) + if (miniWidget.value.options.dataLakeVariable) { + unlistenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name) + deleteDataLakeVariable(miniWidget.value.options.dataLakeVariable.id) } }) </script> diff --git a/src/components/custom-widget-elements/Slider.vue b/src/components/custom-widget-elements/Slider.vue index 0bd14395f..aef3e1cfa 100644 --- a/src/components/custom-widget-elements/Slider.vue +++ b/src/components/custom-widget-elements/Slider.vue @@ -35,10 +35,10 @@ import { toRefs } from '@vueuse/core' import { onMounted, onUnmounted, ref, watch } from 'vue' import { - deleteCockpitActionVariable, - listenCockpitActionVariable, - setCockpitActionVariableData, - unlistenCockpitActionVariable, + deleteDataLakeVariable, + listenDataLakeVariable, + setDataLakeVariableData, + unlistenDataLakeVariable, } from '@/libs/actions/data-lake' import { useWidgetManagerStore } from '@/stores/widgetManager' import { CustomWidgetElementOptions, CustomWidgetElementType } from '@/types/widgets' @@ -71,9 +71,9 @@ watch( const handleSliderChange = (): void => { if (widgetStore.editingMode) return - if (miniWidget.value.options.actionVariable) { + if (miniWidget.value.options.dataLakeVariable) { widgetStore.setMiniWidgetLastValue(miniWidget.value.hash, sliderValue.value.toFixed(1)) - setCockpitActionVariableData(miniWidget.value.options.actionVariable.name, sliderValue.value.toFixed(1)) + setDataLakeVariableData(miniWidget.value.options.dataLakeVariable.name, sliderValue.value.toFixed(1)) } } @@ -90,11 +90,11 @@ onMounted(() => { labelWidth: miniWidget.value.options.layout?.labelWidth || 0, }, variableType: 'number', - actionVariable: undefined, + dataLakeVariable: undefined, }) } - if (miniWidget.value.options.actionVariable) { - listenCockpitActionVariable(miniWidget.value.options.actionVariable?.name, (value) => { + if (miniWidget.value.options.dataLakeVariable) { + listenDataLakeVariable(miniWidget.value.options.dataLakeVariable?.name, (value) => { sliderValue.value = value as number }) sliderValue.value = widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) as number @@ -102,9 +102,9 @@ onMounted(() => { }) onUnmounted(() => { - if (miniWidget.value.options.actionVariable) { - unlistenCockpitActionVariable(miniWidget.value.options.actionVariable.name) - deleteCockpitActionVariable(miniWidget.value.options.actionVariable.id) + if (miniWidget.value.options.dataLakeVariable) { + unlistenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name) + deleteDataLakeVariable(miniWidget.value.options.dataLakeVariable.id) } }) </script> diff --git a/src/components/custom-widget-elements/Switch.vue b/src/components/custom-widget-elements/Switch.vue index ff1173731..eee4361c6 100644 --- a/src/components/custom-widget-elements/Switch.vue +++ b/src/components/custom-widget-elements/Switch.vue @@ -26,10 +26,10 @@ import { onMounted, onUnmounted, ref, toRefs, watch } from 'vue' import { - deleteCockpitActionVariable, - listenCockpitActionVariable, - setCockpitActionVariableData, - unlistenCockpitActionVariable, + deleteDataLakeVariable, + listenDataLakeVariable, + setDataLakeVariableData, + unlistenDataLakeVariable, } from '@/libs/actions/data-lake' import { useWidgetManagerStore } from '@/stores/widgetManager' import { CustomWidgetElementOptions, CustomWidgetElementType } from '@/types/widgets' @@ -61,9 +61,9 @@ watch( const handleToggleAction = (): void => { if (widgetStore.editingMode) return - if (miniWidget.value.options.actionVariable) { + if (miniWidget.value.options.dataLakeVariable) { widgetStore.setMiniWidgetLastValue(miniWidget.value.hash, switchValue.value) - setCockpitActionVariableData(miniWidget.value.options.actionVariable.name, switchValue.value) + setDataLakeVariableData(miniWidget.value.options.dataLakeVariable.name, switchValue.value) } } @@ -77,13 +77,13 @@ onMounted(() => { label: miniWidget.value.options.layout?.label || '', }, variableType: 'boolean', - actionVariable: undefined, + dataLakeVariable: undefined, toggled: true, }) switchValue.value = true - } else if (miniWidget.value.options.actionVariable) { - listenCockpitActionVariable(miniWidget.value.options.actionVariable.name, (value) => { + } else if (miniWidget.value.options.dataLakeVariable) { + listenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name, (value) => { switchValue.value = value as boolean }) switchValue.value = widgetStore.getMiniWidgetLastValue(miniWidget.value.hash) as boolean @@ -91,9 +91,9 @@ onMounted(() => { }) onUnmounted(() => { - if (miniWidget.value.options.actionVariable) { - unlistenCockpitActionVariable(miniWidget.value.options.actionVariable.name) - deleteCockpitActionVariable(miniWidget.value.options.actionVariable.id) + if (miniWidget.value.options.dataLakeVariable) { + unlistenDataLakeVariable(miniWidget.value.options.dataLakeVariable.name) + deleteDataLakeVariable(miniWidget.value.options.dataLakeVariable.id) } }) </script> diff --git a/src/components/widgets/Plotter.vue b/src/components/widgets/Plotter.vue index 88ef8d344..97bd8c77c 100644 --- a/src/components/widgets/Plotter.vue +++ b/src/components/widgets/Plotter.vue @@ -116,10 +116,10 @@ import { useElementVisibility, useWindowSize } from '@vueuse/core' import { computed, nextTick, onBeforeMount, onMounted, ref, toRefs, watch } from 'vue' import { - CockpitActionVariable, - getAllCockpitActionVariablesInfo, - listenCockpitActionVariable, - unlistenCockpitActionVariable, + DataLakeVariable, + getAllDataLakeVariablesInfo, + listenDataLakeVariable, + unlistenDataLakeVariable, } from '@/libs/actions/data-lake' import { resetCanvas } from '@/libs/utils' import { useAppInterfaceStore } from '@/stores/appInterface' @@ -138,7 +138,7 @@ const props = defineProps<{ widget: Widget }>() const widget = toRefs(props).widget -const availableDataLakeVariables = ref<CockpitActionVariable[]>([]) +const availableDataLakeVariables = ref<DataLakeVariable[]>([]) onBeforeMount(() => { // Set initial widget options if they don't exist @@ -156,7 +156,7 @@ onBeforeMount(() => { onMounted(() => { changeDataLakeVariable(widget.value.options.dataLakeVariableId) - availableDataLakeVariables.value = Object.values(getAllCockpitActionVariablesInfo()).filter( + availableDataLakeVariables.value = Object.values(getAllDataLakeVariablesInfo()).filter( (variable) => variable.type === 'number' ) }) @@ -181,10 +181,10 @@ const changeDataLakeVariable = (newId: string): void => { const oldId = widget.value.options.dataLakeVariableId if (oldId !== undefined) { - unlistenCockpitActionVariable(oldId) + unlistenDataLakeVariable(oldId) } - listenCockpitActionVariable(newId, (value) => { + listenDataLakeVariable(newId, (value) => { valuesHistory.push(value as number) cutExtraSamples() diff --git a/src/libs/actions/data-lake.ts b/src/libs/actions/data-lake.ts index faa3072fe..45f7ca782 100644 --- a/src/libs/actions/data-lake.ts +++ b/src/libs/actions/data-lake.ts @@ -5,7 +5,7 @@ * @param { 'string' | 'number' | 'boolean' } type - The type of the variable (string, number or boolean) * @param { string } description - What the variable does or means */ -export class CockpitActionVariable { +export class DataLakeVariable { id: string name: string type: 'string' | 'number' | 'boolean' @@ -19,65 +19,62 @@ export class CockpitActionVariable { } } -const cockpitActionVariableInfo: Record<string, CockpitActionVariable> = {} -export const cockpitActionVariableData: Record<string, string | number | boolean | undefined> = {} -const cockpitActionVariableListeners: Record<string, ((value: string | number | boolean) => void)[]> = {} +const dataLakeVariableInfo: Record<string, DataLakeVariable> = {} +export const dataLakeVariableData: Record<string, string | number | boolean | undefined> = {} +const dataLakeVariableListeners: Record<string, ((value: string | number | boolean) => void)[]> = {} -export const getAllCockpitActionVariablesInfo = (): Record<string, CockpitActionVariable> => { - return cockpitActionVariableInfo +export const getAllDataLakeVariablesInfo = (): Record<string, DataLakeVariable> => { + return dataLakeVariableInfo } -export const getCockpitActionVariableInfo = (id: string): CockpitActionVariable | undefined => { - return cockpitActionVariableInfo[id] +export const getDataLakeVariableInfo = (id: string): DataLakeVariable | undefined => { + return dataLakeVariableInfo[id] } -export const createCockpitActionVariable = ( - variable: CockpitActionVariable, - initialValue?: string | number | boolean -): void => { - if (cockpitActionVariableInfo[variable.id]) { +export const createDataLakeVariable = (variable: DataLakeVariable, initialValue?: string | number | boolean): void => { + if (dataLakeVariableInfo[variable.id]) { throw new Error(`Cockpit action variable with id '${variable.id}' already exists. Update it instead.`) } - cockpitActionVariableInfo[variable.id] = variable - cockpitActionVariableData[variable.id] = initialValue + dataLakeVariableInfo[variable.id] = variable + dataLakeVariableData[variable.id] = initialValue } -export const updateCockpitActionVariableInfo = (variable: CockpitActionVariable): void => { - if (!cockpitActionVariableInfo[variable.id]) { +export const updateDataLakeVariableInfo = (variable: DataLakeVariable): void => { + if (!dataLakeVariableInfo[variable.id]) { throw new Error(`Cockpit action variable with id '${variable.id}' does not exist. Create it first.`) } - cockpitActionVariableInfo[variable.id] = variable + dataLakeVariableInfo[variable.id] = variable } -export const getCockpitActionVariableData = (id: string): string | number | boolean | undefined => { - return cockpitActionVariableData[id] +export const getDataLakeVariableData = (id: string): string | number | boolean | undefined => { + return dataLakeVariableData[id] } -export const setCockpitActionVariableData = (id: string, data: string | number | boolean): void => { - cockpitActionVariableData[id] = data - notifyCockpitActionVariableListeners(id) +export const setDataLakeVariableData = (id: string, data: string | number | boolean): void => { + dataLakeVariableData[id] = data + notifyDataLakeVariableListeners(id) } -export const deleteCockpitActionVariable = (id: string): void => { - delete cockpitActionVariableInfo[id] - delete cockpitActionVariableData[id] +export const deleteDataLakeVariable = (id: string): void => { + delete dataLakeVariableInfo[id] + delete dataLakeVariableData[id] } -export const listenCockpitActionVariable = (id: string, listener: (value: string | number | boolean) => void): void => { - if (!cockpitActionVariableListeners[id]) { - cockpitActionVariableListeners[id] = [] +export const listenDataLakeVariable = (id: string, listener: (value: string | number | boolean) => void): void => { + if (!dataLakeVariableListeners[id]) { + dataLakeVariableListeners[id] = [] } - cockpitActionVariableListeners[id].push(listener) + dataLakeVariableListeners[id].push(listener) } -export const unlistenCockpitActionVariable = (id: string): void => { - delete cockpitActionVariableListeners[id] +export const unlistenDataLakeVariable = (id: string): void => { + delete dataLakeVariableListeners[id] } -const notifyCockpitActionVariableListeners = (id: string): void => { - if (cockpitActionVariableListeners[id]) { - const value = cockpitActionVariableData[id] +const notifyDataLakeVariableListeners = (id: string): void => { + if (dataLakeVariableListeners[id]) { + const value = dataLakeVariableData[id] if (value === undefined) return - cockpitActionVariableListeners[id].forEach((listener) => listener(value)) + dataLakeVariableListeners[id].forEach((listener) => listener(value)) } } diff --git a/src/libs/actions/http-request.ts b/src/libs/actions/http-request.ts index 97bfa2ea6..bccbb165e 100644 --- a/src/libs/actions/http-request.ts +++ b/src/libs/actions/http-request.ts @@ -6,7 +6,7 @@ import { registerActionCallback, registerNewAction, } from '../joystick/protocols/cockpit-actions' -import { getCockpitActionVariableData, getCockpitActionVariableInfo } from './data-lake' +import { getDataLakeVariableData, getDataLakeVariableInfo } from './data-lake' const httpRequestActionIdPrefix = 'http-request-action' @@ -128,8 +128,8 @@ export const getHttpRequestActionCallback = (id: string): HttpRequestActionCallb for (const input of cockpitInputsInBody) { try { const parsedInput = input.replace('{{', '').replace('}}', '').trim() - const inputData = getCockpitActionVariableData(parsedInput) - const variableInfo = getCockpitActionVariableInfo(parsedInput) + const inputData = getDataLakeVariableData(parsedInput) + const variableInfo = getDataLakeVariableInfo(parsedInput) if (inputData !== undefined) { let valueToReplace: string @@ -198,7 +198,7 @@ export const getHttpRequestActionCallback = (id: string): HttpRequestActionCallb for (const [key, value] of cockpitInputsInUrlParams) { try { const parsedInput = value.replace('{{', '').replace('}}', '').trim() - const inputData = getCockpitActionVariableData(parsedInput) + const inputData = getDataLakeVariableData(parsedInput) if (inputData) { parsedUrlParams[key] = inputData.toString() } diff --git a/src/libs/actions/mavlink-message-actions.ts b/src/libs/actions/mavlink-message-actions.ts index 7f4b9b46a..b70d48fb2 100644 --- a/src/libs/actions/mavlink-message-actions.ts +++ b/src/libs/actions/mavlink-message-actions.ts @@ -9,7 +9,7 @@ import { registerActionCallback, registerNewAction, } from '../joystick/protocols/cockpit-actions' -import { getCockpitActionVariableData } from './data-lake' +import { getDataLakeVariableData } from './data-lake' const mavlinkMessageActionIdPrefix = 'mavlink-message-action' @@ -135,7 +135,7 @@ const processMessageConfig = (config: MavlinkMessageConfig): Record<string, any> if (typeof config === 'string') { const configWithDynamicValues = config.replace(/{{\s*([^{}\s]+)\s*}}/g, (match, p1) => { - const variableValue = getCockpitActionVariableData(p1) + const variableValue = getDataLakeVariableData(p1) return variableValue ? variableValue.toString() : match }) processedConfig = JSON.parse(configWithDynamicValues) @@ -143,7 +143,7 @@ const processMessageConfig = (config: MavlinkMessageConfig): Record<string, any> for (const [k, v] of Object.entries(config)) { if (typeof v.value === 'string' && v.value.startsWith('{{') && v.value.endsWith('}}')) { const variableName = v.value.slice(2, -2).trim() - const variableValue = getCockpitActionVariableData(variableName) + const variableValue = getDataLakeVariableData(variableName) processedConfig[k] = typeof variableValue === 'boolean' ? (variableValue ? 1 : 0) : variableValue } else if (v.type === MessageFieldType.TYPE_STRUCT_ENUM) { processedConfig[k] = { type: v.value } diff --git a/src/libs/cosmos.ts b/src/libs/cosmos.ts index 41cc98050..1d875983f 100644 --- a/src/libs/cosmos.ts +++ b/src/libs/cosmos.ts @@ -3,16 +3,16 @@ import { isBrowser } from 'browser-or-node' import { NetworkInfo } from '@/types/network' import { - cockpitActionVariableData, - createCockpitActionVariable, - deleteCockpitActionVariable, - getAllCockpitActionVariablesInfo, - getCockpitActionVariableData, - getCockpitActionVariableInfo, - listenCockpitActionVariable, - setCockpitActionVariableData, - unlistenCockpitActionVariable, - updateCockpitActionVariableInfo, + createDataLakeVariable, + dataLakeVariableData, + deleteDataLakeVariable, + getAllDataLakeVariablesInfo, + getDataLakeVariableData, + getDataLakeVariableInfo, + listenDataLakeVariable, + setDataLakeVariableData, + unlistenDataLakeVariable, + updateDataLakeVariableInfo, } from './actions/data-lake' import { availableCockpitActions, @@ -86,16 +86,16 @@ declare global { interface Window { cockpit: { // Data lake: - cockpitActionVariableData: typeof cockpitActionVariableData - getCockpitActionVariableData: typeof getCockpitActionVariableData - listenCockpitActionVariable: typeof listenCockpitActionVariable - unlistenCockpitActionVariable: typeof unlistenCockpitActionVariable - getAllCockpitActionVariablesInfo: typeof getAllCockpitActionVariablesInfo - getCockpitActionVariableInfo: typeof getCockpitActionVariableInfo - setCockpitActionVariableData: typeof setCockpitActionVariableData - createCockpitActionVariable: typeof createCockpitActionVariable - updateCockpitActionVariableInfo: typeof updateCockpitActionVariableInfo - deleteCockpitActionVariable: typeof deleteCockpitActionVariable + dataLakeVariableData: typeof dataLakeVariableData + getDataLakeVariableData: typeof getDataLakeVariableData + listenDataLakeVariable: typeof listenDataLakeVariable + unlistenDataLakeVariable: typeof unlistenDataLakeVariable + getAllDataLakeVariablesInfo: typeof getAllDataLakeVariablesInfo + getDataLakeVariableInfo: typeof getDataLakeVariableInfo + setDataLakeVariableData: typeof setDataLakeVariableData + createDataLakeVariable: typeof createDataLakeVariable + updateDataLakeVariableInfo: typeof updateDataLakeVariableInfo + deleteDataLakeVariable: typeof deleteDataLakeVariable // Cockpit actions: availableCockpitActions: typeof availableCockpitActions registerNewAction: typeof registerNewAction @@ -126,16 +126,16 @@ if (isBrowser) { // Expose data-lake and cockpit action methods to the global scope under a "cockpit" property window.cockpit = { // Data lake: - cockpitActionVariableData: cockpitActionVariableData, - getCockpitActionVariableData: getCockpitActionVariableData, - listenCockpitActionVariable: listenCockpitActionVariable, - unlistenCockpitActionVariable: unlistenCockpitActionVariable, - getAllCockpitActionVariablesInfo: getAllCockpitActionVariablesInfo, - getCockpitActionVariableInfo: getCockpitActionVariableInfo, - setCockpitActionVariableData: setCockpitActionVariableData, - createCockpitActionVariable: createCockpitActionVariable, - updateCockpitActionVariableInfo: updateCockpitActionVariableInfo, - deleteCockpitActionVariable: deleteCockpitActionVariable, + dataLakeVariableData: dataLakeVariableData, + getDataLakeVariableData: getDataLakeVariableData, + listenDataLakeVariable: listenDataLakeVariable, + unlistenDataLakeVariable: unlistenDataLakeVariable, + getAllDataLakeVariablesInfo: getAllDataLakeVariablesInfo, + getDataLakeVariableInfo: getDataLakeVariableInfo, + setDataLakeVariableData: setDataLakeVariableData, + createDataLakeVariable: createDataLakeVariable, + updateDataLakeVariableInfo: updateDataLakeVariableInfo, + deleteDataLakeVariable: deleteDataLakeVariable, // Cockpit actions: availableCockpitActions: availableCockpitActions, registerNewAction: registerNewAction, diff --git a/src/stores/omniscientLogger.ts b/src/stores/omniscientLogger.ts index 119b4f60f..96c0a7b51 100644 --- a/src/stores/omniscientLogger.ts +++ b/src/stores/omniscientLogger.ts @@ -4,11 +4,7 @@ import { differenceInSeconds } from 'date-fns' import { defineStore } from 'pinia' import { ref, watch } from 'vue' -import { - CockpitActionVariable, - createCockpitActionVariable, - setCockpitActionVariableData, -} from '@/libs/actions/data-lake' +import { createDataLakeVariable, DataLakeVariable, setDataLakeVariableData } from '@/libs/actions/data-lake' import eventTracker from '@/libs/external-telemetry/event-tracking' import { WebRTCStatsEvent, WebRTCVideoStat } from '@/types/video' @@ -20,17 +16,17 @@ export const useOmniscientLoggerStore = defineStore('omniscient-logger', () => { const videoStore = useVideoStore() // Routine to log the memory usage of the application - const cockpitMemoryUsageVariable = new CockpitActionVariable( + const cockpitMemoryUsageVariable = new DataLakeVariable( 'cockpit-memory-usage', 'Cockpit Memory Usage', 'number', 'The memory usage of the Cockpit application in MB. This value is updated every 100ms.' ) - createCockpitActionVariable(cockpitMemoryUsageVariable) + createDataLakeVariable(cockpitMemoryUsageVariable) setInterval(() => { const currentMemoryUsage = window.performance.memory.usedJSHeapSize / 1024 / 1024 - setCockpitActionVariableData(cockpitMemoryUsageVariable.id, currentMemoryUsage) + setDataLakeVariableData(cockpitMemoryUsageVariable.id, currentMemoryUsage) }, 100) // Routine to log the framerate of the video streams diff --git a/src/stores/widgetManager.ts b/src/stores/widgetManager.ts index 4d83a07e9..551de6da2 100644 --- a/src/stores/widgetManager.ts +++ b/src/stores/widgetManager.ts @@ -176,10 +176,10 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => { element.hash = uuid4() hashMap.set(oldHash, element.hash) - if (element.options && element.options.actionVariable) { - const actionVariable = element.options.actionVariable - actionVariable.id = `${actionVariable.id}_new` - actionVariable.name = `${actionVariable.name}_new` + if (element.options && element.options.dataLakeVariable) { + const dataLakeVariable = element.options.dataLakeVariable + dataLakeVariable.id = `${dataLakeVariable.id}_new` + dataLakeVariable.name = `${dataLakeVariable.name}_new` } } diff --git a/src/types/widgets.ts b/src/types/widgets.ts index 0924bd394..820cfaeb8 100644 --- a/src/types/widgets.ts +++ b/src/types/widgets.ts @@ -99,7 +99,7 @@ export type SelectorOption = { /** * Options for the Cockpit Actions parameters */ -export interface CockpitActionVariable { +export interface DataLakeVariable { /** * Parameter ID, equals to initial name of the parameter */ @@ -149,7 +149,7 @@ export type CustomWidgetElementOptions = { /** * Action parameter */ - actionVariable: CockpitActionVariable + dataLakeVariable: DataLakeVariable /** * The label text */ @@ -267,7 +267,7 @@ export type CustomWidgetElementOptions = { /** * Action parameter */ - actionVariable: CockpitActionVariable + dataLakeVariable: DataLakeVariable /** * Layout props for the element */ @@ -314,7 +314,7 @@ export type CustomWidgetElementOptions = { /** * Action parameter */ - actionVariable: CockpitActionVariable + dataLakeVariable: DataLakeVariable /** * Layout options */ @@ -377,7 +377,7 @@ export type CustomWidgetElementOptions = { /** * Action parameter */ - actionVariable: CockpitActionVariable + dataLakeVariable: DataLakeVariable /** * Last selected value */ @@ -428,7 +428,7 @@ export type CustomWidgetElementOptions = { /** * Action parameter */ - actionVariable: CockpitActionVariable + dataLakeVariable: DataLakeVariable /** * Layout options */ @@ -495,7 +495,7 @@ export type CustomWidgetElementOptions = { /** * Action parameter */ - actionVariable: CockpitActionVariable + dataLakeVariable: DataLakeVariable /** * Layout options */