make new folder for reuse ngLib add new features for datatree like change add remove rename datapoints improve pingpong

This commit is contained in:
Adrian Zuercher
2025-07-25 18:37:18 +02:00
parent ffb8e4994e
commit 81b7f96abc
52 changed files with 2145 additions and 960 deletions

View File

@@ -1,180 +0,0 @@
<template>
<q-card>
<div class="row">
<q-card-section class="col-4 scroll tree-container">
<q-tree
class="text-blue text-bold"
dense
:nodes="dbmData"
node-key="key"
no-transition
:default-expand-all="false"
v-model:expanded="expanded"
@update:expanded="onExpandedChange"
@lazy-load="onLazyLoad"
>
<template v-slot:[`default-header`]="props">
<div
class="row items-center text-blue"
@contextmenu.prevent.stop="openSubMenu($event, props.node.key)"
>
<div class="row items-center text-blue"></div>
<div>{{ props.node.path }}</div>
</div>
</template>
</q-tree>
<!-- not implemented yet <sub-menu ref="subMenuRef"></sub-menu> -->
</q-card-section>
<dataTable class="col-8" :rows="getRows()" />
</div>
</q-card>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import {
type TreeNode,
buildTree,
dbmData,
removeSubtreeByParentKey,
} from 'src/composables/dbm/dbmTree';
import DataTable from './DataTable.vue';
import { useQuasar } from 'quasar';
import { NotifyResponse } from 'src/composables/notify';
import { QCard } from 'quasar';
import { subscribe, unsubscribe } from 'src/services/websocket';
import { onBeforeRouteLeave } from 'vue-router';
import { api } from 'boot/axios';
// not implemented yet import SubMenu from './SubMenu.vue';
import { type Subs, type RawSubs, convertToSubscribes } from 'src/models/Subscribe';
import { addSubscriptions, getRows, removeAllSubscriptions } from 'src/models/Subscriptions';
const $q = useQuasar();
const expanded = ref<string[]>([]);
const ZERO_UUID = '00000000-0000-0000-0000-000000000000';
let lastExpanded: string[] = [];
const postQuery = '/json_data';
onMounted(() => {
api
.post(postQuery, { get: [{ path: '.*', query: { depth: 1 } }] })
.then((res) => {
if (res.data.get) buildTree(convertToSubscribes(res.data.get as RawSubs));
})
.catch((err) => NotifyResponse($q, err, 'error'));
});
onBeforeRouteLeave(() => {
unsubscribe([{ path: '.*', depth: 0 }]).catch((err) => NotifyResponse($q, err, 'error'));
});
function onLazyLoad({
node,
done,
fail,
}: {
node: TreeNode;
done: (children: TreeNode[]) => void;
fail: () => void;
}): void {
api
.post(postQuery, { get: [{ uuid: node.key ?? ZERO_UUID, path: '', query: { depth: 2 } }] })
.then((resp) => {
if (resp?.data.get) done(buildTree(convertToSubscribes(resp?.data.get as RawSubs)));
else done([]); // no children returned
})
.catch((err) => {
NotifyResponse($q, err, 'error');
fail(); // trigger the fail handler
});
}
async function onExpandedChange(newExpanded: readonly string[]) {
const collapsed = lastExpanded.filter((k) => !newExpanded.includes(k));
const newlyExpanded = newExpanded.filter((k) => !lastExpanded.includes(k));
try {
await unsubscribe([{ path: '.*', depth: 0 }])
.then(() => {
removeAllSubscriptions();
})
.catch((err) => NotifyResponse($q, err, 'error'));
if (collapsed.length) {
collapsed.forEach((key) => {
removeSubtreeByParentKey(key);
api
.post(postQuery, { get: [{ uuid: key, path: '', query: { depth: 2 } }] })
.then((resp) => {
if (resp?.data.get) {
buildTree(resp?.data.get as Subs);
subscribe([{ uuid: key, path: '', depth: 2 }]).catch((err) =>
NotifyResponse($q, err, 'error'),
);
addSubscriptions(resp?.data.get as RawSubs);
}
})
.catch((err) => NotifyResponse($q, err, 'error'));
});
}
if (newlyExpanded.length) {
newlyExpanded.forEach((key) => {
api
.post(postQuery, { get: [{ uuid: key, path: '', query: { depth: 2 } }] })
.then((resp) => {
if (resp?.data.get) {
buildTree(resp?.data.get as Subs);
subscribe([{ uuid: key, path: '', depth: 2 }]).catch((err) =>
NotifyResponse($q, err, 'error'),
);
addSubscriptions(resp?.data.get as RawSubs);
}
})
.catch((err) => NotifyResponse($q, err, 'error'));
});
}
lastExpanded = [...newExpanded];
} catch {
console.error('error in expand function');
}
}
const subMenuRef = ref();
function openSubMenu(event: MouseEvent, uuid: string) {
subMenuRef.value?.open(event, uuid);
}
</script>
<style scoped>
.tree-container {
overflow-y: auto;
}
@media (max-width: 599px) {
.tree-container {
max-height: 50vh;
}
}
@media (min-width: 600px) and (max-width: 1023px) {
.tree-container {
max-height: 60vh;
}
}
@media (min-width: 1024px) and (max-width: 1439px) {
.tree-container {
max-height: 70vh;
}
}
@media (min-width: 1440px) and (max-width: 1919px) {
.tree-container {
max-height: 80vh;
}
}
@media (min-width: 1920px) {
.tree-container {
max-height: 90vh;
}
}
</style>

