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

125
src/vueLib/dbm/DBMTree.vue Normal file
View File

@@ -0,0 +1,125 @@
<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(expanded)"
@lazy-load="onLazyLoad"
>
<template v-slot:[`default-header`]="props">
<div
class="row items-center text-blue"
@contextmenu.prevent.stop="openSubMenu($event, props.node)"
>
<div class="row items-center text-blue"></div>
<div>{{ props.node.path }}</div>
</div>
</template>
</q-tree>
<sub-menu ref="subMenuRef"></sub-menu>
</q-card-section>
<dataTable class="col-8" />
</div>
</q-card>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import {
type TreeNode,
dbmData,
onExpandedChange,
expanded,
buildTree,
} from '../../vueLib/dbm/dbmTree';
import DataTable from './DataTable.vue';
import { useNotify } from '../general/useNotify';
import { QCard } from 'quasar';
import { unsubscribe } from '../services/websocket';
import { onBeforeRouteLeave } from 'vue-router';
import SubMenu from './SubMenu.vue';
import { convertToSubscribes, type RawSubs } from '../models/Subscribe';
import { getRequest } from '../models/Request';
import { catchError } from '../models/error';
const { NotifyResponse } = useNotify();
const ZERO_UUID = '00000000-0000-0000-0000-000000000000';
onMounted(() => {
getRequest('', '.*', 1)
.then((res) => {
const test = res;
if (res) buildTree(convertToSubscribes(test as RawSubs));
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
});
onBeforeRouteLeave(() => {
unsubscribe([{ path: '.*', depth: 0 }]).catch((err) => NotifyResponse(catchError(err), 'error'));
});
function onLazyLoad({
node,
done,
fail,
}: {
node: TreeNode;
done: (children: TreeNode[]) => void;
fail: () => void;
}) {
getRequest(node.key ?? ZERO_UUID, '', 2)
.then((resp) => {
if (resp) done(buildTree(convertToSubscribes(resp as RawSubs)));
else done([]); // no children returned
})
.catch((err) => {
NotifyResponse(err, 'error');
fail(); // trigger the fail handler
});
}
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

@@ -0,0 +1,124 @@
<template>
<div class="q-pa-md">
<q-table
v-if="tableRows.length > 0"
style="height: 600px"
flat
bordered
:title="tableRows[0]?.path"
:rows="tableRows"
:columns="columns"
row-key="path"
virtual-scroll
:rows-per-page-options="[0]"
>
<template v-slot:body-cell-path="props">
<q-td :props="props" @click="openDialog(props.row, 'rename')">
<div
:class="[
'text-left',
!props.row.path.includes('System') && props.row.path !== 'DBM'
? 'cursor-pointer'
: '',
'q-mx-sm',
]"
>
{{ props.row.path?.split(':').pop() ?? '' }}
</div>
</q-td>
</template>
<template v-slot:body-cell-type="props">
<q-td :props="props" @click="openDialog(props.row, 'type')">
<div
:class="[
'text-center',
!props.row.path.includes('System') && props.row.path !== 'DBM'
? 'cursor-pointer'
: '',
'q-mx-sm',
]"
>
{{ convertFromType(props.row.type) }}
</div>
</q-td>
</template>
<template v-slot:body-cell-value="props">
<q-td :props="props" @click="openDialog(props.row)">
<div :class="['text-center', '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>
<RenameDialog width="400px" button-ok-label="Rename" ref="renameDialog" />
<UpdateDialog width="400px" button-ok-label="Write" ref="updateDialog" />
<UpdateDatatype
width="400px"
button-ok-label="Update"
ref="updateDatatype"
dialog-label="Update Datatype"
/>
</div>
</template>
<script setup lang="ts">
import UpdateDialog from './dialog/UpdateValueDialog.vue';
import RenameDialog from './dialog/RenameDatapoint.vue';
import UpdateDatatype from './dialog/UpdateDatatype.vue';
import type { QTableProps } from 'quasar';
import type { Subscribe } from '../models/Subscribe';
import { computed, ref } from 'vue';
import { TableSubs } from '../dbm/updateTable';
import { convertFromType } from './Datapoint';
const renameDialog = ref();
const updateDialog = ref();
const updateDatatype = ref();
const openDialog = (sub: Subscribe, type?: string) => {
if (sub.path?.includes('System') || sub.path === 'DBM') return;
switch (type) {
case 'type':
updateDatatype.value.open(sub.uuid);
break;
case 'rename':
renameDialog.value.open(sub.uuid);
break;
default:
if (sub.type === 'none') return;
updateDialog.value?.open(ref(sub), type);
break;
}
};
const tableRows = computed(() => [...(TableSubs.value ?? [])]);
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',
},
{
name: 'drivers',
label: 'Drivers',
field: 'drivers',
align: 'center',
},
] as QTableProps['columns'];
</script>

