implement driver add update remove and improve rename tree experience
This commit is contained in:
7
src/vueLib/models/Bus.ts
Normal file
7
src/vueLib/models/Bus.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { Topic } from './Topic';
|
||||
|
||||
export interface Bus {
|
||||
name: string;
|
||||
address?: number[];
|
||||
topic?: Topic;
|
||||
}
|
@@ -1,5 +1,9 @@
|
||||
import type { Bus } from './Bus';
|
||||
export interface Driver {
|
||||
type: string;
|
||||
addess: number;
|
||||
value: number;
|
||||
buses?: Bus[];
|
||||
}
|
||||
|
||||
export const driverDefault = <Driver>{
|
||||
type: '',
|
||||
};
|
||||
|
@@ -1,14 +1,21 @@
|
||||
import type { Driver } from './Drivers';
|
||||
export type Publish = {
|
||||
event: string;
|
||||
uuid: string;
|
||||
path: string;
|
||||
type: string;
|
||||
drivers?: Record<string, Driver>;
|
||||
value: string | number | boolean | null;
|
||||
hasChild: boolean;
|
||||
};
|
||||
export type Pubs = Publish[];
|
||||
|
||||
import { updateSubscriptionValue, removeRawSubscriptions } from './Subscriptions';
|
||||
import {
|
||||
updateSubscriptionValue,
|
||||
removeRawSubscriptions,
|
||||
addRawSubscription,
|
||||
removeRawSubscription,
|
||||
} from './Subscriptions';
|
||||
import { buildTree, buildTreeWithRawSubs, removeNodes } from '../dbm/dbmTree';
|
||||
import type { RawSubs, RawSubscribe } from '../models/Subscribe';
|
||||
import { ref } from 'vue';
|
||||
@@ -33,6 +40,11 @@ export function publishToSubscriptions(pubs: Pubs) {
|
||||
rawSubs.value.push(pub as RawSubscribe);
|
||||
break;
|
||||
}
|
||||
if (pub.drivers) {
|
||||
removeRawSubscription(pub as RawSubscribe);
|
||||
addRawSubscription(pub as RawSubscribe);
|
||||
UpdateTable();
|
||||
}
|
||||
updateSubscriptionValue(pub.uuid, pub.value);
|
||||
});
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import type { Driver } from './Drivers';
|
||||
import type { Gets } from './Get';
|
||||
import type { Sets } from './Set';
|
||||
import type { Subs } from './Subscribe';
|
||||
@@ -61,10 +62,11 @@ export async function rawSetsRequest(sets: Sets): Promise<Sets> {
|
||||
|
||||
export async function setRequest(
|
||||
path: string,
|
||||
type: string,
|
||||
value: string | number | boolean,
|
||||
type?: string,
|
||||
value?: string | number | boolean,
|
||||
rights?: string,
|
||||
uuid?: string,
|
||||
driver?: Driver,
|
||||
rename?: boolean,
|
||||
): Promise<Sets> {
|
||||
const payload = {
|
||||
@@ -73,6 +75,7 @@ export async function setRequest(
|
||||
value: value,
|
||||
rights: rights,
|
||||
uuid: uuid,
|
||||
driver: driver,
|
||||
rename: rename,
|
||||
};
|
||||
|
||||
@@ -99,14 +102,18 @@ export async function setsRequest(sets: Sets): Promise<Sets> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteRequest(uuid?: string, path?: string, rename?: boolean): Promise<Sets> {
|
||||
export async function deleteRequest(
|
||||
uuid?: string,
|
||||
path?: string,
|
||||
driver?: Driver,
|
||||
rename?: boolean,
|
||||
): Promise<Sets> {
|
||||
let payload = {};
|
||||
if (uuid) {
|
||||
payload = { uuid: uuid, rename: rename };
|
||||
payload = { uuid: uuid, driver: driver, rename: rename };
|
||||
} else if (path) {
|
||||
payload = { path: path };
|
||||
payload = { path: path, driver: driver };
|
||||
}
|
||||
|
||||
const resp = await api.delete('/json_data', {
|
||||
data: {
|
||||
set: [payload],
|
||||
|
@@ -20,6 +20,7 @@ export type RawSubscribe = {
|
||||
path?: string;
|
||||
depth?: number;
|
||||
value?: string | number | boolean | null;
|
||||
drivers?: Record<string, Driver>;
|
||||
rights?: string;
|
||||
hasChild?: boolean;
|
||||
};
|
||||
|
4
src/vueLib/models/Topic.ts
Normal file
4
src/vueLib/models/Topic.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface Topic {
|
||||
subscribe: string[];
|
||||
publish: string[];
|
||||
}
|
83
src/vueLib/models/driverTable.ts
Normal file
83
src/vueLib/models/driverTable.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { reactive, ref } from 'vue';
|
||||
import type { QTableColumn } from 'quasar';
|
||||
import type { Subscribe } from './Subscribe';
|
||||
|
||||
export type DriverTableRow = {
|
||||
type: string;
|
||||
bus: string;
|
||||
address?: number | undefined;
|
||||
subscribe?: string;
|
||||
publish?: string;
|
||||
};
|
||||
|
||||
const driverTable = reactive<DriverTableRow[]>([]);
|
||||
const columns = ref<QTableColumn[]>([]);
|
||||
const baseColumns: QTableColumn[] = [
|
||||
{ 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' },
|
||||
{ name: 'settings', label: '', field: 'settings', align: 'center' },
|
||||
];
|
||||
|
||||
export function updateDriverTable(sub: Subscribe) {
|
||||
driverTable.length = 0;
|
||||
let hasSubs = false;
|
||||
let hasPubs = false;
|
||||
|
||||
if (sub.drivers)
|
||||
Object.entries(sub.drivers).forEach(([driverName, driverData]) => {
|
||||
driverData.buses?.forEach((bus) => {
|
||||
hasSubs = bus.topic?.subscribe !== undefined || hasSubs;
|
||||
hasPubs = bus.topic?.publish !== undefined || hasPubs;
|
||||
|
||||
const subscribeList = bus.topic?.subscribe ?? [];
|
||||
const publishList = bus.topic?.publish ?? [];
|
||||
|
||||
const addresses = bus.address?.length ? bus.address : [undefined];
|
||||
|
||||
addresses.forEach((addr) => {
|
||||
driverTable.push({
|
||||
type: driverName,
|
||||
bus: bus.name,
|
||||
address: addr,
|
||||
subscribe: subscribeList.join(', '),
|
||||
publish: publishList.join(', '),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
reloadColumns(hasSubs, hasPubs);
|
||||
}
|
||||
export function useDriverTable() {
|
||||
function emptyTable() {
|
||||
driverTable.length = 0;
|
||||
}
|
||||
|
||||
return {
|
||||
driverTable,
|
||||
emptyTable,
|
||||
columns,
|
||||
};
|
||||
}
|
||||
|
||||
function reloadColumns(hasSubs: boolean, hasPubs: boolean) {
|
||||
columns.value = [...baseColumns];
|
||||
const settingsIndex = columns?.value.findIndex((col) => col.name === 'settings');
|
||||
|
||||
if (hasSubs) {
|
||||
columns.value?.splice(settingsIndex ?? -1, 0, {
|
||||
name: 'subscribe',
|
||||
label: 'subscribe',
|
||||
field: 'subscribe',
|
||||
align: 'left',
|
||||
});
|
||||
}
|
||||
if (hasPubs) {
|
||||
columns.value?.splice(settingsIndex ?? -1, 0, {
|
||||
name: 'publish',
|
||||
label: 'publish',
|
||||
field: 'publish',
|
||||
align: 'left',
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user