View File

@@ -1,52 +0,0 @@
<template>
<q-menu ref="contextMenuRef" context-menu>
<q-list>
<q-item clickable v-close-popup @click="handleAction('Add')">
<q-item-section>Add Datapoint</q-item-section>
</q-item>
<q-item
:class="disable ? 'text-grey-5' : ''"
:clickable="!disable"
v-close-popup
@click="handleAction('Delete')"
>
<q-item-section>Delete Datapoint</q-item-section>
</q-item>
</q-list>
</q-menu>
<AddDialog :dialogLabel="label" width="700px" button-ok-label="Add" ref="addDialog" />
</template>
<script setup lang="ts">
import AddDialog from 'src/components/dialog/AddDatapoint.vue';
import { ref } from 'vue';
const ZERO_UUID = '00000000-0000-0000-0000-000000000000';
const addDialog = ref();
const datapointUuid = ref('');
const contextMenuRef = ref();
const label = ref('');
const disable = ref(false);
function handleAction(action: string) {
switch (action) {
case 'Add':
label.value = 'Add New Datapoint';
addDialog.value?.open(datapointUuid.value);
break;
case 'Delete':
label.value = 'Remove Datapoint';
addDialog.value?.open(datapointUuid.value);
break;
}
}
const open = (event: MouseEvent, uuid: string) => {
if (uuid === ZERO_UUID) disable.value = true;
event.preventDefault();
datapointUuid.value = uuid;
contextMenuRef.value?.show(event);
};
defineExpose({ open });
</script>

View File

@@ -1,82 +0,0 @@
<template>
<div class="q-pa-md">
<q-table
v-if="tableRows.length > 0"
style="height: 600px"
flat
bordered
:title="props.rows[0]?.path"
:rows="rows"
:columns="columns"
row-key="path"
virtual-scroll
:rows-per-page-options="[0]"
>
<template v-slot:body-cell-value="props">
<q-td :props="props" @click="openDialog(props.row)">
<div :class="['cursor-pointer', 'q-mx-sm']">
{{ props.row.value }}
</div>
</q-td>
</template>
<template v-slot:body-cell-drivers="props">
<q-td :props="props" @click="openDialog(props.row, 'driver')">
<div v-if="props.row.type !== 'none'" :class="['cursor-pointer']">
<q-icon size="sm" name="cell_tower" :color="props.row.drivers ? 'blue-5' : 'grey-4'" />
</div>
</q-td>
</template>
</q-table>
<UpdateDialog
dialogLabel="Update Value"
width="400px"
button-ok-label="Write"
ref="updateDialog"
v-model:datapoint="dialogValue"
/>
</div>
</template>
<script setup lang="ts">
import UpdateDialog from 'src/components/dialog/UpdateValueDialog.vue';
import type { QTableProps } from 'quasar';
import type { Subscribe } from 'src/models/Subscribe';
import { computed, ref } from 'vue';
import type { Subs } from 'src/models/Subscribe';
const updateDialog = ref();
const dialogValue = ref();
const openDialog = (sub: Subscribe, type?: string) => {
updateDialog.value?.open(sub, type);
};
// we generate lots of rows here
const props = defineProps<{
rows: Subs;
}>();
const tableRows = computed(() => [...props.rows]);
const columns = [
{ name: 'path', label: 'Path', field: 'path', align: 'left' },
{
name: 'type',
label: 'Type',
field: 'type',
align: 'left',
},
{
name: 'value',
label: 'Value',
field: 'value',
align: 'left',
},
// {. not implemented yet
// name: 'drivers',
// label: 'Drivers',
// field: 'drivers',
// align: 'center',
// },
] as QTableProps['columns'];
</script>