View File

@@ -0,0 +1,72 @@
import type { Gets } from '../models/Get';
import type { Sets } from '../models/Set';
export function datapointRequestForCopy(response: Gets, oldPath: string, newPath: string): Sets {
const copySet = <Sets>[];
response.forEach((get) => {
copySet.push({
path: typeof get.path === 'string' ? get.path.replace(oldPath, newPath) : '',
type: get.type ? get.type : '',
value: get.value,
rights: get.rights ? get.rights : '',
});
});
return copySet;
}
export function convertFromType(type: string): string {
switch (type) {
case 'STR':
return 'string';
case 'BIT':
return 'bool';
case 'BYU':
return 'uint8';
case 'WOU':
return 'uint16';
case 'DWU':
return 'uint32';
case 'BYS':
return 'int8';
case 'WOS':
return 'int16';
case 'DWS':
return 'int32';
case 'LOU':
return 'uint64';
case 'LOS':
return 'int64';
case 'F64':
return 'double';
default:
return 'none';
}
}
export function convertToType(type: string): string {
switch (type) {
case 'String':
return 'STR';
case 'Bool':
return 'BIT';
case 'Uint8':
return 'BYU';
case 'Int8':
return 'BYS';
case 'Uint16':
return 'WOU';
case 'Int16':
return 'WOS';
case 'Uint32':
return 'DWU';
case 'Int32':
return 'DWS';
case 'Int':
return 'LOS';
case 'Double':
return 'F64';
default:
return 'NONE';
}
}

179
src/vueLib/dbm/SubMenu.vue Normal file
View File

@@ -0,0 +1,179 @@
<template>
<q-menu ref="contextMenuRef" context-menu>
<q-list>
<q-item :clickable="!disableAll" v-close-popup @click="handleAction('Add')">
<q-item-section>
<div class="row">
<div class="col-5">
<q-icon
:color="disableAll ? 'grey-5' : 'primary'"
class="q-pr-sm"
name="add"
size="xs"
left
/>
</div>
<div :class="['col-7', disableAll ? 'text-grey-5' : 'text-primary']">Add</div>
</div>
</q-item-section>
</q-item>
<q-item
:class="disable ? 'text-grey-5' : ''"
:clickable="!disable"
v-close-popup
@click="handleAction('Rename')"
><q-item-section>
<div class="row">
<div class="col-5">
<q-icon
:color="disable ? 'grey-5' : 'primary'"
class="q-pr-sm"
name="edit"
size="xs"
left
/>
</div>
<div :class="['col-7', disable ? 'text-grey-5' : 'text-primary']">Rename</div>
</div>
</q-item-section>
</q-item>
<q-item
:class="disable ? 'text-grey-5' : ''"
:clickable="!disable"
v-close-popup
@click="handleAction('Delete')"
><q-item-section>
<div class="row">
<div class="col-5">
<q-icon
:color="disable ? 'grey-5' : 'primary'"
class="q-pr-sm"
name="delete"
size="xs"
left
/>
</div>
<div :class="['col-7', disable ? 'text-grey-5' : 'text-primary']">Delete</div>
</div>
</q-item-section>
</q-item>
<q-item
:color="disable ? 'grey-5' : 'primary'"
:clickable="!disable"
v-close-popup
@click="handleAction('Copy')"
>
<q-item-section>
<div class="row">
<div class="col-5">
<q-icon
:color="disable ? 'grey-5' : 'primary'"
class="q-pr-sm"
name="content_copy"
size="xs"
left
/>
</div>
<div :class="['col-7', disable ? 'text-grey-5' : 'text-primary']">Copy</div>
</div>
</q-item-section>
</q-item>
<q-item
:color="disable ? 'grey-5' : 'primary'"
:clickable="!disable"
v-close-popup
@click="handleAction('Datatype')"
>
<q-item-section>
<div class="row">
<div class="col-5">
<q-icon
:color="disable ? 'grey-5' : 'primary'"
class="q-pr-sm"
name="text_fields"
size="xs"
left
/>
</div>
<div :class="['col-7', disable ? 'text-grey-5' : 'text-primary']">Datatype</div>
</div>
</q-item-section>
</q-item>
</q-list>
</q-menu>
<RenameDatapoint :dialogLabel="label" width="700px" button-ok-label="Rename" ref="renameDialog" />
<AddDialog :dialogLabel="label" width="700px" button-ok-label="Add" ref="addDialog" />
<RemoveDialog :dialogLabel="label" width="350px" button-ok-label="Remove" ref="removeDialog" />
<CopyDialog :dialogLabel="label" width="300px" button-ok-label="Copy" ref="copyDialog" />
<UpdateDatapoint
:dialogLabel="label"
width="300px"
button-ok-label="Update"
ref="datatypeDialog"
/>
</template>
<script setup lang="ts">
import AddDialog from './dialog/AddDatapoint.vue';
import RemoveDialog from './dialog/RemoveDatapoint.vue';
import CopyDialog from './dialog/CopyDatapoint.vue';
import UpdateDatapoint from './dialog/UpdateDatatype.vue';
import { ref } from 'vue';
import { type TreeNode } from '../dbm/dbmTree';
import { findSubscriptionByUuid } from '../models/Subscriptions';
import RenameDatapoint from './dialog/RenameDatapoint.vue';
const ZERO_UUID = '00000000-0000-0000-0000-000000000000';
const renameDialog = ref();
const addDialog = ref();
const removeDialog = ref();
const copyDialog = ref();
const datatypeDialog = ref();
const datapointUuid = ref('');
const contextMenuRef = ref();
const label = ref('');
const disable = ref(false);
const disableAll = ref(false);
function handleAction(action: string) {
switch (action) {
case 'Rename':
label.value = 'Rename Datapoint';
renameDialog.value?.open(datapointUuid.value);
break;
case 'Add':
label.value = 'Add New Datapoint';
addDialog.value?.open(datapointUuid.value);
break;
case 'Delete':
label.value = 'Remove Datapoint';
removeDialog.value.open(datapointUuid.value);
break;
case 'Copy':
label.value = 'Copy Datapoint';
copyDialog.value.open(datapointUuid.value);
break;
case 'Datatype':
label.value = 'Update Datatype';
datatypeDialog.value.open(datapointUuid.value);
break;
}
}
const open = (event: MouseEvent, sub: TreeNode) => {
disable.value = false;
disableAll.value = false;
if (findSubscriptionByUuid(sub.key ?? '')?.path?.includes('System')) {
disable.value = true;
disableAll.value = true;
}
if (sub.key === ZERO_UUID) disable.value = true;
event.preventDefault();
datapointUuid.value = sub.key ?? '';
contextMenuRef.value?.show(event);
};
defineExpose({ open });
</script>

