import { Box, Button, FormControl, Grid2 as Grid, MenuItem, Select, Tab, Tabs, TextField, Typography, useTheme } from "@mui/material"; import PageContainer from "./PageContainer"; import { pond } from "protobuf-ts/pond"; import LogsDisplay from "common/LogsDisplay"; import { useEffect, useState } from "react"; import { useDeviceAPI, useSnackbar } from "hooks"; import { useLocation, useParams } from "react-router-dom"; import { Component, Device, Interaction } from "models"; import { getContextKeys, getContextTypes } from "pbHelpers/Context"; import SmartBreadcrumb from "common/SmartBreadcrumb"; import { DevicePageData } from "./Device"; import AddComponentManualDialog from "component/AddComponentManualDialog"; import { useGlobalState } from "providers"; import DeviceActions from "device/DeviceActions"; import { cloneDeep } from "lodash"; import { FindAvailablePositions } from "pbHelpers/DeviceAvailability"; import LoadingScreen from "app/LoadingScreen"; import DeviceOverview from "device/DeviceOverview"; interface TabPanelProps { children?: React.ReactNode; index: any; value: any; } function TabPanelMine(props: TabPanelProps) { const { children, value, index, ...other } = props; return ( ); } export default function DeviceSupport() { const deviceID = +(useParams<{ deviceID: string }>()?.deviceID ?? "0"); const deviceAPI = useDeviceAPI() const snackbar = useSnackbar() const theme = useTheme() const { state } = useLocation(); const [{ user, as }] = useGlobalState() const [device, setDevice] = useState(Device.create()) const [devicePageData, setDevicePageData] = useState(state?.devicePageData ? state.devicePageData : undefined) const [tabNumber, setTabNumber] = useState(0) const [newCap, setNewCap] = useState(0); const [datacap, setDatacap] = useState(); const [isOver, setIsOver] = useState(undefined); const [pauseCheck, setPauseCheck] = useState(undefined); const [inputFirmware, setInputFirmware] = useState(""); const [platform, setPlatform] = useState( pond.DevicePlatform.DEVICE_PLATFORM_INVALID ); const [addComponentManualDialogOpen, setAddComponentManualDialogOpen] = useState(false) const [loading, setLoading] = useState(false) // useEffect(() => { // if (state?.device) return // deviceAPI.get(deviceID, undefined, getContextKeys(), getContextTypes()).then(resp => { // setDevice(Device.create(resp.data)) // }) // }, [deviceID, state?.device]) useEffect(() => { if (state?.devicePageData) { setDevice(Device.create(state?.devicePageData.device)) return } setLoading(true) deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes()).then(resp => { setDevice(resp.data?.device ? Device.create(resp.data?.device) : Device.create()) setDevicePageData({ device: resp.data.device ? Device.create(resp.data.device) : Device.create(), components: resp.data.components.map(comp => Component.create(comp)), interactions: resp.data.interactions.map(interaction => Interaction.create(interaction)), permissions: resp.data.permissions, preferences: resp.data.user?.preferences as pond.DevicePreferences }) }).finally(() => { setLoading(false) }) }, [deviceID, state?.devicePageData]) const handleChange = (_event: React.ChangeEvent<{}>, newValue: number) => { setTabNumber(newValue); }; const resetQuackCount = () => { deviceAPI.resetQuackCount(device.id()).then(resp => console.log(resp)); }; const resetQuackCountTx = () => { deviceAPI.resetQuackCountTx(device.id()).then(resp => console.log(resp)); }; const resetQuackCountTx1000 = () => { deviceAPI.resetQuackCountTx1000(device.id()).then(resp => console.log(resp)); }; const clearPending = () => { deviceAPI.clearPending(device.id()).then(resp => { console.log(resp); }); }; const setFirmwareVersion = (firmwareVersion: string) => { let status = device.status; status.firmwareVersion = firmwareVersion; deviceAPI.updateStatus(device.id(), status).then(() => { snackbar.info("Firmware version set to " + firmwareVersion); }); }; const updateDevicePlatform = (firmwareVersion: pond.DevicePlatform) => { let settings = device.settings; settings.platform = firmwareVersion; deviceAPI.update(device.id(), settings).then(() => { snackbar.info("Platform set to " + firmwareVersion.toString()); }); }; const getDatacap = () => { deviceAPI.getDatacap(device.id()).then(resp => { //console.log(resp); setDatacap(resp.data.overlimit); }); }; const updateDatacap = () => { deviceAPI.setDatacap(device.id(), newCap).then(resp => { console.log(resp); }); }; const checkLimit = () => { deviceAPI.isOverLimit(device.id()).then(resp => { //console.log(resp); setIsOver(resp.data); }); }; const checkIfPaused = () => { deviceAPI.isPaused(device.id()).then(resp => { //console.log(resp); setPauseCheck(resp.data); }); }; const pauseDevice = () => { deviceAPI.pause(device.id()).then(resp => { console.log(resp); }); }; const resumeDevice = () => { deviceAPI.resume(device.id()).then(resp => { console.log(resp); }); }; const toggleNotificationPreference = () => { let updatedPreferences = cloneDeep(devicePageData.preferences); updatedPreferences.notify = !devicePageData.preferences.notify; let updatedDevicePageData = cloneDeep(devicePageData) updatedDevicePageData.preferences = updatedPreferences deviceAPI .updatePreferences(deviceID, updatedPreferences, getContextKeys(), getContextTypes(), as) .then(() => setDevicePageData(updatedDevicePageData)) .catch(() => { snackbar.error( "Error occured while " + (devicePageData.preferences.notify ? "enabling" : "disabling") + " notifications" ); }); }; if (!devicePageData) { return ( ) } return ( {}} availablePositions={FindAvailablePositions(devicePageData.components, device.settings.product).availability} availableOffsets={new Map()} components={[...devicePageData.components.map(comp => Component.any(comp))]} interactions={devicePageData.interactions.map(inter => Interaction.any(inter))} /> {/* */}
General Options: setAddComponentManualDialogOpen(false)} /> {user.hasFeature("developer") === true && } setInputFirmware(e.currentTarget.value)} /> OPI Cable Functions: setNewCap(+e.target.value)} /> {datacap && datacap / 1000 / 1000}Mb {isOver === undefined ? "Click to Check" : isOver ? "Over Limit" : "Under Limit"} {pauseCheck === undefined ? "Click to Check" : pauseCheck ? "Paused" : "Running"} History Not imported yet {/* */}
) }