View File

@@ -1,101 +0,0 @@
<template>
<DialogFrame ref="Dialog" :width="props.width">
<q-card-section
v-if="props.dialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>{{ props.dialogLabel }}
</q-card-section>
<q-form ref="addForm" @submit="onSubmit" class="q-gutter-md">
<q-input
class="q-pa-md"
filled
v-model="path"
label=""
:rules="[(val) => !!val || 'Path is required']"
>
<template #prepend>
<div class="column">
<span class="text-caption text-primary non-editable-prefix">Path *</span>
<span class="text-body2 text-grey-6 non-editable-prefix">{{ staticPrefix }}</span>
</div>
</template>
</q-input>
<DataTypes class="q-ma-md" flat></DataTypes>
<q-btn no-caps class="q-ma-lg" type="submit" color="primary">{{ props.buttonOkLabel }}</q-btn>
</q-form>
</DialogFrame>
</template>
<script setup lang="ts">
import { useQuasar } from 'quasar';
import { ref } from 'vue';
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
import { api } from 'boot/axios';
import { NotifyResponse } from 'src/composables/notify';
import DataTypes from 'src/vueLib/buttons/DataTypes.vue';
//import datatype from 'src/vueLib/buttons/DataType.vue';
const $q = useQuasar();
const Dialog = ref();
const path = ref('');
const staticPrefix = ref('');
//const radio = ref('bool');
const addForm = ref();
const open = (uuid: string) => {
Dialog.value?.open();
getDatapoint(uuid);
};
function validate() {
addForm.value.validate().then((success: undefined) => {
if (success) {
console.log(909);
// yay, models are correct
} else {
console.log(910);
// oh no, user has filled in
// at least one invalid value
}
});
}
const props = defineProps({
buttonOkLabel: {
type: String,
default: 'OK',
},
labelColor: {
type: String,
default: 'primary',
},
dialogLabel: {
type: String,
default: '',
},
width: {
type: String,
default: '300px',
},
});
function onSubmit() {
validate();
console.log('submit', props);
}
function getDatapoint(uuid: string) {
api
.post('/json_data', { get: [{ uuid: uuid, query: { depth: 1 } }] })
.then((resp) => {
if (resp.data.get) {
staticPrefix.value = resp.data.get[0].path;
if (staticPrefix.value !== '') staticPrefix.value += ':';
}
})
.catch((err) => NotifyResponse($q, err, 'error'));
}
defineExpose({ open });
</script>

View File

