diff --git a/backend/services/controller/internal/api/api.go b/backend/services/controller/internal/api/api.go index 29e5227..2b3f34c 100644 --- a/backend/services/controller/internal/api/api.go +++ b/backend/services/controller/internal/api/api.go @@ -64,7 +64,7 @@ func (a *Api) StartApi() { iot.HandleFunc("/cwmp/{sn}/setParameterValues", a.cwmpSetParameterValuesMsg).Methods("PUT") iot.HandleFunc("/cwmp/{sn}/addObject", a.cwmpAddObjectMsg).Methods("PUT") iot.HandleFunc("/cwmp/{sn}/deleteObject", a.cwmpDeleteObjectMsg).Methods("PUT") - iot.HandleFunc("", a.retrieveDevices).Methods("GET") + iot.HandleFunc("", a.retrieveDevices).Methods("GET", "DELETE") iot.HandleFunc("/filterOptions", a.filterOptions).Methods("GET") iot.HandleFunc("/{sn}/{mtp}/generic", a.deviceGenericMessage).Methods("PUT") iot.HandleFunc("/{sn}/{mtp}/get", a.deviceGetMsg).Methods("PUT") diff --git a/frontend/src/pages/devices.js b/frontend/src/pages/devices.js index dec5f6e..d0a03e0 100644 --- a/frontend/src/pages/devices.js +++ b/frontend/src/pages/devices.js @@ -39,7 +39,8 @@ import { Select, DialogContentText, TableContainer, - TablePagination + TablePagination, + Typography } from '@mui/material'; import ViewColumnsIcon from '@heroicons/react/24/outline/ViewColumnsIcon'; @@ -95,8 +96,10 @@ const Page = () => { const [rowsPerPage, setRowsPerPage] = useState(20); const [showSetDeviceAlias, setShowSetDeviceAlias] = useState(false); + const [showSetDeviceToBeRemoved, setShowSetDeviceToBeRemoved] = useState(false); const [deviceAlias, setDeviceAlias] = useState(null); const [deviceToBeChanged, setDeviceToBeChanged] = useState(null); + const [deviceToBeRemoved, setDeviceToBeRemoved] = useState(null); const [showFilter, setShowFilter] = useState(false); const [selected, setSelected] = useState([]); const [selectAll, setSelectAll] = useState(false); @@ -260,6 +263,38 @@ const Page = () => { }, [auth.user]); + const removeDevice = async (sn) => { + var myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + myHeaders.append("Authorization", localStorage.getItem("token")); + + var requestOptions = { + method: 'DELETE', + headers: myHeaders, + redirect: 'follow' + }; + + let result = await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT || ""}/api/device?id=${sn}`, requestOptions) + console.log("result:", result) + if (result.status === 401) { + router.push("/auth/login") + } else if (result.status != 200) { + console.log("Status:", result.status) + let content = await result.json() + console.log("Message:", content) + setShowSetDeviceToBeRemoved(false) + setDeviceToBeRemoved(null) + } else { + let content = await result.json() + console.log("remove device result:", content) + setShowSetDeviceToBeRemoved(false) + setDeviceToBeRemoved(null) + devices.splice(deviceToBeRemoved, 1) + setDevices([...devices]) + } + + } + const setNewDeviceAlias = async (alias, sn) => { var myHeaders = new Headers(); myHeaders.append("Content-Type", "application/json"); @@ -663,6 +698,21 @@ const Page = () => { + + + {/* } + {showSetDeviceToBeRemoved && + + + Are you sure you want to remove {devices[deviceToBeRemoved].SN} device? + + + + + + } {/* / : //