264
src/vueLib/dbm/dbmTree.ts Normal file
View File

@@ -0,0 +1,264 @@
import { ref, computed, type Ref } from 'vue';
import { convertToSubscribes, type Subs } from '../models/Subscribe';
import { setValues, subscribe, unsubscribe } from '../services/websocket';
import {
findSubscriptionByPath,
addRawSubscriptions,
removeAllSubscriptions,
} from '../models/Subscriptions';
import { UpdateTable } from '..//dbm/updateTable';
import type { Response } from '..//models/Response';
import type { RawSubs } from '..//models/Subscribe';
import { getRequest } from '../models/Request';
import type { Pubs } from '../models/Publish';
const ZERO_UUID = '00000000-0000-0000-0000-000000000000';
export const dbmData = ref<TreeNode[]>([]);
export const expanded = ref<string[]>([]);
let lastExpanded: string[] = [];
export type TreeNode = {
path?: string;
key?: string;
lazy: boolean;
children?: TreeNode[];
};
type TreeMap = {
[key: string]: {
__children: TreeMap;
uuid?: string;
value?: string | number | boolean | null;
lazy: boolean;
};
};
const root: TreeMap = {};
export function buildTreeWithRawSubs(subs: RawSubs): TreeNode[] {
return buildTree(convertToSubscribes(subs));
}
export function buildTree(subs: Subs | null): TreeNode[] {
if (subs) {
for (const { path, uuid, value, hasChild } of subs) {
if (!path) continue;
const parts = path.split(':');
let current = root;
parts.forEach((part, idx) => {
if (!part) return;
if (!current[part]) current[part] = { __children: {}, lazy: true };
if (idx === parts.length - 1 && uuid) {
current[part].uuid = uuid;
current[part].value = value?.value ?? null;
current[part].lazy = !!hasChild;
}
current = current[part].__children;
});
}
}
const toTreeNodes = (map: TreeMap): TreeNode[] =>
Object.entries(map)
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, node]) => ({
path: key,
key: node.uuid ?? key,
value: node.value,
lazy: node.lazy,
children: toTreeNodes(node.__children),
}));
const newTree = [
{
path: 'DBM',
key: ZERO_UUID,
lazy: true,
children: toTreeNodes(root),
},
];
dbmData.value.splice(0, dbmData.value.length, ...newTree);
return newTree;
}
export function removeNodes(pubs: Pubs) {
pubs.forEach((pub) => {
removeNode(pub.uuid);
});
}
export function removeNode(uuid: string) {
removeFromTreeMap(root, uuid);
removeFromTree(dbmData.value, uuid);
collapseNode(uuid);
}
function removeFromTreeMap(tree: TreeMap, uuid: string): boolean {
for (const [key, node] of Object.entries(tree)) {
if (node.uuid === uuid) {
delete tree[key];
return true;
}
if (removeFromTreeMap(node.__children, uuid)) return true;
}
return false;
}
function removeFromTree(nodes: TreeNode[], uuid: string): boolean {
const index = nodes.findIndex((n) => n.key === uuid);
if (index !== -1) {
nodes.splice(index, 1);
return true;
}
for (const node of nodes) {
if (node.children && removeFromTree(node.children, uuid)) {
if (node.children.length === 0) {
delete node.children;
node.lazy = true;
}
return true;
}
}
return false;
}
export function removeSubtreeByParentKey(parentKey: string) {
const recurse = (nodes: TreeNode[]): boolean => {
for (const node of nodes) {
if (node.key === parentKey) {
delete node.children;
node.lazy = true;
return true;
}
if (node.children && recurse(node.children)) return true;
}
return false;
};
recurse(dbmData.value);
}
function collapseNode(uuid: string) {
const idx = expanded.value.indexOf(uuid);
if (idx !== -1) {
expanded.value.splice(idx, 1);
const lastIdx = lastExpanded.indexOf(uuid);
if (lastIdx !== -1) lastExpanded.splice(lastIdx, 1);
onExpandedChange([...expanded.value]).catch(console.error);
}
}
export function updateValue(
NotifyResponse: (
response: Response | string | undefined,
type?: 'warning' | 'error',
timeout?: 5000,
) => void,
path1: string,
toggle?: Ref<boolean>,
path2?: string,
path3?: string,
value3?: number,
) {
return computed({
get() {
const path = toggle?.value && path2 ? path2 : path1;
return Number(findSubscriptionByPath(path)?.value ?? 0);
},
set(val) {
const baseValue = val;
const updates = [
{ path: toggle?.value && path2 ? path2 : path1, value: baseValue },
...(path3 ? [{ path: path3, value: value3 ?? baseValue }] : []),
];
setValues(updates)
.then((response) => NotifyResponse(response))
.catch((err) =>
NotifyResponse(`Failed to update [${[path1, path2, path3].join(' ')}]: ${err}`, 'error'),
);
},
});
}
export 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);
for (const key of collapsed) {
removeSubtreeByParentKey(key);
fetchAndUpdateNode(key);
}
for (const key of newlyExpanded) {
fetchAndUpdateNode(key);
}
lastExpanded = [...newExpanded];
} catch (err) {
console.error('error in expand function', err);
}
}
function fetchAndUpdateNode(key: string) {
getRequest(key, '', 2)
.then((resp) => {
if (resp) {
buildTreeWithRawSubs(resp);
subscribe([{ uuid: key, path: '', depth: 2 }]).catch((err) => console.error(err));
addRawSubscriptions(resp);
}
UpdateTable(key);
})
.catch((err) => console.error(err));
}
export function findParentKey(
childKey: string,
parentKey: string | null = null,
nodes?: TreeNode[],
): string | null {
if (!nodes) nodes = dbmData.value;
for (const node of nodes) {
if (node.key === childKey) return parentKey;
if (node.children) {
const found = findParentKey(childKey, node.key ?? null, node.children);
if (found) return found;
}
}
return null;
}
function getNodeUuidByPath(path: string, nodes?: TreeNode[]): string {
if (!nodes) nodes = dbmData.value;
for (const node of nodes) {
if (node.path === path) return node.key ?? '';
if (node.children) {
const found = getNodeUuidByPath(path, node.children);
if (found !== '') return found;
}
}
return '';
}
export function pathIsExpanded(path: string): boolean {
if (!path.includes(':')) {
return true;
}
let p = path.replace(/:.+$/, '');
if (expanded.value.includes(getNodeUuidByPath(p))) {
return true;
}
p = path.replace(/:.+$/, '');
return expanded.value.includes(getNodeUuidByPath(p));
}