@@ -1,126 +0,0 @@
<template>
<DialogFrame ref="Dialog" :width="props.width">
<q-card-section
v-if="props.dialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>{{ props.dialogLabel + ': ' + props.datapoint?.path }}</q-card-section
>
<q-card-section>
<q-input
class="q-px-md q-ma-sm"
label="current value"
dense
filled
readonly
v-model="inputValue as string | number"
></q-input>
<q-input
class="q-px-md q-mx-sm"
label="new value"
dense
filled
@keyup.enter="write"
v-model="writeValue as string | number"
></q-input>
</q-card-section>
<q-card-section v-if="props.text" class="text-center" style="white-space: pre-line">{{
props.text
}}</q-card-section>
<q-card-actions align="left" class="text-primary">
<q-btn v-if="props.buttonCancelLabel" flat :label="props.buttonCancelLabel" v-close-popup>
</q-btn>
<q-btn
class="q-mb-xl q-ml-lg q-mt-none"
v-if="props.buttonOkLabel"
color="primary"
:label="props.buttonOkLabel"
@click="write"
>
</q-btn>
</q-card-actions>
</DialogFrame>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
import type { Subscribe } from 'src/models/Subscribe';
import type { PropType } from 'vue';
import { setValues } from 'src/services/websocket';
import { NotifyResponse } from 'src/composables/notify';
import { useQuasar } from 'quasar';
const $q = useQuasar();
const Dialog = ref();
const writeValue = ref();
const props = defineProps({
buttonOkLabel: {
type: String,
default: 'OK',
},
labelColor: {
type: String,
default: 'primary',
},
dialogLabel: {
type: String,
default: '',
},
text: {
type: String,
default: '',
},
buttonCancelLabel: {
type: String,
default: '',
},
width: {
type: String,
default: '300px',
},
datapoint: Object as PropType<Subscribe>,
});
const inputValue = ref(props.datapoint?.value);
const open = (sub: Subscribe, type?: string) => {
Dialog.value?.open();
switch (type) {
case 'driver':
console.log(9, sub.drivers);
writeValue.value = sub.drivers;
break;
default:
writeValue.value = sub.value;
}
};
watch(
() => props.datapoint?.value,
(newVal) => {
inputValue.value = newVal;
},
);
function write() {
setValues([{ uuid: props.datapoint?.uuid ?? '', value: writeValue.value ?? undefined }])
.then((resp) => {
if (resp?.set) {
resp.set.forEach((set) => {
inputValue.value = set.value;
});
}
})
.catch((err) => NotifyResponse($q, err));
}
defineExpose({ open });
</script>
<style scoped>
.outercard {
border-radius: 10px;
}
</style>

View File

@@ -105,14 +105,14 @@
</template>
<script setup lang="ts">
import { useQuasar } from 'quasar';
import { watch, reactive, ref } from 'vue';
import type { Light } from 'src/models/Light';
import { setValues } from 'src/services/websocket';
import { setValues } from 'src/vueLib/services/websocket';
import SettingDialog from 'src/components/lights/SettingDomeLight.vue';
import { NotifyResponse } from 'src/composables/notify';
import { useNotify } from 'src/vueLib/general/useNotify';
import { catchError } from 'src/vueLib/models/error';
const $q = useQuasar();
const { NotifyResponse } = useNotify();
const settings = ref(false);
const light = reactive<Light>({
@@ -154,10 +154,10 @@ watch(light, (newVal: Light) => {
},
])
.then((response) => {
NotifyResponse($q, response);
NotifyResponse(response);
})
.catch((err) => {
NotifyResponse($q, err, 'error');
NotifyResponse(catchError(err), 'error');
});
});
</script>

View File

