Added location management from web

This commit is contained in:
Hunter Thornsberry
2024-06-12 18:32:04 -04:00
parent 11c69a4610
commit 4466a519c8
2 changed files with 21 additions and 28 deletions
+12 -19
View File
@@ -1,4 +1,4 @@
import type { ChannelValidation } from "@app/validation/channel.js"; import { ChannelValidation, Channel_SettingsValidation } from "@app/validation/channel.js";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.js";
import { useToast } from "@core/hooks/useToast.js"; import { useToast } from "@core/hooks/useToast.js";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.js";
@@ -20,7 +20,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
...data.settings, ...data.settings,
psk: toByteArray(data.settings.psk ?? ""), psk: toByteArray(data.settings.psk ?? ""),
moduleSettings: { moduleSettings: {
positionPrecision: data.positionPrecision, positionPrecision: data.settings.positionEnabled ? data.settings.preciseLocation ? 32 : data.settings.positionPrecision : 0,
} }
}, },
}); });
@@ -43,11 +43,11 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
settings: { settings: {
...channel?.settings, ...channel?.settings,
psk: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)), psk: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)),
positionEnabled: channel?.settings?.moduleSettings?.positionPrecision != undefined && channel?.settings?.moduleSettings?.positionPrecision > 0,
preciseLocation: channel?.settings?.moduleSettings?.positionPrecision == 32,
positionPrecision: channel?.settings?.moduleSettings?.positionPrecision == undefined ? config.display?.units == 0 ? 23000 : 24140 : channel?.settings?.moduleSettings?.positionPrecision
}, },
}, },
positionEnabled: true,
preciseLocation: true,
positionPrecision: 1
}} }}
fieldGroups={[ fieldGroups={[
{ {
@@ -85,6 +85,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
name: "settings.uplinkEnabled", name: "settings.uplinkEnabled",
label: "Uplink Enabled", label: "Uplink Enabled",
description: "Send messages from the local mesh to MQTT", description: "Send messages from the local mesh to MQTT",
}, },
{ {
type: "toggle", type: "toggle",
@@ -94,35 +95,27 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
}, },
{ {
type: "toggle", type: "toggle",
name: "positionEnabled", name: "settings.positionEnabled",
label: "Allow Position Requests", label: "Allow Position Requests",
description: "Send position to channel", description: "Send position to channel",
}, },
{ {
type: "toggle", type: "toggle",
name: "preciseLocation", name: "settings.preciseLocation",
label: "Precise Location", label: "Precise Location",
description: "Send precise location to channel", description: "Send precise location to channel",
disabledBy: [{
fieldName: "positionEnabled",
}]
}, },
{ {
type: "select", type: "select",
name: "positionPrecision", name: "settings.positionPrecision",
label: "Approximate Location", label: "Approximate Location",
description: description:
"Position shared on mesh is accurate within this distance", "If not sharing precise location, position shared on mesh will be accurate within this distance",
properties: { properties: {
enumValue: config.display?.units == 0 ? enumValue: config.display?.units == 0 ?
{ "Within 23 km":2300, "Within 12 km":12000, "Within 5.8 km":5800, "Within 2.9 km":2900, "Within 1.5 km":1500, "Within 700 m":700, "Within 350 m":350, "Within 200 m":200, "Within 90 m":90, "Within 50 m":50 } : { "Within 23 km":23000, "Within 12 km":12000, "Within 5.8 km":5800, "Within 2.9 km":2900, "Within 1.5 km":1500, "Within 700 m":700, "Within 350 m":350, "Within 200 m":200, "Within 90 m":90, "Within 50 m":50 } :
{ "Within 15 miles":1, "Within 7.3 miles":2, "Within 3.6 miles":3, "Within 1.8 miles":4, "Within 0.9 miles":5, "Within 0.5 miles":6, "Within 0.2 miles":7, "Within 600 feet":8, "Within 300 feet":9, "Within 150 feet":10 } { "Within 15 miles":24140, "Within 7.3 miles":11748, "Within 3.6 miles":5793, "Within 1.8 miles":2896, "Within 0.9 miles":1448, "Within 0.5 miles":804, "Within 0.2 miles":321, "Within 600 feet":182, "Within 300 feet":91, "Within 150 feet":45 }
}, },
disabledBy: [
{
fieldName: "positionEnabled",
},
],
}, },
], ],
}, },
+9 -9
View File
@@ -19,15 +19,6 @@ export class ChannelValidation
@IsEnum(Protobuf.Channel.Channel_Role) @IsEnum(Protobuf.Channel.Channel_Role)
role: Protobuf.Channel.Channel_Role; role: Protobuf.Channel.Channel_Role;
@IsBoolean()
positionEnabled: boolean;
@IsBoolean()
preciseLocation: boolean;
@IsInt()
positionPrecision: number;
} }
export class Channel_SettingsValidation export class Channel_SettingsValidation
@@ -50,4 +41,13 @@ export class Channel_SettingsValidation
@IsBoolean() @IsBoolean()
downlinkEnabled: boolean; downlinkEnabled: boolean;
@IsBoolean()
positionEnabled: boolean;
@IsBoolean()
preciseLocation: boolean;
@IsInt()
positionPrecision: number;
} }