diff --git a/csharp/App/Backend/Controller.cs b/csharp/App/Backend/Controller.cs index 2550edd40..3755d0146 100644 --- a/csharp/App/Backend/Controller.cs +++ b/csharp/App/Backend/Controller.cs @@ -514,18 +514,16 @@ public class Controller : ControllerBase } [HttpPost(nameof(UpdateFirmware))] - public ActionResult UpdateFirmware(Int64 batteryNode, Int64 installationId,Token authToken) + public async Task UpdateFirmware(Int64 batteryNode, Int64 installationId,Token authToken) { var session = Db.GetSession(authToken); var installationToUpdate = Db.GetInstallationById(installationId); Console.WriteLine("Inside firmware function controller,batteryNode="+batteryNode+ "and installation is "+installationId); -#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed if (installationToUpdate != null) { - session.RunScriptInBackground(installationToUpdate.VpnIp, batteryNode); + _ = session.RunScriptInBackground(installationToUpdate.VpnIp, batteryNode); } -#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return Ok(); } diff --git a/typescript/frontend-marios2/src/content/dashboards/BatteryView/BatteryView.tsx b/typescript/frontend-marios2/src/content/dashboards/BatteryView/BatteryView.tsx index 4139096d5..bf559b6ba 100644 --- a/typescript/frontend-marios2/src/content/dashboards/BatteryView/BatteryView.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/BatteryView/BatteryView.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { Container, Grid, @@ -8,7 +8,8 @@ import { TableCell, TableContainer, TableHead, - TableRow + TableRow, + Typography } from '@mui/material'; import { TopologyValues } from '../Log/graph.util'; import { @@ -24,10 +25,12 @@ import { I_S3Credentials } from '../../../interfaces/S3Types'; import routes from '../../../Resources/routes.json'; import MainStats from './MainStats'; import DetailedBatteryView from './DetailedBatteryView'; +import CircularProgress from '@mui/material/CircularProgress'; interface BatteryViewProps { values: TopologyValues; s3Credentials: I_S3Credentials; + installationId: number; } function BatteryView(props: BatteryViewProps) { @@ -40,6 +43,10 @@ function BatteryView(props: BatteryViewProps) { (a, b) => b.BatteryId - a.BatteryId ); + const [loading, setLoading] = useState( + sortedBatteryView.length == 0 ? true : false + ); + const handleMainStatsButton = () => { navigate(routes.mainstats); }; @@ -52,15 +59,116 @@ function BatteryView(props: BatteryViewProps) { } }; + useEffect(() => { + if (sortedBatteryView.length == 0) { + setLoading(true); + } else { + setLoading(false); + } + }, [sortedBatteryView]); + return ( <> - - - + + + Battery service is not available at the moment + + + Please wait or refresh the page + + + )} + + {!loading && ( + + + + + + + + + + + + + } + /> + {props.values.batteryView.map((battery) => ( + + } + /> + ))} + + + + - - - - - - - - - - } - /> - {props.values.batteryView.map((battery) => ( - - } - /> - ))} - - - - - - - - Battery - Firmware - Power - Voltage - SoC - Temperature - Warnings - Alarms - - - - {sortedBatteryView.map((battery) => ( - - - - {'Node ' + battery.BatteryId} - - - - {battery.FwVersion.value} - - - {battery.Power.value + ' ' + battery.Power.unit} - - 57 - ? '#FF033E' - : '#32CD32', - color: battery.Voltage.value === '' ? 'white' : 'inherit' - }} - > - {battery.Voltage.value + ' ' + battery.Voltage.unit} - - - {battery.Soc.value + ' ' + battery.Soc.unit} - - 270 - ? '#FF033E' - : '#32CD32 ' - }} - > - {battery.AverageTemperature.value + - ' ' + - battery.AverageTemperature.unit} - - - - {battery.Warnings.value === '' ? ( - 'None' - ) : battery.Warnings.value.toString().split('-').length > - 1 ? ( - - Multiple Warnings - - ) : ( - battery.Warnings.value - )} - - - {battery.Alarms.value === '' ? ( - 'None' - ) : battery.Alarms.value.toString().split('-').length > - 1 ? ( - - Multiple Alarms - - ) : ( - battery.Alarms.value - )} - +
+ + + Battery + Firmware + Power + Voltage + SoC + Temperature + Warnings + Alarms - ))} - -
-
-
+ + + {sortedBatteryView.map((battery) => ( + + + + {'Node ' + battery.BatteryId} + + + + {battery.FwVersion.value} + + + {battery.Power.value + ' ' + battery.Power.unit} + + 57 + ? '#FF033E' + : '#32CD32', + color: + battery.Voltage.value === '' ? 'white' : 'inherit' + }} + > + {battery.Voltage.value + ' ' + battery.Voltage.unit} + + + {battery.Soc.value + ' ' + battery.Soc.unit} + + 270 + ? '#FF033E' + : '#32CD32 ' + }} + > + {battery.AverageTemperature.value + + ' ' + + battery.AverageTemperature.unit} + + + + {battery.Warnings.value === '' ? ( + 'None' + ) : battery.Warnings.value.toString().split('-').length > + 1 ? ( + + Multiple Warnings + + ) : ( + battery.Warnings.value + )} + + + {battery.Alarms.value === '' ? ( + 'None' + ) : battery.Alarms.value.toString().split('-').length > + 1 ? ( + + Multiple Alarms + + ) : ( + battery.Alarms.value + )} + + + ))} + + + + + )} ); } diff --git a/typescript/frontend-marios2/src/content/dashboards/BatteryView/DetailedBatteryView.tsx b/typescript/frontend-marios2/src/content/dashboards/BatteryView/DetailedBatteryView.tsx index 3940a5c3a..808d54d7a 100644 --- a/typescript/frontend-marios2/src/content/dashboards/BatteryView/DetailedBatteryView.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/BatteryView/DetailedBatteryView.tsx @@ -1,8 +1,11 @@ import React, { useEffect, useState } from 'react'; import { I_S3Credentials } from '../../../interfaces/S3Types'; import { + Box, Card, Grid, + IconButton, + Modal, Paper, Table, TableBody, @@ -12,14 +15,16 @@ import { Typography } from '@mui/material'; import { Battery } from '../Log/graph.util'; +import { useNavigate } from 'react-router-dom'; +import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import Button from '@mui/material/Button'; import { FormattedMessage } from 'react-intl'; -import { useNavigate } from 'react-router-dom'; -import routes from '../../../Resources/routes.json'; +import axiosConfig from '../../../Resources/axiosConfig'; interface DetailedBatteryViewProps { s3Credentials: I_S3Credentials; batteryData: Battery; + installationId: number; } function DetailedBatteryView(props: DetailedBatteryViewProps) { @@ -27,16 +32,20 @@ function DetailedBatteryView(props: DetailedBatteryViewProps) { return null; } const navigate = useNavigate(); + const [openModalFirmwareUpdate, setOpenModalFirmwareUpdate] = useState(false); + const [openModalResultFirmwareUpdate, setOpenModalResultFirmwareUpdate] = + useState(false); const handleBatteryViewButton = () => { navigate(location.pathname.split('/').slice(0, -2).join('/')); }; - const handleMainStatsButton = () => { - navigate( - location.pathname.split('/').slice(0, -2).join('/') + - '/' + - routes.mainstats - ); + + const handleUpdateFirmware = () => { + setOpenModalFirmwareUpdate(true); + }; + + const firmwareModalResultHandleOk = () => { + navigate(location.pathname.split('/').slice(0, -2).join('/')); }; const [GreenisBlinking, setGreenisBlinking] = useState( @@ -96,26 +105,177 @@ function DetailedBatteryView(props: DetailedBatteryViewProps) { backgroundColor: '#bfbfbf' }; + const FirmwareModalHandleProceed = async (e) => { + setOpenModalFirmwareUpdate(false); + + const res = await axiosConfig + .post( + `/UpdateFirmware?batteryNode=${props.batteryData.BatteryId.toString()}&installationId=${ + props.installationId + }` + ) + .catch((err) => { + if (err.response) { + // setError(true); + // setLoading(false); + } + }); + + //if (res) { + setOpenModalResultFirmwareUpdate(true); + //} + }; + + const FirmwareModalHandleCancel = () => { + setOpenModalFirmwareUpdate(false); + }; + return ( <> + {openModalResultFirmwareUpdate && ( + + + + The firmware is getting updated. Please wait... + + +
+ +
+
+
+ )} + + {openModalFirmwareUpdate && ( + + + + Do you really want to update the firmware? + + + + This action requires the battery service to be stopped. + + +
+ + +
+
+
+ )} + - + + diff --git a/typescript/frontend-marios2/src/content/dashboards/BatteryView/MainStats.tsx b/typescript/frontend-marios2/src/content/dashboards/BatteryView/MainStats.tsx index d80945f1e..3744c5799 100644 --- a/typescript/frontend-marios2/src/content/dashboards/BatteryView/MainStats.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/BatteryView/MainStats.tsx @@ -1,4 +1,12 @@ -import { Box, Card, Container, Grid, Modal, Typography } from '@mui/material'; +import { + Box, + Card, + Container, + Grid, + IconButton, + Modal, + Typography +} from '@mui/material'; import { FormattedMessage } from 'react-intl'; import React, { useEffect, useState } from 'react'; import { I_S3Credentials } from '../../../interfaces/S3Types'; @@ -16,6 +24,7 @@ import { DateTimePicker, LocalizationProvider } from '@mui/x-date-pickers'; import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; import CircularProgress from '@mui/material/CircularProgress'; import { useLocation, useNavigate } from 'react-router-dom'; +import ArrowBackIcon from '@mui/icons-material/ArrowBack'; interface MainStatsProps { s3Credentials: I_S3Credentials; @@ -384,31 +393,18 @@ function MainStats(props: MainStatsProps) { {!loading && ( <> - - - + +