From 93749d5b70c2125467e112262710e6dbbba4a03b Mon Sep 17 00:00:00 2001 From: leandrofars Date: Thu, 5 Oct 2023 01:13:01 -0300 Subject: [PATCH 1/3] feat: device paramater discovery [close #95] --- .../src/sections/devices/devices-discovery.js | 494 +++++++++++++----- 1 file changed, 374 insertions(+), 120 deletions(-) diff --git a/frontend/src/sections/devices/devices-discovery.js b/frontend/src/sections/devices/devices-discovery.js index 88b9c9b..882b67c 100644 --- a/frontend/src/sections/devices/devices-discovery.js +++ b/frontend/src/sections/devices/devices-discovery.js @@ -14,13 +14,95 @@ import PlusCircleIcon from '@heroicons/react/24/outline/PlusCircleIcon'; import ArrowUturnLeftIcon from '@heroicons/react/24/outline/ArrowUturnLeftIcon' import { useRouter } from 'next/router'; +function ShowParamsWithValues({x, deviceParametersValue}) { + console.log("estoy aqui") + let paths = x.supported_obj_path.split(".") + console.log(paths) + if(paths[paths.length -2] == "{i}"){ + return Object.keys(deviceParametersValue).map((paramKey, h)=>{ + return ( + + + {paramKey}} + sx={{fontWeight:'bold'}} + /> + + {deviceParametersValue[paramKey].map((param, i) => { + console.log("opa") + return ( + + + {Object.values(param)[0]} + + } + > + + + + ) + })} + + ) + }) + }else{ + return x.supported_params.map((y, index)=>{ + return ( + + + {deviceParametersValue[y.param_name]} + + } + > + + + ) + }) + } +} export const DevicesDiscovery = () => { const router = useRouter() const [deviceParameters, setDeviceParameters] = useState(null) -const [deviceParametersValue, setDeviceParametersValue] = useState([]) +const [deviceParametersValue, setDeviceParametersValue] = useState({}) const initialize = async (raw) => { let content = await getDeviceParameters(raw) @@ -47,6 +129,27 @@ const getDeviceParameters = async (raw) =>{ } } +const getDeviceParameterInstances = async (raw) =>{ + var myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + myHeaders.append("Authorization", localStorage.getItem("token")); + + var requestOptions = { + method: 'PUT', + headers: myHeaders, + redirect: 'follow', + body: raw + }; + + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/instances`, requestOptions)) + if (result.status != 200) { + throw new Error('Please check your email and password'); + }else{ + return result.json() + } +} + + useEffect(()=> { initialize( @@ -82,9 +185,95 @@ const getDeviceParameters = async (raw) =>{ // ) // }) // } + // Multi instance not used, found better way to get values + const updateDeviceParametersMultiInstance = async (param) =>{ + console.log("UpdateDeviceParametersMultiInstance => param = ", param) + + let raw = JSON.stringify({ + "obj_paths": [param], + "first_level_only" : true, + "return_commands" : true, + "return_events" : true, + "return_params" : true + }) + + let response = await getDeviceParameterInstances(raw) + console.log("response:", response) + + let instancesToGet = [] + if (response.req_path_results[0].curr_insts) { + let supportedParams = response.req_path_results[0].curr_insts + let instances = () => { + for (let i =0; i < supportedParams.length ;i++){ + instancesToGet.push(supportedParams[i].instantiated_obj_path) + } + } + instances() + }else{ + instancesToGet.push(response.req_path_results[0].requested_path) + } + + let rawInP = JSON.stringify({ + "obj_paths": instancesToGet, + "first_level_only" : true, + "return_commands" : true, + "return_events" : true, + "return_params" : true + }) + + let resultParams = await getDeviceParameters(rawInP) + console.log("result params:", resultParams) + setDeviceParameters(resultParams) + + + let paramsToFetch = [] + + // console.log("parameters to fetch: ", paramsToFetch) + + // let rawV = JSON.stringify({ + // "param_paths": paramsToFetch, + // "max_depth": 1 + // }) + + // let resultValues = await getDeviceParametersValue(rawV) + // console.log("result values:", resultValues) + + + // let rawP = JSON.stringify({ + // "obj_paths": paramsToFetch, + // "first_level_only" : true, + // "return_commands" : true, + // "return_events" : true, + // "return_params" : true + // }) + + // let resultParams = await getDeviceParameters(rawP) + // console.log("result params:", resultParams) + + // let values = {} + // let setvalues = () => {resultValues.req_path_results.map((x)=>{ + // // let path = x.requested_path.split(".") + // // let param = path[path.length -1] + // if (!x.resolved_path_results){ + // return + // } + // x.resolved_path_results.map((y)=> { + + // }) + // // Object.keys(x.resolved_path_results[0].result_params).forEach((key, index) =>{ + // // values[key] = x.resolved_path_results[0].result_params[key] + // // }) + // return values + // })} + // setvalues() + // console.log("values:",values) + + // setDeviceParameters(resultParams) + // setDeviceParametersValue(values) + } const updateDeviceParameters = async (param) => { - + console.log("UpdateDeviceParameters => param = ", param) let raw = JSON.stringify({ "obj_paths": [param], "first_level_only" : true, @@ -97,13 +286,12 @@ const getDeviceParameters = async (raw) =>{ console.log("content:",content) - setDeviceParameters(content) - let supportedParams = content.req_obj_results[0].supported_objs[0].supported_params let parametersToFetch = () => { let paramsToFetch = [] for (let i =0; i < supportedParams.length ;i++){ - paramsToFetch.push(content.req_obj_results[0].supported_objs[0].supported_obj_path+supportedParams[i].param_name) + let supported_obj_path = content.req_obj_results[0].supported_objs[0].supported_obj_path.replaceAll("{i}","*") + paramsToFetch.push(supported_obj_path+supportedParams[i].param_name) } return paramsToFetch } @@ -120,14 +308,58 @@ const getDeviceParameters = async (raw) =>{ let result = await getDeviceParametersValue(raw) console.log("result:", result) - let values = [] - let setValues = result.req_path_results.map((x)=>{ - let path = x.requested_path.split(".") - let param = path[path.length -1] - return values.push(x.resolved_path_results[0].result_params[param]) - }) + let values = {} + // let setvalues = () => {resultValues.req_path_results.map((x)=>{ + // // let path = x.requested_path.split(".") + // // let param = path[path.length -1] + // if (!x.resolved_path_results){ + // return + // } + + // Object.keys(x.resolved_path_results[0].result_params).forEach((key, index) =>{ + // values[key] = x.resolved_path_results[0].result_params[key] + // }) + // return values + // })} + // setvalues() + + let setvalues = () => {result.req_path_results.map((x)=>{ + if (!x.resolved_path_results){ + return + } + + let paths = x.requested_path.split(".") + if(paths[paths.length -2] == "*"){ + x.resolved_path_results.map(y=>{ + if (values[y.resolved_path]){ + values[y.resolved_path].push(y.result_params) + }else{ + values[y.resolved_path] = [] + values[y.resolved_path].push(y.result_params) + } + // Object.keys(y.result_params).forEach((key, index) =>{ + // if (values[y.resolved_path]){ + // values[y.resolved_path].push(y.result_params) + // }else{ + // values[y.resolved_path] = [] + // values[y.resolved_path].push(y.result_params) + // } + // }) + }) + }else{ + Object.keys(x.resolved_path_results[0].result_params).forEach((key, index) =>{ + values[key] = x.resolved_path_results[0].result_params[key] + }) + } + + return values + })} + setvalues() console.log(values) setDeviceParametersValue(values) + setDeviceParameters(content) + }else{ + setDeviceParameters(content) } } @@ -154,117 +386,139 @@ const getDeviceParameters = async (raw) =>{ } const showParameters = () => { - return deviceParameters.req_obj_results[0].supported_objs.map((x,i)=> { - return ( - - - { - let paths = x.supported_obj_path.split(".") - console.log(paths) - updateDeviceParameters(paths[paths.length -3]+".") - } - }> - - - - - : - updateDeviceParameters(x.supported_obj_path)}> - - { - x.supported_obj_path != "Device." && - - } - - + return deviceParameters.req_obj_results.map((a,b)=>{ + return a.supported_objs.map((x,i)=> { + + let supported_obj_path = x.supported_obj_path.split(".") + let supportedObjPath = "" + + supported_obj_path.map((x,i)=>{ + if(i !== supported_obj_path.length -2){ + supportedObjPath = supportedObjPath + x + "." + } + }) + + let req_obj_path = a.req_obj_path.split(".") + let reqObjPath = "" + + req_obj_path.map((x,i)=>{ + if(i !== req_obj_path.length -2){ + reqObjPath = reqObjPath + x + "." + } + }) + + // console.log("reqObjPath:", reqObjPath) + // console.log("supportedObjPath:", supportedObjPath) + + let paramName = x.supported_obj_path + if (supportedObjPath != "Device.."){ + if (supportedObjPath == reqObjPath){ + paramName = a.req_obj_path } - sx={{ - boxShadow: 'rgba(149, 157, 165, 0.2) 0px 0px 5px;' - }} - > - {x.supported_obj_path}} - sx={{fontWeight:'bold'}} - /> - - { x.supported_params && - x.supported_params.map((y, index)=>{ - return - {deviceParametersValue[index]} - } - > - - - - }) } - { x.supported_commands && - x.supported_commands.map((y)=>{ - return - - - - - }) - } - { x.supported_events && - x.supported_events.map((y)=>{ - return - - - - - }) - } - ) + + return ( + + + { + let supported_obj_path = x.supported_obj_path.replaceAll("{i}.","*.") + let paths = supported_obj_path.split(".") + console.log("paths:",paths) + + let pathsToJump = 2 + if (paths[paths.length -2] == "*"){ + pathsToJump = 3 + } + + paths.splice(paths.length - pathsToJump, pathsToJump) + let pathToFetch = paths.join(".") + + updateDeviceParameters(pathToFetch) + } + }> + + + + + : + { + console.log("x.supported_obj_path:",x.supported_obj_path) + let supported_obj_path = x.supported_obj_path.replaceAll("{i}.","*.") + updateDeviceParameters(supported_obj_path) + }}> + + { + x.supported_obj_path != "Device." && + + } + + + } + sx={{ + boxShadow: 'rgba(149, 157, 165, 0.2) 0px 0px 5px;' + }} + > + {paramName}} + sx={{fontWeight:'bold'}} + /> + + { x.supported_params && + + } + { x.supported_commands && + x.supported_commands.map((y)=>{ + return + + + + + }) + } + { x.supported_events && + x.supported_events.map((y)=>{ + return + + + + + }) + } + ) + }) }) } From 3497572c508a63ec14876c5e0f83d53894738e21 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Thu, 5 Oct 2023 01:51:08 -0300 Subject: [PATCH 2/3] chore: add passowrd and user for demo usage --- frontend/src/pages/auth/login.js | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/frontend/src/pages/auth/login.js b/frontend/src/pages/auth/login.js index b2abe4d..a38ebf4 100644 --- a/frontend/src/pages/auth/login.js +++ b/frontend/src/pages/auth/login.js @@ -131,21 +131,12 @@ const Page = () => { Login - {/* - Don't have an account? -   - - Register - - */} + This project is open source, reach out at Github or Slack + {/* { sx={{ mt: 3 }} >
- Don't have an account? ask one for us at - Github - + You can use demo@gmail.com and password demo
From 3f55818b1bb4446bb3128998dfda1aa0d50b68d2 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Thu, 5 Oct 2023 01:51:35 -0300 Subject: [PATCH 3/3] chore: add github link to project --- frontend/public/assets/general/github-mark.png | Bin 0 -> 6393 bytes frontend/src/layouts/dashboard/layout.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 frontend/public/assets/general/github-mark.png diff --git a/frontend/public/assets/general/github-mark.png b/frontend/public/assets/general/github-mark.png new file mode 100644 index 0000000000000000000000000000000000000000..6cb3b705d018006a2bd4200ea94c9d5fb98b6f76 GIT binary patch literal 6393 zcmVt<80drDELIAGL9O(c600d`2O+f$vv5y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&tE`h0d-&WQaq+RNOY1>-l>uJxCCG%Z}2J$QG8&B=04khK>O%~xk zM0^_$2sj0)+-pUh4i`nd7Gm=>{xdkVqTTPG(gV23$$)?tK& zNi|~SpW1gQF!!f^gSEEC@MAW#2Wy)i2sk6e>R78Rjo{Bazq=nlQEO zPIhAR2|W|hV{2_gSX%%900000000000000000000;FtVA#ht2v8mJ-W00000NkvXX Hu0mjfZ$b4` literal 0 HcmV?d00001 diff --git a/frontend/src/layouts/dashboard/layout.js b/frontend/src/layouts/dashboard/layout.js index e480f5d..fbeba5e 100644 --- a/frontend/src/layouts/dashboard/layout.js +++ b/frontend/src/layouts/dashboard/layout.js @@ -52,10 +52,25 @@ export const Layout = withAuthGuard((props) => { onClose={() => setOpenNav(false)} open={openNav} /> + {children} + );