-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1dd702
commit 80fbdbb
Showing
12 changed files
with
175 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { base } from '$app/paths'; | ||
import type { DeviceSetting, DeviceDetail } from './types'; | ||
|
||
export async function fetchDeviceSettings(fetch, id: string): Promise<DeviceSetting> { | ||
const response = await fetch(`${base}/api/device/${id}/settings`); | ||
if (!response.ok) throw new Error("Something went wrong loading device details (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} | ||
|
||
export async function fetchDeviceDetails(id: string): Promise<DeviceDetail> { | ||
const response = await fetch(`${base}/api/device/${id}/details`); | ||
if (!response.ok) throw new Error("Something went wrong loading device details (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { base } from '$app/paths'; | ||
import type { Settings, Node, NodeSetting } from './types'; | ||
|
||
export async function loadSettings(id: string): Promise<Settings> { | ||
const response = await fetch(`${base}/api/node/${id}/settings`); | ||
if (!response.ok) throw new Error("Something went wrong loading settings (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} | ||
|
||
export async function saveSettings(newSettings: Settings): Promise<Settings> { | ||
const response = await fetch(`${base}/api/node/${newSettings.id}/settings`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(newSettings), | ||
}); | ||
if (!response.ok) throw new Error("Something went wrong loading settings (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} | ||
|
||
export async function restartNode(nodeId: string): Promise<void> { | ||
const response = await fetch(`${base}/api/node/${nodeId}/restart`, { method: 'POST' }); | ||
if (!response.ok) throw new Error(response.statusText); | ||
} | ||
|
||
export async function updateNodeSelf(nodeId: string): Promise<void> { | ||
const response = await fetch(`${base}/api/node/${nodeId}/update`, { method: 'POST' }); | ||
if (!response.ok) throw new Error(response.statusText); | ||
} | ||
|
||
export async function saveNodeSettings(nodeId: string, settings: NodeSetting): Promise<void> { | ||
const response = await fetch(`${base}/api/node/${nodeId}/settings`, { | ||
method: 'PUT', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(settings) | ||
}); | ||
if (!response.ok) throw new Error(response.statusText); | ||
} | ||
|
||
export async function fetchNode(nodeId: string): Promise<Node> { | ||
const response = await fetch(`${base}/api/node/${nodeId}/settings`); | ||
if (!response.ok) throw new Error(response.statusText); | ||
return await response.json(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { base } from '$app/paths'; | ||
import type { Config, CalibrationData, Device } from './types'; | ||
|
||
export async function fetchConfig(): Promise<Config> { | ||
const response = await fetch(`${base}/api/state/config`); | ||
if (!response.ok) throw new Error("Something went wrong loading config (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} | ||
|
||
export async function fetchCalibrationState(): Promise<CalibrationData> { | ||
const response = await fetch(`${base}/api/state/calibration`); | ||
if (!response.ok) throw new Error("Something went wrong loading calibration state (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} | ||
|
||
export async function fetchDeviceState(): Promise<Device[]> { | ||
const response = await fetch(`${base}/api/state/devices`); | ||
if (!response.ok) throw new Error("Something went wrong loading device state (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} | ||
|
||
export async function fetchNodeState(includeTele: boolean = true): Promise<Node[]> { | ||
const response = await fetch(`${base}/api/state/nodes?includeTele=${includeTele}`); | ||
if (!response.ok) throw new Error("Something went wrong loading node state (error="+response.status+" "+response.statusText+")"); | ||
return await response.json(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { base } from '$app/paths'; | ||
import { error } from '@sveltejs/kit'; | ||
import type { PageLoad } from './$types'; | ||
import { fetchDeviceSettings } from '$lib/device' | ||
|
||
export async function load({ fetch, params }) { | ||
return await fetch(`${base}/api/device/${params.id}`) | ||
.then((response) => { | ||
if (response.status != 200) throw new Error(response.statusText); | ||
var data = response.json(); | ||
return data; | ||
}) | ||
.catch((e) => { | ||
return { settings: { originalId: params.id, id: null, name: null, 'rssi@1m': null, error: e } }; | ||
}); | ||
} | ||
export const load: PageLoad = async ({ fetch, params }) => { | ||
if (!params.id) { | ||
throw error(400, 'No device id'); | ||
} | ||
try { | ||
var settings = fetchDeviceSettings(fetch, params.id); | ||
return { id: params.id, settings: settings }; | ||
} | ||
catch (e) { | ||
return { settings: { originalId: params.id, id: null, name: null, 'rssi@1m': null, error: e } }; | ||
} | ||
}; |
Oops, something went wrong.