@@ -109,8 +109,8 @@
<script lang="ts" setup>
import { addOne, substractOne } from 'src/utils/number-helpers';
import { ref, computed, onMounted, onUnmounted } from 'vue';
import { updateValue } from 'src/composables/dbm/dbmTree';
import { useQuasar } from 'quasar';
import { updateValue } from 'src/vueLib/dbm/dbmTree';
import { useNotify } from 'src/vueLib/general/useNotify';
const props = defineProps({
reversePan: {
@@ -141,16 +141,15 @@ const props = defineProps({
},
});
const $q = useQuasar();
const { NotifyResponse } = useNotify();
const togglePan = ref(false);
const toggleTilt = ref(false);
const pad = ref<HTMLElement | null>(null);
const dragging = ref(false);
const containerSize = ref(0);
const pan = updateValue(props.panPath, $q, togglePan, props.panPath2);
const tilt = updateValue(props.tiltPath, $q, toggleTilt, props.tiltPath2);
const pan = updateValue(NotifyResponse, props.panPath, togglePan, props.panPath2);
const tilt = updateValue(NotifyResponse, props.tiltPath, toggleTilt, props.tiltPath2);
const scaleFactor = computed(() => containerSize.value / 255);
// 200px → 2, 400px → 4, etc.
@@ -202,7 +201,7 @@ function stopDrag() {
}
function startTouch(e: TouchEvent) {
e.preventDefault(); // ✅ block scroll
e.preventDefault();
const touch = e.touches[0];
if (!touch) return;
dragging.value = true;

View File

@@ -66,21 +66,21 @@
</template>
<script setup lang="ts">
import { useQuasar } from 'quasar';
import LightSlider from './LightSlider.vue';
import { ref, onMounted, onUnmounted } from 'vue';
import { unsubscribe, subscribeToPath } from 'src/services/websocket';
import { unsubscribe, subscribeToPath } from 'src/vueLib/services/websocket';
import SettingDialog from 'src/components/lights/SettingDomeLight.vue';
import { NotifyResponse } from 'src/composables/notify';
import { updateValue } from 'src/composables/dbm/dbmTree';
import { removeAllSubscriptions } from 'src/models/Subscriptions';
import { useNotify } from 'src/vueLib/general/useNotify';
import { updateValue } from 'src/vueLib/dbm/dbmTree';
import { removeAllSubscriptions } from 'src/vueLib/models/Subscriptions';
import { catchError } from 'src/vueLib/models/error';
const $q = useQuasar();
const { NotifyResponse } = useNotify();
const settings = ref(false);
const brightness = updateValue('LightBar:Brightness', $q);
const state = updateValue('LightBar:State', $q);
const brightness = updateValue(NotifyResponse, 'LightBar:Brightness');
const state = updateValue(NotifyResponse, 'LightBar:State');
onMounted(() => {
subscribeToPath($q, 'LightBar:.*');
subscribeToPath(NotifyResponse, 'LightBar:.*');
});
onUnmounted(() => {
@@ -90,7 +90,7 @@ onUnmounted(() => {
depth: 0,
},
]).catch((err) => {
NotifyResponse($q, err, 'error');
NotifyResponse(catchError(err), 'error');
});
removeAllSubscriptions();
});

View File

@@ -45,11 +45,9 @@
<script setup lang="ts">
import { ref } from 'vue';
import { useQuasar } from 'quasar';
import { updateValue } from 'src/composables/dbm/dbmTree';
import { updateValue } from 'src/vueLib/dbm/dbmTree';
import { addOne, substractOne } from 'src/utils/number-helpers';
const $q = useQuasar();
import { useNotify } from 'src/vueLib/general/useNotify';
const props = defineProps({
toggleHighLow: {
@@ -123,10 +121,11 @@ const props = defineProps({
},
});
const { NotifyResponse } = useNotify();
const toggle = ref(false);
const localValue = updateValue(
NotifyResponse,
props.dbmPath,
$q,
toggle,
props.dbmPath2,
props.dbmPath3,

View File

@@ -101,21 +101,21 @@ select
</template>
<script setup lang="ts">
import { useQuasar } from 'quasar';
import LightSlider from './LightSlider.vue';
import { NotifyResponse } from 'src/composables/notify';
import { useNotify } from 'src/vueLib/general/useNotify';
import { onBeforeUpdate, computed, onMounted, onUnmounted, ref } from 'vue';
import { subscribeToPath, unsubscribe, setValues } from 'src/services/websocket';
import { subscribeToPath, unsubscribe, setValues } from 'src/vueLib/services/websocket';
import { LocalStorage } from 'quasar';
import { updateValue } from 'src/composables/dbm/dbmTree';
import { updateValue } from 'src/vueLib/dbm/dbmTree';
import DragPad from 'src/components/lights/DragPad.vue';
import SettingDialog from './SettingMovingHead.vue';
import type { Settings } from 'src/models/MovingHead';
import { findSubscriptionByPath, removeAllSubscriptions } from 'src/models/Subscriptions';
import { findSubscriptionByPath, removeAllSubscriptions } from 'src/vueLib/models/Subscriptions';
import { catchError } from 'src/vueLib/models/error';
const $q = useQuasar();
const { NotifyResponse } = useNotify();
const brightness = updateBrightnessValue('MovingHead:Brightness');
const state = updateValue('MovingHead:State', $q);
const state = updateValue(NotifyResponse, 'MovingHead:State');
const settings = ref<Settings>({
show: false,
reversePan: false,
@@ -126,11 +126,11 @@ const settings = ref<Settings>({
onMounted(() => {
settings.value.reversePan = LocalStorage.getItem('reversePan') ?? false;
settings.value.reverseTilt = LocalStorage.getItem('reverseTilt') ?? false;
subscribeToPath($q, 'MovingHead:.*');
subscribeToPath(NotifyResponse, 'MovingHead:.*');
});
onBeforeUpdate(() => {
subscribeToPath($q, 'MovingHead:.*');
subscribeToPath(NotifyResponse, 'MovingHead:.*');
});
onUnmounted(() => {
@@ -140,7 +140,7 @@ onUnmounted(() => {
depth: 0,
},
]).catch((err) => {
NotifyResponse($q, err, 'error');
NotifyResponse(catchError(err), 'error');
});
removeAllSubscriptions();
});
@@ -172,7 +172,7 @@ function updateBrightnessValue(path: string) {
setPaths.push({ path: `MovingHead:Strobe`, value: 255 });
setValues(setPaths)
.then((response) => NotifyResponse($q, response))
.then((response) => NotifyResponse(response))
.catch((err) => console.error(`Failed to update ${path.split(':')[1]}:`, err));
},
});

View File

@@ -1,13 +1,14 @@
<template>
<!-- new edit scene dialog-->
<q-dialog v-model="showDialog" persistent>
<q-card style="min-width: 350px">
<DialogFrame ref="sceneDialog" width="350px">
<q-card>
<q-card-section>
<div class="text-primary text-h6">{{ dialogLabel }}</div>
</q-card-section>
<q-card-section class="q-pt-none">
<q-input
:readonly="dialog === 'load'"
class="q-mb-md"
dense
v-model="newScene.name"
@@ -17,6 +18,7 @@
@keyup.enter="saveScene"
/>
<q-input
:readonly="dialog === 'load'"
dense
v-model="newScene.description"
placeholder="Description"
@@ -32,11 +34,10 @@
</q-card-section>
<q-card-actions align="right" class="text-primary">
<q-btn flat label="Cancel" v-close-popup />
<q-btn flat :label="dialogLabel" @click="saveScene()" />
<q-btn flat :label="dialogLabel" v-close-popup @click="saveScene()" />
</q-card-actions>
</q-card>
</q-dialog>
</DialogFrame>
<Dialog
dialogLabel="Duplicate Scene"
:text="`Scene '${newScene.name}' exists already`"
@@ -110,18 +111,19 @@
</template>
<script setup lang="ts">
import { NotifyDialog } from 'src/composables/notify';
import { onMounted, reactive, ref } from 'vue';
import { useQuasar } from 'quasar';
import type { Scene } from 'src/models/Scene';
import type { Set } from 'src/models/Set';
import type { Set } from 'src/vueLib/models/Set';
import axios from 'axios';
import { api } from 'boot/axios';
import { NotifyResponse } from 'src/composables/notify';
import { api } from 'src/boot/axios';
import { useNotify } from 'src/vueLib/general/useNotify';
import Dialog from 'src/components/dialog/OkDialog.vue';
import { setValues } from 'src/services/websocket';
const $q = useQuasar();
const showDialog = ref(false);
import { setValues } from 'src/vueLib/services/websocket';
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
import { catchError } from 'src/vueLib/models/error';
const { NotifyResponse, NotifyDialog } = useNotify();
const sceneDialog = ref();
const dialog = ref('');
const existsAlready = ref(false);
const editIndex = ref(-1);
@@ -154,13 +156,13 @@ onMounted(() => {
}
})
.catch((err) => {
NotifyResponse($q, err.response.data.error, 'error');
NotifyResponse(catchError(err), 'error');
});
});
function removeScene(name: string) {
dialog.value = '';
NotifyDialog($q, 'Delete', 'Do you want to delete scene: ' + name, 'YES', 'NO')
NotifyDialog('Delete', 'Do you want to delete scene: ' + name, 'YES', 'NO')
.then((res) => {
if (res) {
scenes.value = scenes.value.filter((s) => s.name !== name);
@@ -171,15 +173,15 @@ function removeScene(name: string) {
})
.then((res) => {
if (res.data) {
NotifyResponse($q, res.data, 'warning');
NotifyResponse(res.data, 'warning');
}
})
.catch((err) => {
NotifyResponse($q, err.response.data.error, 'error');
NotifyResponse(catchError(err), 'error');
});
}
})
.catch((err) => NotifyResponse($q, err.resp, 'warning'));
.catch((err) => NotifyResponse(catchError(err), 'warning'));
}
function openDialog(dialogType: string, scene?: Scene, index?: number) {
@@ -190,7 +192,6 @@ function openDialog(dialogType: string, scene?: Scene, index?: number) {
newScene.name = '';
newScene.movingHead = true;
newScene.lightBar = true;
showDialog.value = true;
break;
case 'edit':
if (!scene) return;
@@ -199,7 +200,6 @@ function openDialog(dialogType: string, scene?: Scene, index?: number) {
dialogLabel.value = 'Update Scene';
editIndex.value = index;
Object.assign(newScene, JSON.parse(JSON.stringify(scene)));
showDialog.value = true;
break;
case 'load':
if (!scene) return;
@@ -210,15 +210,12 @@ function openDialog(dialogType: string, scene?: Scene, index?: number) {
.then((res) => {
if (res.data) {
Object.assign(newScene, JSON.parse(JSON.stringify(res.data)));
showDialog.value = true;
}
})
.catch((err) => NotifyResponse($q, err.response.data.error, 'error'));
break;
default:
showDialog.value = false;
.catch((err) => NotifyResponse(catchError(err), 'error'));
break;
}
sceneDialog.value.open();
}
const saveScene = async () => {
@@ -258,7 +255,7 @@ const saveScene = async () => {
const res = await api.post('/json_data', { get: sendValues });
newScene.values = res.data.get;
} catch (err) {
NotifyResponse($q, err as Error, 'error');
NotifyResponse(err as Error, 'error');
}
} else {
newScene.values = [];
@@ -273,14 +270,15 @@ const saveScene = async () => {
.post('/api/saveScene', JSON.stringify(newScene))
.then((res) => {
if (res.data) {
NotifyResponse($q, res.data);
NotifyResponse(res.data);
}
})
.catch((err) => {
NotifyResponse($q, err.response.data.error, 'error');
NotifyResponse(catchError(err), 'error');
});
scenes.value = [...scenes.value];
break;
case 'edit':
if (exists) {
existsAlready.value = true;
@@ -306,7 +304,7 @@ const saveScene = async () => {
const res = await api.post('/json_data', { get: sendValues });
newScene.values = res.data.get;
} catch (err) {
NotifyResponse($q, err as Error, 'error');
NotifyResponse(err as Error, 'error');
}
} else {
newScene.values = [];
@@ -319,43 +317,41 @@ const saveScene = async () => {
.post('/api/saveScene', JSON.stringify(newScene))
.then((res) => {
if (res.data) {
NotifyResponse($q, res.data);
NotifyResponse(res.data);
}
})
.catch((err) => {
NotifyResponse($q, err.response.data.error, 'error');
NotifyResponse(catchError(err), 'error');
});
scenes.value = [...scenes.value];
break;
case 'load':
{
const setPaths = <Set[]>[];
if (newScene.movingHead) {
newScene.values?.forEach((element) => {
if (element.path && element.path.includes('MovingHead')) {
setPaths.push({ path: element.path, value: element.value });
}
});
}
newScene.values?.forEach((element) => {
if (!element.path) return;
if (newScene.movingHead && element.path.includes('MovingHead'))
setPaths.push({ uuid: element.uuid, path: element.path, value: element.value });
if (newScene.lightBar && element.path.includes('LightBar'))
setPaths.push({ uuid: element.uuid, path: element.path, value: element.value });
});
if (newScene.lightBar) {
newScene.values?.forEach((element) => {
if (element.path && element.path.includes('LightBar')) {
setPaths.push({ path: element.path, value: element.value });
}
});
}
setValues(setPaths)
.then((response) => {
NotifyResponse($q, response);
NotifyResponse(response);
})
.catch((err) => console.error(`Failed to load scene ${newScene.name}`, err));
.catch((err) => {
NotifyResponse(`Failed to load scene ${newScene.name}`, 'warning');
NotifyResponse(catchError(err), 'error');
});
}
break;
}
dialog.value = '';
showDialog.value = false;
};
</script>