From 8112e1ed8b7e2b6973712aa38e5afa9f35b6bf11 Mon Sep 17 00:00:00 2001 From: Sina Blattmann Date: Mon, 6 Mar 2023 09:32:43 +0100 Subject: [PATCH] Change folder structure --- typescript/Frontend/lang/en.json | 50 --- typescript/Frontend/src/App.tsx | 9 +- typescript/Frontend/src/Login.tsx | 2 +- typescript/Frontend/src/api.tsx | 5 - .../{routes => components/Groups}/Group.tsx | 4 +- .../src/components/{ => Groups}/GroupTabs.tsx | 4 +- .../src/components/{ => Groups}/GroupTree.tsx | 5 +- .../{routes => components/Groups}/Groups.tsx | 10 +- .../Installations}/Alarms.tsx | 10 +- .../{ => Installations}/CustomerForm.tsx | 240 +++++++------- .../Installations}/Installation.tsx | 106 +++--- .../{ => Installations}/InstallationList.tsx | 8 +- .../{ => Installations}/InstallationTabs.tsx | 4 +- .../Installations}/Installations.tsx | 10 +- .../Installations}/Log.tsx | 312 +++++++++--------- .../src/components/{ => Layout}/FlowComp.tsx | 114 +++---- .../{ => Layout}/InnovenergyTextfield.tsx | 76 ++--- .../{ => Layout}/LanguageSelect.tsx | 0 .../components/{ => Layout}/LogoutButton.tsx | 2 +- .../{ => Layout}/NavigationButtons.tsx | 10 +- .../src/components/{ => Layout}/Sidebar.tsx | 2 +- .../src/components/{ => Layout}/Table.tsx | 130 ++++---- .../Frontend/src/components/Navigation.scss | 3 - .../Frontend/src/components/Navigation.tsx | 16 - 24 files changed, 531 insertions(+), 601 deletions(-) delete mode 100644 typescript/Frontend/lang/en.json delete mode 100644 typescript/Frontend/src/api.tsx rename typescript/Frontend/src/{routes => components/Groups}/Group.tsx (91%) rename typescript/Frontend/src/components/{ => Groups}/GroupTabs.tsx (93%) rename typescript/Frontend/src/components/{ => Groups}/GroupTree.tsx (93%) rename typescript/Frontend/src/{routes => components/Groups}/Groups.tsx (74%) rename typescript/Frontend/src/{routes => components/Installations}/Alarms.tsx (93%) rename typescript/Frontend/src/components/{ => Installations}/CustomerForm.tsx (90%) rename typescript/Frontend/src/{routes => components/Installations}/Installation.tsx (86%) rename typescript/Frontend/src/components/{ => Installations}/InstallationList.tsx (93%) rename typescript/Frontend/src/components/{ => Installations}/InstallationTabs.tsx (95%) rename typescript/Frontend/src/{routes => components/Installations}/Installations.tsx (79%) rename typescript/Frontend/src/{routes => components/Installations}/Log.tsx (95%) rename typescript/Frontend/src/components/{ => Layout}/FlowComp.tsx (95%) rename typescript/Frontend/src/components/{ => Layout}/InnovenergyTextfield.tsx (96%) rename typescript/Frontend/src/components/{ => Layout}/LanguageSelect.tsx (100%) rename typescript/Frontend/src/components/{ => Layout}/LogoutButton.tsx (92%) rename typescript/Frontend/src/components/{ => Layout}/NavigationButtons.tsx (80%) rename typescript/Frontend/src/components/{ => Layout}/Sidebar.tsx (90%) rename typescript/Frontend/src/components/{ => Layout}/Table.tsx (96%) delete mode 100644 typescript/Frontend/src/components/Navigation.scss delete mode 100644 typescript/Frontend/src/components/Navigation.tsx diff --git a/typescript/Frontend/lang/en.json b/typescript/Frontend/lang/en.json deleted file mode 100644 index c2937f320..000000000 --- a/typescript/Frontend/lang/en.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "alarms": { - "defaultMessage": "Alarms" - }, - "allInstallations": { - "defaultMessage": "All installations" - }, - "applyChanges": { - "defaultMessage": "Apply changes" - }, - "country": { - "defaultMessage": "Country" - }, - "customerName": { - "defaultMessage": "Customer name" - }, - "english": { - "defaultMessage": "English" - }, - "german": { - "defaultMessage": "German" - }, - "installation": { - "defaultMessage": "Installation" - }, - "location": { - "defaultMessage": "Location" - }, - "log": { - "defaultMessage": "Log" - }, - "logout": { - "defaultMessage": "Logout" - }, - "orderNumbers": { - "defaultMessage": "Order number" - }, - "region": { - "defaultMessage": "Region" - }, - "search": { - "defaultMessage": "Search" - }, - "updatedSuccessfully": { - "defaultMessage": "Updated successfully" - }, - "users": { - "defaultMessage": "Users" - } -} diff --git a/typescript/Frontend/src/App.tsx b/typescript/Frontend/src/App.tsx index f33d0aafd..14e903ff0 100644 --- a/typescript/Frontend/src/App.tsx +++ b/typescript/Frontend/src/App.tsx @@ -7,11 +7,10 @@ import { IntlProvider } from "react-intl"; import { useState } from "react"; import en from "./lang/en.json"; import de from "./lang/de.json"; -import LanguageSelect from "./components/LanguageSelect"; -import LogoutButton from "./components/LogoutButton"; -import Installations from "./routes/Installations"; - -import Groups from "./routes/Groups"; +import Installations from "./components/Installations/Installations"; +import LanguageSelect from "./components/Layout/LanguageSelect"; +import LogoutButton from "./components/Layout/LogoutButton"; +import Groups from "./components/Groups/Groups"; const App = () => { const { token, setToken, removeToken } = useToken(); diff --git a/typescript/Frontend/src/Login.tsx b/typescript/Frontend/src/Login.tsx index 10939760d..d2448a1ed 100644 --- a/typescript/Frontend/src/Login.tsx +++ b/typescript/Frontend/src/Login.tsx @@ -1,8 +1,8 @@ import React, { useState } from "react"; import { Alert, Button, CircularProgress, Grid } from "@mui/material"; import Container from "@mui/material/Container"; -import InnovenergyTextfield from "./components/InnovenergyTextfield"; import { axiosConfigWithoutToken } from "./config/axiosConfig"; +import InnovenergyTextfield from "./components/Layout/InnovenergyTextfield"; const loginUser = async (username: string, password: string) => { return axiosConfigWithoutToken.post("/Login", { diff --git a/typescript/Frontend/src/api.tsx b/typescript/Frontend/src/api.tsx deleted file mode 100644 index 7dfdd0de7..000000000 --- a/typescript/Frontend/src/api.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import axios from 'axios'; - -export const API = axios.create({ - baseURL: `https://localhost:7291/` -}); \ No newline at end of file diff --git a/typescript/Frontend/src/routes/Group.tsx b/typescript/Frontend/src/components/Groups/Group.tsx similarity index 91% rename from typescript/Frontend/src/routes/Group.tsx rename to typescript/Frontend/src/components/Groups/Group.tsx index fe1d53cde..7ee75835d 100644 --- a/typescript/Frontend/src/routes/Group.tsx +++ b/typescript/Frontend/src/components/Groups/Group.tsx @@ -2,8 +2,8 @@ import { Box, CircularProgress, Alert } from "@mui/material"; import { AxiosError } from "axios"; import { useState, useEffect } from "react"; import { useParams } from "react-router-dom"; -import axiosConfig from "../config/axiosConfig"; -import { I_Installation } from "../util/types"; +import axiosConfig from "../../config/axiosConfig"; +import { I_Installation } from "../../util/types"; const Group = () => { const { id } = useParams(); diff --git a/typescript/Frontend/src/components/GroupTabs.tsx b/typescript/Frontend/src/components/Groups/GroupTabs.tsx similarity index 93% rename from typescript/Frontend/src/components/GroupTabs.tsx rename to typescript/Frontend/src/components/Groups/GroupTabs.tsx index dee0b92dd..a279982e9 100644 --- a/typescript/Frontend/src/components/GroupTabs.tsx +++ b/typescript/Frontend/src/components/Groups/GroupTabs.tsx @@ -3,8 +3,8 @@ import Tabs from "@mui/material/Tabs"; import Tab from "@mui/material/Tab"; import Box from "@mui/material/Box"; import { Link } from "react-router-dom"; -import routes from "../routes.json"; -import useRouteMatch from "../hooks/useRouteMatch"; +import routes from "../../routes.json"; +import useRouteMatch from "../../hooks/useRouteMatch"; import { useIntl } from "react-intl"; const GroupTabs = () => { diff --git a/typescript/Frontend/src/components/GroupTree.tsx b/typescript/Frontend/src/components/Groups/GroupTree.tsx similarity index 93% rename from typescript/Frontend/src/components/GroupTree.tsx rename to typescript/Frontend/src/components/Groups/GroupTree.tsx index cd400e398..8da0135e8 100644 --- a/typescript/Frontend/src/components/GroupTree.tsx +++ b/typescript/Frontend/src/components/Groups/GroupTree.tsx @@ -3,9 +3,10 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import ChevronRightIcon from "@mui/icons-material/ChevronRight"; import { ReactNode, useEffect, useState } from "react"; import { TreeItem } from "@mui/lab"; -import { I_Folder, I_Installation } from "../util/types"; -import axiosConfig from "../config/axiosConfig"; + import { Link } from "react-router-dom"; +import axiosConfig from "../../config/axiosConfig"; +import { I_Folder, I_Installation } from "../../util/types"; const GroupTree = () => { const [data, setData] = useState<(I_Folder | I_Installation)[]>(); diff --git a/typescript/Frontend/src/routes/Groups.tsx b/typescript/Frontend/src/components/Groups/Groups.tsx similarity index 74% rename from typescript/Frontend/src/routes/Groups.tsx rename to typescript/Frontend/src/components/Groups/Groups.tsx index d5eb782c9..77c062ca9 100644 --- a/typescript/Frontend/src/routes/Groups.tsx +++ b/typescript/Frontend/src/components/Groups/Groups.tsx @@ -1,11 +1,11 @@ import { Grid } from "@mui/material"; import { Container } from "@mui/system"; import { Routes, Route } from "react-router"; -import GroupTabs from "../components/GroupTabs"; -import NavigationButtons from "../components/NavigationButtons"; -import UserTree from "../components/GroupTree"; -import routes from "../routes.json"; +import routes from "../../routes.json"; +import NavigationButtons from "../Layout/NavigationButtons"; import Group from "./Group"; +import GroupTabs from "./GroupTabs"; +import GroupTree from "./GroupTree"; const Groups = () => { return ( @@ -13,7 +13,7 @@ const Groups = () => { - + diff --git a/typescript/Frontend/src/routes/Alarms.tsx b/typescript/Frontend/src/components/Installations/Alarms.tsx similarity index 93% rename from typescript/Frontend/src/routes/Alarms.tsx rename to typescript/Frontend/src/components/Installations/Alarms.tsx index a7cb1420d..9baf6bf70 100644 --- a/typescript/Frontend/src/routes/Alarms.tsx +++ b/typescript/Frontend/src/components/Installations/Alarms.tsx @@ -1,5 +1,5 @@ -const Alarms = () => { - return
alarms
; -}; - -export default Alarms; +const Alarms = () => { + return
alarms
; +}; + +export default Alarms; diff --git a/typescript/Frontend/src/components/CustomerForm.tsx b/typescript/Frontend/src/components/Installations/CustomerForm.tsx similarity index 90% rename from typescript/Frontend/src/components/CustomerForm.tsx rename to typescript/Frontend/src/components/Installations/CustomerForm.tsx index a5393c71e..f37718c95 100644 --- a/typescript/Frontend/src/components/CustomerForm.tsx +++ b/typescript/Frontend/src/components/Installations/CustomerForm.tsx @@ -1,120 +1,120 @@ -import { Alert, Button, Grid, Snackbar } from "@mui/material"; -import { useFormik } from "formik"; -import { useState } from "react"; -import { FormattedMessage, useIntl } from "react-intl"; -import axiosConfig from "../config/axiosConfig"; -import { I_Installation } from "../util/types"; -import InnovenergyTextfield from "./InnovenergyTextfield"; - -interface I_CustomerFormProps { - values: I_Installation; - id: string | undefined; -} -const CustomerForm = (props: I_CustomerFormProps) => { - const { values, id } = props; - const intl = useIntl(); - - const [open, setOpen] = useState(false); - - const formik = useFormik({ - initialValues: { - name: values.name, - region: values.region, - location: values.location, - country: values.country, - orderNumbers: values.orderNumbers, - }, - onSubmit: (formikValues) => { - axiosConfig - .put("https://localhost:7087/api/UpdateInstallation", { - ...formikValues, - id, - }) - .then((res) => { - setOpen(true); - }); - }, - }); - - const handleClose = () => { - setOpen(false); - }; - - return ( -
- - - - - - - - - - - - - - - ); -}; - -export default CustomerForm; +import { Alert, Button, Grid, Snackbar } from "@mui/material"; +import { useFormik } from "formik"; +import { useState } from "react"; +import { FormattedMessage, useIntl } from "react-intl"; +import axiosConfig from "../../config/axiosConfig"; +import { I_Installation } from "../../util/types"; +import InnovenergyTextfield from "../Layout/InnovenergyTextfield"; + +interface I_CustomerFormProps { + values: I_Installation; + id: string | undefined; +} +const CustomerForm = (props: I_CustomerFormProps) => { + const { values, id } = props; + const intl = useIntl(); + + const [open, setOpen] = useState(false); + + const formik = useFormik({ + initialValues: { + name: values.name, + region: values.region, + location: values.location, + country: values.country, + orderNumbers: values.orderNumbers, + }, + onSubmit: (formikValues) => { + axiosConfig + .put("/UpdateInstallation", { + ...formikValues, + id, + }) + .then((res) => { + setOpen(true); + }); + }, + }); + + const handleClose = () => { + setOpen(false); + }; + + return ( +
+ + + + + + + + + + + + + + + ); +}; + +export default CustomerForm; diff --git a/typescript/Frontend/src/routes/Installation.tsx b/typescript/Frontend/src/components/Installations/Installation.tsx similarity index 86% rename from typescript/Frontend/src/routes/Installation.tsx rename to typescript/Frontend/src/components/Installations/Installation.tsx index fe6c60dac..de6f78824 100644 --- a/typescript/Frontend/src/routes/Installation.tsx +++ b/typescript/Frontend/src/components/Installations/Installation.tsx @@ -1,53 +1,53 @@ -import { Alert, Box, CircularProgress } from "@mui/material"; -import { AxiosError } from "axios"; -import { useEffect, useState } from "react"; -import { useParams } from "react-router-dom"; -import CustomerForm from "../components/CustomerForm"; -import axiosConfig from "../config/axiosConfig"; -import { I_Installation } from "../util/types"; - -const InstallationDetail = () => { - const { id } = useParams(); - const [values, setValues] = useState(); - const [loading, setLoading] = useState(false); - const [error, setError] = useState(); - - useEffect(() => { - setLoading(true); - axiosConfig - .get("/GetInstallationById?id=" + id) - .then((res) => { - setValues(res.data); - setLoading(false); - }) - .catch((err: AxiosError) => { - setError(err); - setLoading(false); - }); - }, [id]); - - if (values && values.id && values.id.toString() === id) { - return ( - - - - ); - } else if (loading) { - return ( - - - - ); - } else if (error) { - return ( - - {error.message} - - ); - } - return null; -}; - -export default InstallationDetail; +import { Alert, Box, CircularProgress } from "@mui/material"; +import { AxiosError } from "axios"; +import { useEffect, useState } from "react"; +import { useParams } from "react-router-dom"; +import CustomerForm from "./CustomerForm"; +import axiosConfig from "../../config/axiosConfig"; +import { I_Installation } from "../../util/types"; + +const InstallationDetail = () => { + const { id } = useParams(); + const [values, setValues] = useState(); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(); + + useEffect(() => { + setLoading(true); + axiosConfig + .get("/GetInstallationById?id=" + id) + .then((res) => { + setValues(res.data); + setLoading(false); + }) + .catch((err: AxiosError) => { + setError(err); + setLoading(false); + }); + }, [id]); + + if (values && values.id && values.id.toString() === id) { + return ( + + + + ); + } else if (loading) { + return ( + + + + ); + } else if (error) { + return ( + + {error.message} + + ); + } + return null; +}; + +export default InstallationDetail; diff --git a/typescript/Frontend/src/components/InstallationList.tsx b/typescript/Frontend/src/components/Installations/InstallationList.tsx similarity index 93% rename from typescript/Frontend/src/components/InstallationList.tsx rename to typescript/Frontend/src/components/Installations/InstallationList.tsx index 082202e7c..b145cd0b3 100644 --- a/typescript/Frontend/src/components/InstallationList.tsx +++ b/typescript/Frontend/src/components/Installations/InstallationList.tsx @@ -3,11 +3,11 @@ import ListItemButton from "@mui/material/ListItemButton"; import ListItemText from "@mui/material/ListItemText"; import { CircularProgress, Divider, Grid } from "@mui/material"; import { Link } from "react-router-dom"; -import useRouteMatch from "../hooks/useRouteMatch"; -import routes from "../routes.json"; +import useRouteMatch from "../../hooks/useRouteMatch"; +import routes from "../../routes.json"; import { Fragment, useEffect, useState } from "react"; -import { I_Installation } from "../util/types"; -import axiosConfig from "../config/axiosConfig"; +import { I_Installation } from "../../util/types"; +import axiosConfig from "../../config/axiosConfig"; interface InstallationListProps { searchQuery: string; diff --git a/typescript/Frontend/src/components/InstallationTabs.tsx b/typescript/Frontend/src/components/Installations/InstallationTabs.tsx similarity index 95% rename from typescript/Frontend/src/components/InstallationTabs.tsx rename to typescript/Frontend/src/components/Installations/InstallationTabs.tsx index 678518c84..1b56e574d 100644 --- a/typescript/Frontend/src/components/InstallationTabs.tsx +++ b/typescript/Frontend/src/components/Installations/InstallationTabs.tsx @@ -3,8 +3,8 @@ import Tabs from "@mui/material/Tabs"; import Tab from "@mui/material/Tab"; import Box from "@mui/material/Box"; import { Link } from "react-router-dom"; -import routes from "../routes.json"; -import useRouteMatch from "../hooks/useRouteMatch"; +import routes from "../../routes.json"; +import useRouteMatch from "../../hooks/useRouteMatch"; import { useIntl } from "react-intl"; const InstallationTabs = () => { diff --git a/typescript/Frontend/src/routes/Installations.tsx b/typescript/Frontend/src/components/Installations/Installations.tsx similarity index 79% rename from typescript/Frontend/src/routes/Installations.tsx rename to typescript/Frontend/src/components/Installations/Installations.tsx index 2670ce302..5a3086918 100644 --- a/typescript/Frontend/src/routes/Installations.tsx +++ b/typescript/Frontend/src/components/Installations/Installations.tsx @@ -1,14 +1,14 @@ import { Grid } from "@mui/material"; import { Container } from "@mui/system"; import { Routes, Route } from "react-router"; -import InstallationTabs from "../components/InstallationTabs"; -import NavigationButtons from "../components/NavigationButtons"; -import BasicTable from "../components/Table"; +import NavigationButtons from "../Layout/NavigationButtons"; +import Sidebar from "../Layout/Sidebar"; +import BasicTable from "../Layout/Table"; import Alarms from "./Alarms"; import InstallationDetail from "./Installation"; +import InstallationTabs from "./InstallationTabs"; import Log from "./Log"; -import routes from "../routes.json"; -import Sidebar from "../components/Sidebar"; +import routes from "../../routes.json"; const Installations = () => { return ( diff --git a/typescript/Frontend/src/routes/Log.tsx b/typescript/Frontend/src/components/Installations/Log.tsx similarity index 95% rename from typescript/Frontend/src/routes/Log.tsx rename to typescript/Frontend/src/components/Installations/Log.tsx index 8b1eb817a..c3606b476 100644 --- a/typescript/Frontend/src/routes/Log.tsx +++ b/typescript/Frontend/src/components/Installations/Log.tsx @@ -1,156 +1,156 @@ -const Log = () => { - const foo = { - TimeStamp: "1676643900", - Devices: [ - { - "TruConvertAc 205330741": { - Ac: { - L1: { - Current: 2.49, - Voltage: 239.4, - Phi: 0.200334842323119592691046359, - }, - L2: { - Current: 2.65, - Voltage: 239.6, - Phi: 0.200334842323119592691046359, - }, - L3: { - Current: 2.63, - Voltage: 239.8, - Phi: 0, - }, - Frequency: 49.98, - }, - Dc: { - Current: 2.249388753056234718826405868, - Voltage: 818, - Power: 1840.0, - }, - Alarms: [], - }, - }, - { - "TruConvertDc 3214": { - Dc: { - Current: -2.1173594132029339853300733496, - Voltage: 818, - Power: -1732.0, - }, - Dc48: { - Current: -30, - Voltage: 56.0, - Power: -1680.0, - }, - Warnings: [], - Alarms: [], - }, - }, - { - "EmuMeter 123": { - Ac: { - L1: { - Current: 3.212, - Voltage: 239.4, - Phi: 1.1483422646081408626645746948, - }, - L2: { - Current: -2.462, - Voltage: 238.9, - Phi: 1.8441893582623698418074097834, - }, - L3: { - Current: 2.995, - Voltage: 238.8, - Phi: 0.1415394733244272187457893568, - }, - Frequency: 49.9, - }, - }, - }, - { - "EmuMeter 123": { - Ac: { - L1: { - Current: 3.212, - Voltage: 239.4, - Phi: 1.1483422646081408626645746948, - }, - L2: { - Current: -2.462, - Voltage: 238.9, - Phi: 1.8441893582623698418074097834, - }, - L3: { - Current: 2.995, - Voltage: 238.8, - Phi: 0.1415394733244272187457893568, - }, - Frequency: 49.9, - }, - }, - }, - { - Name: "AMPT", - Type: "PvOnDc", - "Current 1": 2.098, - "Current 2": 2.575, - "Voltage 1": 822.989, - "Voltage 2": 823.169, - "Power 1": 1726.630922, - "Power 2": 2119.660175, - }, - { - Name: "48TL Battery", - Type: "Battery", - Dc48: { - Current: 14.17, - Voltage: 53.41, - Power: 756.8197, - }, - Alarms: [], - Warnings: [], - Soc: 77.4, - HeaterOn: true, - EocReached: false, - BatteryCold: false, - Temperature: 265.4, - }, - { - Name: "48TL Battery", - Type: "Battery", - Dc48: { - Current: 11.3, - Voltage: 53.4, - Power: 603.42, - }, - Alarms: [], - Warnings: ["bit44:"], - Soc: 77.6, - HeaterOn: true, - EocReached: false, - BatteryCold: false, - Temperature: 264.9, - }, - ], - }; - - const flattenObject = (obj: any, prefix = "") => - Object.keys(obj).reduce((previous: any, current: any) => { - const pre = prefix.length ? prefix + "/" : ""; - if (Array.isArray(obj) || typeof obj === "string") { - return previous; - } - if (typeof obj[current] === "object") { - Object.assign(previous, flattenObject(obj[current], pre + current)); - } else { - previous[pre + current] = obj[current]; - } - return previous; - }, {}); - - console.log(flattenObject(foo.Devices[0])); - return
log
; -}; - -export default Log; +const Log = () => { + const foo = { + TimeStamp: "1676643900", + Devices: [ + { + "TruConvertAc 205330741": { + Ac: { + L1: { + Current: 2.49, + Voltage: 239.4, + Phi: 0.200334842323119592691046359, + }, + L2: { + Current: 2.65, + Voltage: 239.6, + Phi: 0.200334842323119592691046359, + }, + L3: { + Current: 2.63, + Voltage: 239.8, + Phi: 0, + }, + Frequency: 49.98, + }, + Dc: { + Current: 2.249388753056234718826405868, + Voltage: 818, + Power: 1840.0, + }, + Alarms: [], + }, + }, + { + "TruConvertDc 3214": { + Dc: { + Current: -2.1173594132029339853300733496, + Voltage: 818, + Power: -1732.0, + }, + Dc48: { + Current: -30, + Voltage: 56.0, + Power: -1680.0, + }, + Warnings: [], + Alarms: [], + }, + }, + { + "EmuMeter 123": { + Ac: { + L1: { + Current: 3.212, + Voltage: 239.4, + Phi: 1.1483422646081408626645746948, + }, + L2: { + Current: -2.462, + Voltage: 238.9, + Phi: 1.8441893582623698418074097834, + }, + L3: { + Current: 2.995, + Voltage: 238.8, + Phi: 0.1415394733244272187457893568, + }, + Frequency: 49.9, + }, + }, + }, + { + "EmuMeter 123": { + Ac: { + L1: { + Current: 3.212, + Voltage: 239.4, + Phi: 1.1483422646081408626645746948, + }, + L2: { + Current: -2.462, + Voltage: 238.9, + Phi: 1.8441893582623698418074097834, + }, + L3: { + Current: 2.995, + Voltage: 238.8, + Phi: 0.1415394733244272187457893568, + }, + Frequency: 49.9, + }, + }, + }, + { + Name: "AMPT", + Type: "PvOnDc", + "Current 1": 2.098, + "Current 2": 2.575, + "Voltage 1": 822.989, + "Voltage 2": 823.169, + "Power 1": 1726.630922, + "Power 2": 2119.660175, + }, + { + Name: "48TL Battery", + Type: "Battery", + Dc48: { + Current: 14.17, + Voltage: 53.41, + Power: 756.8197, + }, + Alarms: [], + Warnings: [], + Soc: 77.4, + HeaterOn: true, + EocReached: false, + BatteryCold: false, + Temperature: 265.4, + }, + { + Name: "48TL Battery", + Type: "Battery", + Dc48: { + Current: 11.3, + Voltage: 53.4, + Power: 603.42, + }, + Alarms: [], + Warnings: ["bit44:"], + Soc: 77.6, + HeaterOn: true, + EocReached: false, + BatteryCold: false, + Temperature: 264.9, + }, + ], + }; + + const flattenObject = (obj: any, prefix = "") => + Object.keys(obj).reduce((previous: any, current: any) => { + const pre = prefix.length ? prefix + "/" : ""; + if (Array.isArray(obj) || typeof obj === "string") { + return previous; + } + if (typeof obj[current] === "object") { + Object.assign(previous, flattenObject(obj[current], pre + current)); + } else { + previous[pre + current] = obj[current]; + } + return previous; + }, {}); + + console.log(flattenObject(foo.Devices[0])); + return
log
; +}; + +export default Log; diff --git a/typescript/Frontend/src/components/FlowComp.tsx b/typescript/Frontend/src/components/Layout/FlowComp.tsx similarity index 95% rename from typescript/Frontend/src/components/FlowComp.tsx rename to typescript/Frontend/src/components/Layout/FlowComp.tsx index 9868366f2..ef40a9ad9 100644 --- a/typescript/Frontend/src/components/FlowComp.tsx +++ b/typescript/Frontend/src/components/Layout/FlowComp.tsx @@ -1,57 +1,57 @@ -import { useState, useCallback } from "react"; -import ReactFlow, { - addEdge, - FitViewOptions, - applyNodeChanges, - applyEdgeChanges, - Node, - Edge, - NodeChange, - EdgeChange, - Connection, -} from "reactflow"; - -const initialNodes: Node[] = [ - { id: "1", data: { label: "Node 1" }, position: { x: 5, y: 5 } }, - { id: "2", data: { label: "Node 2" }, position: { x: 5, y: 100 } }, -]; - -const initialEdges: Edge[] = [{ id: "e1-2", source: "1", target: "2" }]; - -const fitViewOptions: FitViewOptions = { - padding: 0.2, -}; - -function Flow() { - const [nodes, setNodes] = useState(initialNodes); - const [edges, setEdges] = useState(initialEdges); - - const onNodesChange = useCallback( - (changes: NodeChange[]) => - setNodes((nds) => applyNodeChanges(changes, nds)), - [setNodes] - ); - const onEdgesChange = useCallback( - (changes: EdgeChange[]) => - setEdges((eds) => applyEdgeChanges(changes, eds)), - [setEdges] - ); - const onConnect = useCallback( - (connection: Connection) => setEdges((eds) => addEdge(connection, eds)), - [setEdges] - ); - - return ( - - ); -} - -export default Flow; +import { useState, useCallback } from "react"; +import ReactFlow, { + addEdge, + FitViewOptions, + applyNodeChanges, + applyEdgeChanges, + Node, + Edge, + NodeChange, + EdgeChange, + Connection, +} from "reactflow"; + +const initialNodes: Node[] = [ + { id: "1", data: { label: "Node 1" }, position: { x: 5, y: 5 } }, + { id: "2", data: { label: "Node 2" }, position: { x: 5, y: 100 } }, +]; + +const initialEdges: Edge[] = [{ id: "e1-2", source: "1", target: "2" }]; + +const fitViewOptions: FitViewOptions = { + padding: 0.2, +}; + +function Flow() { + const [nodes, setNodes] = useState(initialNodes); + const [edges, setEdges] = useState(initialEdges); + + const onNodesChange = useCallback( + (changes: NodeChange[]) => + setNodes((nds) => applyNodeChanges(changes, nds)), + [setNodes] + ); + const onEdgesChange = useCallback( + (changes: EdgeChange[]) => + setEdges((eds) => applyEdgeChanges(changes, eds)), + [setEdges] + ); + const onConnect = useCallback( + (connection: Connection) => setEdges((eds) => addEdge(connection, eds)), + [setEdges] + ); + + return ( + + ); +} + +export default Flow; diff --git a/typescript/Frontend/src/components/InnovenergyTextfield.tsx b/typescript/Frontend/src/components/Layout/InnovenergyTextfield.tsx similarity index 96% rename from typescript/Frontend/src/components/InnovenergyTextfield.tsx rename to typescript/Frontend/src/components/Layout/InnovenergyTextfield.tsx index 0bcd5b57e..055cadd0c 100644 --- a/typescript/Frontend/src/components/InnovenergyTextfield.tsx +++ b/typescript/Frontend/src/components/Layout/InnovenergyTextfield.tsx @@ -1,38 +1,38 @@ -import { Grid, InputLabel, TextField } from "@mui/material"; - -interface I_InnovenergyTextfieldProps { - id: string; - label: string; - value: string; - name: string; - handleChange: (e: React.ChangeEvent) => void; - type?: string; - readOnly?: boolean; -} - -const InnovenergyTextfield = (props: I_InnovenergyTextfieldProps) => { - return ( - - - {props.label} - - - - - - ); -}; - -export default InnovenergyTextfield; +import { Grid, InputLabel, TextField } from "@mui/material"; + +interface I_InnovenergyTextfieldProps { + id: string; + label: string; + value: string; + name: string; + handleChange: (e: React.ChangeEvent) => void; + type?: string; + readOnly?: boolean; +} + +const InnovenergyTextfield = (props: I_InnovenergyTextfieldProps) => { + return ( + + + {props.label} + + + + + + ); +}; + +export default InnovenergyTextfield; diff --git a/typescript/Frontend/src/components/LanguageSelect.tsx b/typescript/Frontend/src/components/Layout/LanguageSelect.tsx similarity index 100% rename from typescript/Frontend/src/components/LanguageSelect.tsx rename to typescript/Frontend/src/components/Layout/LanguageSelect.tsx diff --git a/typescript/Frontend/src/components/LogoutButton.tsx b/typescript/Frontend/src/components/Layout/LogoutButton.tsx similarity index 92% rename from typescript/Frontend/src/components/LogoutButton.tsx rename to typescript/Frontend/src/components/Layout/LogoutButton.tsx index fe773519e..bb1ab45ad 100644 --- a/typescript/Frontend/src/components/LogoutButton.tsx +++ b/typescript/Frontend/src/components/Layout/LogoutButton.tsx @@ -1,7 +1,7 @@ import { Button } from "@mui/material"; import { FormattedMessage } from "react-intl"; -import axiosConfig from "../config/axiosConfig"; import { useNavigate } from "react-router-dom"; +import axiosConfig from "../../config/axiosConfig"; interface LogoutButtonProps { removeToken: () => void; diff --git a/typescript/Frontend/src/components/NavigationButtons.tsx b/typescript/Frontend/src/components/Layout/NavigationButtons.tsx similarity index 80% rename from typescript/Frontend/src/components/NavigationButtons.tsx rename to typescript/Frontend/src/components/Layout/NavigationButtons.tsx index 0283785e2..66c53a8e8 100644 --- a/typescript/Frontend/src/components/NavigationButtons.tsx +++ b/typescript/Frontend/src/components/Layout/NavigationButtons.tsx @@ -1,8 +1,8 @@ import { ToggleButton, ToggleButtonGroup } from "@mui/material"; import { FormattedMessage } from "react-intl"; import { Link } from "react-router-dom"; -import useRouteMatch from "../hooks/useRouteMatch"; -import routes from "../routes.json"; +import useRouteMatch from "../../hooks/useRouteMatch"; +import routes from "../../routes.json"; const NavigationButtons = () => { const routeMatch = useRouteMatch([ @@ -27,7 +27,11 @@ const NavigationButtons = () => { defaultMessage="All installations" /> - + diff --git a/typescript/Frontend/src/components/Sidebar.tsx b/typescript/Frontend/src/components/Layout/Sidebar.tsx similarity index 90% rename from typescript/Frontend/src/components/Sidebar.tsx rename to typescript/Frontend/src/components/Layout/Sidebar.tsx index 00d97c9a3..35c666f54 100644 --- a/typescript/Frontend/src/components/Sidebar.tsx +++ b/typescript/Frontend/src/components/Layout/Sidebar.tsx @@ -1,7 +1,7 @@ import { TextField } from "@mui/material"; import { useState } from "react"; import { useIntl } from "react-intl"; -import InstallationList from "./InstallationList"; +import InstallationList from "../Installations/InstallationList"; const Sidebar = () => { const [searchQuery, setSearchQuery] = useState(""); diff --git a/typescript/Frontend/src/components/Table.tsx b/typescript/Frontend/src/components/Layout/Table.tsx similarity index 96% rename from typescript/Frontend/src/components/Table.tsx rename to typescript/Frontend/src/components/Layout/Table.tsx index c454f0989..1c458b997 100644 --- a/typescript/Frontend/src/components/Table.tsx +++ b/typescript/Frontend/src/components/Layout/Table.tsx @@ -1,65 +1,65 @@ -import * as React from "react"; -import Table from "@mui/material/Table"; -import TableBody from "@mui/material/TableBody"; -import TableCell from "@mui/material/TableCell"; -import TableContainer from "@mui/material/TableContainer"; -import TableHead from "@mui/material/TableHead"; -import TableRow from "@mui/material/TableRow"; -import Paper from "@mui/material/Paper"; - -const rows = [ - { - device: "48TL200", - code: "MSWE", - message: "Main switch error", - severity: "Alarm", - }, - { - device: "48TL200", - code: "MSWE", - message: "Main switch error", - severity: "Alarm", - }, - { - device: "48TL200", - code: "MSWE", - message: "Main switch error", - severity: "Alarm", - }, - { - device: "48TL200", - code: "MSWE", - message: "Main switch error", - severity: "Alarm", - }, -]; -const BasicTable = () => { - return ( - - - - - Device - Code - Message - Severity - - - - {rows.map((row, i) => ( - - {row.device} - {row.code} - {row.message} - {row.severity} - - ))} - -
-
- ); -}; - -export default BasicTable; +import * as React from "react"; +import Table from "@mui/material/Table"; +import TableBody from "@mui/material/TableBody"; +import TableCell from "@mui/material/TableCell"; +import TableContainer from "@mui/material/TableContainer"; +import TableHead from "@mui/material/TableHead"; +import TableRow from "@mui/material/TableRow"; +import Paper from "@mui/material/Paper"; + +const rows = [ + { + device: "48TL200", + code: "MSWE", + message: "Main switch error", + severity: "Alarm", + }, + { + device: "48TL200", + code: "MSWE", + message: "Main switch error", + severity: "Alarm", + }, + { + device: "48TL200", + code: "MSWE", + message: "Main switch error", + severity: "Alarm", + }, + { + device: "48TL200", + code: "MSWE", + message: "Main switch error", + severity: "Alarm", + }, +]; +const BasicTable = () => { + return ( + + + + + Device + Code + Message + Severity + + + + {rows.map((row, i) => ( + + {row.device} + {row.code} + {row.message} + {row.severity} + + ))} + +
+
+ ); +}; + +export default BasicTable; diff --git a/typescript/Frontend/src/components/Navigation.scss b/typescript/Frontend/src/components/Navigation.scss deleted file mode 100644 index 75963a6b1..000000000 --- a/typescript/Frontend/src/components/Navigation.scss +++ /dev/null @@ -1,3 +0,0 @@ -.link { - text-decoration: none; -} \ No newline at end of file diff --git a/typescript/Frontend/src/components/Navigation.tsx b/typescript/Frontend/src/components/Navigation.tsx deleted file mode 100644 index 0ab872342..000000000 --- a/typescript/Frontend/src/components/Navigation.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import AppBar from '@mui/material/AppBar'; -import Toolbar from '@mui/material/Toolbar'; -import { Link } from 'react-router-dom'; - - -function Navigation() { - return ( - - - All installations - Users - - - ); -} -export default Navigation;