From f69bb64db96a805c366a994fa0162f5f00b745a6 Mon Sep 17 00:00:00 2001 From: Patrick Baxter Date: Wed, 9 Oct 2024 09:23:30 +1300 Subject: [PATCH] add audio modes to browse-next --- api/api/V1/Device.ts | 5 +- browse-next/src/api/Device.ts | 32 ++ .../src/components/DeviceRecordingSetup.vue | 339 +++++++++++++++++- types/api/device.d.ts | 12 + 4 files changed, 376 insertions(+), 12 deletions(-) diff --git a/api/api/V1/Device.ts b/api/api/V1/Device.ts index 7ad0f58e..e1479a70 100755 --- a/api/api/V1/Device.ts +++ b/api/api/V1/Device.ts @@ -1549,7 +1549,10 @@ export default function (app: Application, baseUrl: string) { } ); } catch (e) { - return next(new FatalError("Failed to update device settings.")); + console.log(e); + return next( + new FatalError(`Failed to update device settings: ${e.message}`) + ); } } ); diff --git a/browse-next/src/api/Device.ts b/browse-next/src/api/Device.ts index 50da20e3..eb51bdc2 100644 --- a/browse-next/src/api/Device.ts +++ b/browse-next/src/api/Device.ts @@ -141,6 +141,7 @@ export const getDeviceNodeGroup = (deviceId: DeviceId) => { type: "salt-update", limit: 1, }).then((response) => { + debugger; if (response.success && response.result.rows.length) { resolve( response.result.rows[0].EventDetail.details.nodegroup || @@ -153,6 +154,37 @@ export const getDeviceNodeGroup = (deviceId: DeviceId) => { }) as Promise; }; +export const getDeviceModel = async (deviceId: DeviceId) => { + try { + const nodegroup = await getDeviceNodeGroup(deviceId); + if (nodegroup) { + const model = nodegroup.includes("tc2") + ? "tc2" + : nodegroup.includes("pi") + ? "pi" + : null; + if (model !== null) { + return model; + } + } + const model = await getLatestEventsByDeviceId(deviceId, { + type: "versionData", + limit: 1, + }).then((response) => { + if (response.success && response.result.rows.length) { + return response.result.rows[0].EventDetail.details["tc2-agent"] + ? "tc2" + : "pi"; + } else { + return null; + } + }); + return model; + } catch (e) { + return null; + } +}; + export interface BatteryInfoEvent { dateTime: IsoFormattedString | Date; voltage: number | null; diff --git a/browse-next/src/components/DeviceRecordingSetup.vue b/browse-next/src/components/DeviceRecordingSetup.vue index 0518f1fa..d82c399d 100644 --- a/browse-next/src/components/DeviceRecordingSetup.vue +++ b/browse-next/src/components/DeviceRecordingSetup.vue @@ -4,11 +4,13 @@ import { selectedProjectDevices } from "@models/provides.ts"; import type { ApiDeviceHistorySettings, ApiDeviceResponse, + AudioModes, } from "@typedefs/api/device"; import { useRoute } from "vue-router"; import type { DeviceId } from "@typedefs/api/common"; import type { LoadedResource } from "@api/types.ts"; import { + getDeviceModel, getDeviceNodeGroup, getSettingsForDevice, updateDeviceSettings, @@ -21,7 +23,7 @@ const devices = inject(selectedProjectDevices) as Ref< ApiDeviceResponse[] | null >; const route = useRoute(); -const saltNodeGroup = ref>(null); +const deviceModel = ref>(null); // Device Settings const settings = ref>(null); const syncedSettings = ref>(null); @@ -52,9 +54,9 @@ const device = computed(() => { const settingsLoading = resourceIsLoading(settings); const lastSyncedSettingsLoading = resourceIsLoading(lastSyncedSettings); -const nodeGroupInfoLoading = resourceIsLoading(saltNodeGroup); +const nodeGroupInfoLoading = resourceIsLoading(deviceModel); const isTc2Device = computed(() => { - return (saltNodeGroup.value || "").includes("tc2"); + return deviceModel.value === "tc2"; }); const defaultWindows = { powerOn: "-30m", @@ -78,6 +80,7 @@ const timeObjToTimeStr = (time: Time): string => { const fetchSettings = async () => { const response = await getSettingsForDevice(deviceId.value); + debugger; if (response && response.success && response.result.settings) { return response.result.settings; } @@ -151,8 +154,8 @@ const loadResource = async ( const initialised = ref(false); onBeforeMount(async () => { await projectDevicesLoaded(); - await loadResource(saltNodeGroup, () => getDeviceNodeGroup(deviceId.value)); await loadResource(settings, fetchSettings); + await loadResource(deviceModel, () => getDeviceModel(deviceId.value)); initialised.value = true; if (settings.value && !settings.value.synced) { // Load last synced settings @@ -282,6 +285,236 @@ const customRecordingWindowStop = computed