View File

@@ -0,0 +1,144 @@
<template>
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
<q-card-section
v-if="props.dialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>
</q-card-section>
<q-form ref="addForm" class="q-gutter-md">
<q-input
class="q-mt-lg q-mb-none q-pl-lg q-pr-xl"
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"
>{{ prefix }}{{ staticPrefix }}</span
>
</div>
</template>
</q-input>
<DataTypes class="q-mt-lg q-pl-md q-pr-xl" flat v-model:datatype="datatype"></DataTypes>
<div class="q-pl-lg">
<div class="text-grey text-bold">Read Write Access</div>
<q-checkbox v-model="read">Read</q-checkbox>
<q-checkbox v-model="write">Write</q-checkbox>
</div>
<q-input
:type="valueType"
stack-label
label="Value"
class="q-pl-md q-pr-xl"
filled
v-model="value"
></q-input>
<q-btn no-caps class="q-mb-xl q-mx-xl q-px-lg" @click="onSubmit" color="primary">{{
props.buttonOkLabel
}}</q-btn>
</q-form>
</DialogFrame>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import DialogFrame from '../../dialog/DialogFrame.vue';
import { useNotify } from '../../general/useNotify';
import DataTypes from '../../buttons/DataTypes.vue';
import { addRawSubscription } from '../../models/Subscriptions';
import { UpdateTable } from '../../dbm/updateTable';
import { getRequest, setRequest } from 'src/vueLib/models/Request';
import { convertToType } from '../Datapoint';
import { catchError } from 'src/vueLib/models/error';
const { NotifyResponse } = useNotify();
const Dialog = ref();
const path = ref('');
const staticPrefix = ref('');
const value = ref('');
const valueType = ref<'text' | 'number'>('text');
const read = ref(true);
const write = ref(true);
const datatype = ref('None');
const addForm = ref();
const prefix = 'DBM:';
const open = (uuid: string) => {
Dialog.value?.open();
getDatapoint(uuid);
};
watch(datatype, (newVal) => {
if (newVal === 'String') valueType.value = 'text';
else valueType.value = 'number';
});
function onSubmit() {
let type = 'NONE';
let access = '';
addForm.value.validate().then((success: undefined) => {
if (success) {
type = convertToType(datatype.value);
if (read.value) access = 'R';
if (write.value) access += 'W';
if (access == '') access = 'R';
setRequest(staticPrefix.value + path.value, type, value.value, access)
.then((respond) => {
if (respond) {
respond.forEach((set) => {
NotifyResponse("Datapoint '" + prefix + set.path + "' added");
});
addRawSubscription(respond[0]);
UpdateTable();
}
})
.catch((err) => {
NotifyResponse(catchError(err), 'error');
});
} else {
if (path.value === '') {
NotifyResponse("Field 'Path' is requierd", 'error');
return;
} else NotifyResponse('Form not validated', 'error');
}
});
}
const props = defineProps({
buttonOkLabel: {
type: String,
default: 'OK',
},
labelColor: {
type: String,
default: 'primary',
},
dialogLabel: {
type: String,
default: '',
},
width: {
type: String,
default: '300px',
},
});
function getDatapoint(uuid: string) {
getRequest(uuid, '', 1)
.then((resp) => {
if (resp[0]) {
staticPrefix.value = resp[0].path ?? '';
if (staticPrefix.value !== '') staticPrefix.value += ':';
}
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
}
defineExpose({ open });
</script>

View File

@@ -0,0 +1,131 @@
<template>
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
<q-card-section
v-if="props.dialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>
</q-card-section>
<q-form ref="copyForm" class="q-gutter-md">
<q-input
class="q-mt-lg q-mb-none q-pl-md q-mx-lg"
filled
v-model="path"
label="Current Path"
label-color="primary"
readonly
>
</q-input>
<q-input
class="q-mt-lg q-mt-none q-pl-md q-mx-lg"
filled
v-model="copyPath"
label="New Path *"
label-color="primary"
@keyup.enter="onSubmit"
:rules="[(val) => !!val || 'Path is required']"
>
</q-input>
<div class="q-mx-sm">
<q-btn no-caps class="q-mb-xl q-ml-lg q-px-lg" @click="onSubmit" color="primary">{{
props.buttonOkLabel
}}</q-btn>
</div>
</q-form>
</DialogFrame>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import DialogFrame from '../../dialog/DialogFrame.vue';
import { useNotify } from '../../general/useNotify';
import { getRequest, setsRequest } from 'src/vueLib/models/Request';
import { datapointRequestForCopy } from '../Datapoint';
import { catchError } from 'src/vueLib/models/error';
const { NotifyResponse } = useNotify();
const Dialog = ref();
const path = ref('');
const copyPath = ref('');
const copyForm = ref();
const prefix = 'DBM:';
const open = (uuid: string) => {
Dialog.value?.open();
getDatapoint(uuid);
};
function onSubmit() {
copyForm.value.validate().then((success: undefined) => {
if (success) {
if (copyPath.value === path.value) {
NotifyResponse('copy path can not be the same as current path', 'error');
return;
}
const absolutePath = path.value.slice(prefix.length);
const absolutecopyPath = copyPath.value.slice(prefix.length);
getRequest('', absolutecopyPath, 1)
.then((response) => {
if (response?.length > 0) {
NotifyResponse("path '" + copyPath.value + "' already exists", 'warning');
return;
}
})
.catch((err) => {
if (err instanceof Error && err.message === 'No data returned') {
getRequest('', absolutePath, 0)
.then((response) => {
setsRequest(
datapointRequestForCopy(response, absolutePath, absolutecopyPath),
).catch((err) => console.error(err));
NotifyResponse(copyPath.value + ' copied');
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
} else {
NotifyResponse(catchError(err), 'error');
}
return;
});
} else {
if (copyPath.value === '') {
NotifyResponse("Field 'New Path' is requierd", 'error');
return;
} else NotifyResponse('Form not validated', 'error');
}
});
}
const props = defineProps({
buttonOkLabel: {
type: String,
default: 'OK',
},
labelColor: {
type: String,
default: 'primary',
},
dialogLabel: {
type: String,
default: '',
},
width: {
type: String,
default: '300px',
},
});
function getDatapoint(uuid: string) {
getRequest(uuid)
.then((resp) => {
if (resp[0]) {
path.value = prefix + resp[0].path;
copyPath.value = prefix + resp[0].path;
}
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
}
defineExpose({ open });
</script>

View File

@@ -0,0 +1,102 @@
<template>
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
<q-card-section
v-if="props.dialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>
</q-card-section>
<div class="text-center text-bold text-primary">
Do you want to remove Datapoint
<br />
'{{ datapoint.path ?? '' }}'
</div>
<q-btn no-caps class="q-ma-md" filled color="negative" @click="remove">{{
props.buttonOkLabel
}}</q-btn>
</DialogFrame>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import DialogFrame from '../../dialog/DialogFrame.vue';
import { useNotify } from '../../general/useNotify';
import { subscribe } from '../../services/websocket';
import { findParentKey, buildTree } from '../../dbm/dbmTree';
import { addRawSubscriptions } from '../../models/Subscriptions';
import { UpdateTable } from '../../dbm/updateTable';
import { convertToSubscribes } from '../../models/Subscribe';
import { deleteRequest, getRequest } from 'src/vueLib/models/Request';
import { catchError } from 'src/vueLib/models/error';
const { NotifyResponse } = useNotify();
const Dialog = ref();
const datapoint = ref();
const prefix = 'DBM:';
const open = (uuid: string) => {
getDatapoint(uuid)
.then(() => Dialog.value?.open())
.catch((err) => NotifyResponse(catchError(err), 'error'));
};
function remove() {
deleteRequest(datapoint.value.uuid)
.then((respond) => {
const sub = respond[respond.length - 1];
if (sub) NotifyResponse("Datapoint '" + prefix + sub.path + "' removed", 'warning');
Dialog.value.close();
{
const parentKey = findParentKey(datapoint.value.uuid);
if (parentKey) {
subscribe([{ uuid: parentKey, path: '', depth: 2 }])
.then((res) => {
if (res?.subscribe) {
addRawSubscriptions(res.subscribe);
buildTree(convertToSubscribes(res.subscribe));
UpdateTable();
}
})
.catch((err) => NotifyResponse('Subscribe failed ' + catchError(err), 'error'));
}
}
})
.catch((err) => {
if (err.response) {
NotifyResponse(err.response.data.message, 'error');
} else console.error(err);
});
}
const props = defineProps({
buttonOkLabel: {
type: String,
default: 'OK',
},
labelColor: {
type: String,
default: 'primary',
},
dialogLabel: {
type: String,
default: '',
},
width: {
type: String,
default: '300px',
},
});
async function getDatapoint(uuid: string) {
await getRequest(uuid, '', 1)
.then((resp) => {
if (resp) {
datapoint.value = resp[0];
}
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
}
defineExpose({ open, close });
</script>

View File

@@ -0,0 +1,141 @@
<template>
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
<q-card-section
v-if="props.dialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>
</q-card-section>
<q-form ref="copyForm" class="q-gutter-md">
<q-input
class="q-mt-lg q-mb-none q-pl-md q-mx-lg"
filled
v-model="path"
label="Current Path"
label-color="primary"
readonly
>
</q-input>
<q-input
class="q-mt-lg q-mt-none q-pl-md q-mx-lg"
filled
v-model="newPath"
label="New Path *"
label-color="primary"
@keyup.enter="onSubmit"
:rules="[(val) => !!val || 'Path is required']"
>
</q-input>
<div class="q-mx-sm">
<q-btn no-caps class="q-mb-xl q-ml-lg q-px-lg" @click="onSubmit" color="primary">{{
props.buttonOkLabel
}}</q-btn>
</div>
</q-form>
</DialogFrame>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import DialogFrame from '../../dialog/DialogFrame.vue';
import { useNotify } from '../../general/useNotify';
import { getRequest, setRequest } from 'src/vueLib/models/Request';
import { catchError } from 'src/vueLib/models/error';
import { convertToSubscribes, type RawSubs } from 'src/vueLib/models/Subscribe';
import { UpdateTable } from '../updateTable';
import { addRawSubscriptions } from 'src/vueLib/models/Subscriptions';
import { buildTree } from '../dbmTree';
const { NotifyResponse } = useNotify();
const Dialog = ref();
const datapoint = ref();
const path = ref('');
const newPath = ref('');
const copyForm = ref();
const prefix = 'DBM:';
const open = (uuid: string) => {
Dialog.value?.open();
getDatapoint(uuid);
};
function onSubmit() {
copyForm.value.validate().then((success: undefined) => {
if (success) {
if (newPath.value === path.value) {
NotifyResponse('same name', 'warning');
return;
}
getRequest('', newPath.value.slice(prefix.length), 1)
.then((response) => {
console.log(10, response);
if (response?.length > 0) {
NotifyResponse("path '" + response[0]?.path + "' already exists", 'warning');
return;
}
})
.catch((err) => {
const error = catchError(err);
if (error !== 'No data returned') {
NotifyResponse(error, 'error');
return;
}
setRequest(
newPath.value.slice(prefix.length),
datapoint.value.type,
datapoint.value.value,
datapoint.value.rights,
datapoint.value.uuid,
true,
)
.then((res) => {
addRawSubscriptions(res as RawSubs);
buildTree(convertToSubscribes(res as RawSubs));
UpdateTable();
})
.catch((err) => NotifyResponse(err, 'error'));
});
} else {
if (newPath.value === '') {
NotifyResponse("Field 'New Path' is requierd", 'error');
return;
} else NotifyResponse('Form not validated', 'error');
}
});
}
const props = defineProps({
buttonOkLabel: {
type: String,
default: 'OK',
},
labelColor: {
type: String,
default: 'primary',
},
dialogLabel: {
type: String,
default: '',
},
width: {
type: String,
default: '300px',
},
});
function getDatapoint(uuid: string) {
getRequest(uuid)
.then((resp) => {
if (resp[0]) {
datapoint.value = resp[0];
path.value = prefix + resp[0].path;
newPath.value = prefix + resp[0].path;
}
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
}
defineExpose({ open });
</script>

View File

@@ -0,0 +1,140 @@
<template>
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
<q-card-section
v-if="props.dialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>DBM:{{ datapoint.path }}
</q-card-section>
<q-form ref="datatypeForm" class="q-gutter-md">
<q-input
class="q-mt-lg q-mb-none q-pl-md q-mx-lg"
filled
dense
v-model="currentDatatype"
label="Current Path"
label-color="primary"
readonly
>
</q-input>
<q-select
class="q-mt-lg q-mt-none q-pl-md q-mx-lg"
popup-content-class="small-dropdown"
filled
dense
v-model="selectedDatatype"
:options="options"
option-label="label"
>
</q-select>
<div class="q-mx-sm">
<q-btn no-caps class="q-mb-xl q-ml-lg q-px-lg" @click="onSubmit" color="primary">{{
props.buttonOkLabel
}}</q-btn>
</div>
</q-form>
</DialogFrame>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import DialogFrame from '../../dialog/DialogFrame.vue';
import { useNotify } from '../../general/useNotify';
import { getRequest, setRequest } from 'src/vueLib/models/Request';
import { UpdateTable } from '../updateTable';
import { updateSubscription } from 'src/vueLib/models/Subscriptions';
import { convertToSubscribe } from 'src/vueLib/models/Subscribe';
import { convertFromType } from '../Datapoint';
import { catchError } from 'src/vueLib/models/error';
const { NotifyResponse } = useNotify();
const Dialog = ref();
const datapoint = ref();
const currentDatatype = ref('');
const datatypeForm = ref();
const selectedDatatype = ref({ label: 'None', value: 'NONE' });
const options = [
{ label: 'None', value: 'NONE' },
{ label: 'String (Text)', value: 'STR' },
{ label: 'Bool (On/Off)', value: 'BIT' },
{ label: 'Uint8 (0 - 256)', value: 'BYU' },
{ label: 'Uint16 (0 - 65535)', value: 'WOU' },
{ label: 'Uint32 (0 - 429496...)', value: 'DWU' },
{ label: 'Int8 (-128 - 127)', value: 'BYS' },
{ label: 'Int16 (-32768 -3...)', value: 'WOS' },
{ label: 'Int32 (-21474836...)', value: 'DWS' },
{ label: 'Int64 (-2^63 -(2^...))', value: 'DWS' },
{ label: 'Double (1.7E 1/-3...)', value: 'F64' },
];
const open = async (uuid: string) => {
await getDatapoint(uuid);
Dialog.value?.open();
};
async function onSubmit() {
const success = await datatypeForm.value.validate();
if (!success) {
NotifyResponse('Form not validated', 'error');
return;
}
const datatype = options.find((s) => s.label === selectedDatatype.value.label)?.value;
if (datatype === undefined) return;
try {
const response = await setRequest(datapoint.value.path, datatype, datapoint.value.value);
if (response[0]) updateSubscription(convertToSubscribe(response[0]));
NotifyResponse(
'new datatype: ' +
convertFromType(response[0]?.type ?? '') +
' for datapoint :DBM:' +
response[0]?.path,
);
UpdateTable();
return;
} catch (err) {
console.error(err);
}
}
const props = defineProps({
buttonOkLabel: {
type: String,
default: 'OK',
},
labelColor: {
type: String,
default: 'primary',
},
dialogLabel: {
type: String,
default: '',
},
width: {
type: String,
default: '300px',
},
});
async function getDatapoint(uuid: string) {
await getRequest(uuid)
.then((resp) => {
if (resp[0]) {
datapoint.value = resp[0];
const type = options.find((s) => s.value === (resp[0]?.type ?? 'NONE'))?.label ?? 'None';
currentDatatype.value = type;
selectedDatatype.value.value = type;
}
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
}
defineExpose({ open });
</script>
<style scope>
.small-dropdown .q-item {
min-height: 28px; /* default is 48px */
padding: 4px 8px;
}
</style>

View File

@@ -0,0 +1,159 @@
<template>
<DialogFrame ref="Dialog" :width="props.width" :header-title="datapoint?.path">
<q-card-section
v-if="props.dialogLabel || localDialogLabel"
class="text-bold text-left q-mb-none q-pb-none"
:class="'text-' + props.labelColor"
>{{ props.dialogLabel ? props.dialogLabel : localDialogLabel }}</q-card-section
>
<q-card-section v-if="drivers && drivers.length == 0">
<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
:readonly="onlyRead"
@keyup.enter="write"
:type="writeType"
v-model="writeValue as string | number"
></q-input>
</q-card-section>
<q-card-section v-else>
<q-table
flat
dense
virtual-scroll
:rows-per-page-options="[0]"
:rows="drivers"
:columns="columns"
>
</q-table>
</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"
no-caps
:label="props.buttonOkLabel"
@click="write"
>
</q-btn>
</q-card-actions>
</DialogFrame>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import DialogFrame from '../../dialog/DialogFrame.vue';
import type { Subscribe } from '../../models/Subscribe';
import type { Ref } from 'vue';
import { setValues } from '../../services/websocket';
import { useNotify } from '../../general/useNotify';
import type { QTableProps } from 'quasar';
import type { Driver } from '../../models/Drivers';
import { catchError } from 'src/vueLib/models/error';
const { NotifyResponse } = useNotify();
const Dialog = ref();
const writeValue = ref();
const onlyRead = ref(false);
const writeType = ref<'text' | 'number'>('text');
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',
},
});
const datapoint = ref();
const inputValue = ref(datapoint?.value);
const localDialogLabel = ref('');
const drivers = ref<Driver[]>([]);
const columns = [
{ name: 'type', label: 'Driver Name', field: 'type', align: 'left' },
{ name: 'bus', label: 'Bus Name', field: 'bus', align: 'center' },
{ name: 'address', label: 'Address', field: 'address', align: 'center' },
] as QTableProps['columns'];
const open = (sub: Ref<Subscribe>, type?: string) => {
datapoint.value = sub.value;
if (datapoint.value.rights == 'R') onlyRead.value = true;
drivers.value = [];
switch (type) {
case 'driver':
localDialogLabel.value = 'Update Drivers';
if (sub.value.drivers) drivers.value = Object.values(sub.value.drivers);
writeValue.value = sub.value.drivers;
break;
default:
localDialogLabel.value = 'Update Value';
if (sub.value.type === 'STR') writeType.value = 'text';
else if (sub.value.type === 'BIT') writeType.value = 'text';
else writeType.value = 'number';
writeValue.value = sub.value.value;
}
Dialog.value?.open();
};
watch(
() => datapoint.value?.value,
(newVal) => {
inputValue.value = newVal;
},
);
function write() {
setValues([{ uuid: datapoint.value?.uuid ?? '', value: writeValue.value ?? undefined }])
.then((resp) => {
if (resp?.set) {
resp.set.forEach((set) => {
inputValue.value = set.value;
});
}
})
.catch((err) => NotifyResponse(catchError(err), 'error'));
}
defineExpose({ open });
</script>
<style scoped>
.outercard {
border-radius: 10px;
}
</style>

View File

@@ -0,0 +1,22 @@
import type { Subs } from '../models/Subscribe';
import { Subscriptions } from '../models/Subscriptions';
import { ref } from 'vue';
export const TableSubs = ref<Subs>();
export function UpdateTable(targetUuid?: string) {
TableSubs.value = Object.values(Subscriptions)
.map((sub) => {
sub.type = sub.type ?? 'none';
return sub;
})
.sort((a, b) => {
if (targetUuid) {
if (a.uuid === targetUuid) return -1; // move `a` to front
if (b.uuid === targetUuid) return 1; // move `b` to front
}
const aPath = a.path ?? '';
const bPath = b.path ?? '';
return aPath.localeCompare(bPath);
});
}