Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 1 and Task 2 of GSOC'21 WebUI challenge completed #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function App(props) {
const classes = useStyles();

const [drawerOpen, setDrawerOpen] = useState(isDesktop);

console.log(props.theme.palette.primary.main);
MANSHALAMBA marked this conversation as resolved.
Show resolved Hide resolved
return (
<div className={classes.root}>
<AppBar position="fixed" className={classes.appBar}>
Expand Down Expand Up @@ -119,6 +119,7 @@ export function App(props) {
})}
>
<div className={classes.toolbar} />

<Switch>
{Object.values(routes).map(({ route, Component }) => (
<Route exact path={route} key={route} component={Component} />
Expand Down
53 changes: 53 additions & 0 deletions frontend/components/CameraLoadWidget.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { useEffect, useState } from 'react';

import { exec } from '../util/exec';

import Chart from 'react-google-charts';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package seems to load a script from the internet, unfortunately this doesn't really work for this application, as this site has to work without internet access.


const CameraLoadWidget = props => {
const [load, setLoad] = useState([
['Time Lapsed(In seconds)', '1 minute avg', '5 minute avg', '15 minute avg'],
[0, 0, 0, 0],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these makes all of the graphs start from zero, even if the load never was zero.

]);
useEffect(() => {
rroohhh marked this conversation as resolved.
Show resolved Hide resolved
let intervalId = setInterval(function a() {
exec('uptime').then(result => {
let splitres = String(result)
.trim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this first trim necessary?

.split('load average:')[1]
.trim()
.split(',');

setLoad(oldLoad => {
let loadArr = [
[
oldLoad[oldLoad.length - 1][0] + 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use the actual time as included from the uptime output, if for some reason some of the requests get stalled and are then completed all at once.

splitres[0].trim(),
splitres[1].trim(),
splitres[2].trim(),
],
];
return oldLoad.concat(loadArr);
});
});
}, 1000);

return () => {
clearInterval(intervalId);
};
}, []);

return (
<p>
<Chart
height={'400px'}
chartType="Line"
loader={<div>Loading Chart</div>}
data={load}
rootProps={{ 'data-testid': '2' }}
MANSHALAMBA marked this conversation as resolved.
Show resolved Hide resolved
/>
</p>
);
};

export default CameraLoadWidget;
25 changes: 13 additions & 12 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>AXIOM-web</title>
</head>

</head>

<body style="margin: 0; padding: 0; overflow-x: hidden;">
<div id="root"></div>
<script src="index.jsx"></script>
</body>

</html>
<body style="margin: 0; padding: 0; overflow-x: hidden;">
<div id="root"></div>
<script src="index.jsx"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions frontend/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const theme = createMuiTheme({
palette: {
primary: {
main: '#FA8756',
contrastText: 'white',
contrastText: '#FFFFFF',
},
secondary: green,
},
Expand All @@ -19,7 +19,7 @@ const theme = createMuiTheme({
ReactDOM.render(
<Router>
<ThemeProvider theme={theme}>
<App />
<App theme={theme} />
</ThemeProvider>
</Router>,
document.getElementById('root')
Expand Down
60 changes: 60 additions & 0 deletions frontend/routes/SystemInformation.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,74 @@
import * as React from 'react';
import { useState } from 'react';

import CameraIcon from '@material-ui/icons/Camera';
import CancelPresentationIcon from '@material-ui/icons/CancelPresentation';

import Button from '@material-ui/core/Button';
import Modal from '@material-ui/core/Modal';
import Typography from '@material-ui/core/Typography';

import { Command } from '../components/CommandWidgets';
import CameraLoadWidget from '../components/CameraLoadWidget.jsx';

export const title = 'System Information';
export const route = '/system_information';
export const explanation = `Get an overview of whats going on in the linux side of your camera.
Ip address, system load, etc can be found here`;

export function Component(props) {
const [modalOpen, setmodalOpen] = useState(false);
MANSHALAMBA marked this conversation as resolved.
Show resolved Hide resolved

return (
<div>
<Modal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason for making this a modal popup?

If not embedding the chart directly on the system configuration page seems better.

open={modalOpen}
onClose={() => {
setmodalOpen(false);
}}
aria-labelledby="simple-modal-title"
aria-describedby="simple-modal-description"
>
<div
style={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
overflow: 'scroll',
width: 600,
backgroundColor: 'white',
border: '1px solid black',
padding: '20px',
}}
>
<Typography variant="h5" align="center">
Camera Load Graph
<Button
style={{ float: 'right' }}
onClick={() => {
setmodalOpen(false);
}}
>
<CancelPresentationIcon />
</Button>
</Typography>
<CameraLoadWidget />
</div>
</Modal>
<Button
variant="contained"
color="primary"
endIcon={<CameraIcon />}
onClick={() => {
setmodalOpen(true);
}}
style={{ float: 'right', margin: '15px' }}
>
Camera Load
</Button>
<br />
<br />
<Command command="date" interval={1000} />
<Command command="uptime" interval={1000} />
<Command command="free -h" interval={1000} />
Expand Down
134 changes: 105 additions & 29 deletions frontend/routes/Wifi.jsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,129 @@
import * as React from 'react';
import { forwardRef } from 'react';
import MaterialTable from 'material-table';
import AddBox from '@material-ui/icons/AddBox';
import ArrowDownward from '@material-ui/icons/ArrowDownward';
import Check from '@material-ui/icons/Check';
import ChevronLeft from '@material-ui/icons/ChevronLeft';
import ChevronRight from '@material-ui/icons/ChevronRight';
import Clear from '@material-ui/icons/Clear';
import DeleteOutline from '@material-ui/icons/DeleteOutline';
import Edit from '@material-ui/icons/Edit';
import FilterList from '@material-ui/icons/FilterList';
import FirstPage from '@material-ui/icons/FirstPage';
import LastPage from '@material-ui/icons/LastPage';
import Remove from '@material-ui/icons/Remove';
import SaveAlt from '@material-ui/icons/SaveAlt';
import Search from '@material-ui/icons/Search';
import ViewColumn from '@material-ui/icons/ViewColumn';
import { withTheme } from '@material-ui/core/styles';
import Chip from '@material-ui/core/Chip';
import Typography from '@material-ui/core/Typography';
import { exec_table, exec } from '../util/exec';

export const title = 'Wifi Configuration';
export const route = '/wifi';

export class Component extends React.Component {
const tableIcons = {
Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />),
Check: forwardRef((props, ref) => <Check {...props} ref={ref} />),
Clear: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
Delete: forwardRef((props, ref) => <DeleteOutline {...props} ref={ref} />),
DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
Edit: forwardRef((props, ref) => <Edit {...props} ref={ref} />),
Export: forwardRef((props, ref) => <SaveAlt {...props} ref={ref} />),
Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />),
FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />),
ThirdStateCheck: forwardRef((props, ref) => <Remove {...props} ref={ref} />),
ViewColumn: forwardRef((props, ref) => <ViewColumn {...props} ref={ref} />),
};

class ComponentRaw extends React.Component {
constructor(props) {
super(props);

this.state = {
wifi_networks: [],
last_refresh: '',
};
setInterval(() => {
exec_table('nmcli dev wifi').then(result => this.setState({ wifi_networks: result }));
this.id = setInterval(() => {
exec_table('nmcli device wifi list').then(result => this.setState({ wifi_networks: result }));
exec('date').then(result => this.setState({ last_refresh: result }));
}, 1000);
}

componentWillUnmount() {
clearInterval(this.id);
}

render() {
return (
<div>
<Table data={this.state.wifi_networks} />
<div style={{ padding: '40px' }}>
{this.state.wifi_networks.length == 0 ? (
<Typography variant="h2" color="textSecondary">
No wifi networks available
</Typography>
) : (
<MaterialTable
icons={tableIcons}
columns={[
{
title: 'SSID',
field: 'SSID',
render: rowData => {
if (rowData['IN-USE'] != '') {
return <p style={{ color: '#ec0101' }}>{rowData.SSID}</p>;
} else {
return <p>{rowData.SSID}</p>;
}
},
sorting: true,
defaultSort: 'asc',
},
{
title: 'SIGNAL',
field: 'SIGNAL',
type: 'numeric',
sorting: true,
defaultSort: 'asc',
},
{
title: 'SECURITY',
field: 'SECURITY',
sorting: false,
render: rowData => {
return rowData['SECURITY'].split(' ').map(tag => {
return (
<Chip key={tag} label={tag} variant="outlined" style={{ margin: '2px' }} />
);
});
},
},

{ title: 'MODE', field: 'MODE', sorting: true, defaultSort: 'asc' },
{ title: 'CHAN', field: 'CHAN', type: 'numeric', defaultSort: 'asc', sorting: true },
{ title: 'RATE', field: 'RATE', sorting: true, defaultSort: 'asc' },
]}
data={[...this.state.wifi_networks]}
MANSHALAMBA marked this conversation as resolved.
Show resolved Hide resolved
options={{
headerStyle: {
backgroundColor: this.props.theme.palette.primary.main,
color: '#FFF',
},
emptyRowsWhenPaging: false,
}}
title="Wifi Networks"
/>
)}
</div>
);
}
}

function Table(props) {
const { data } = props;
if (data.length === 0) return <table />;
return (
<table>
<thead>
<tr>
{Object.keys(data[0]).map(s => (
<th key={s}>{s}</th>
))}
</tr>
</thead>
<tbody>
{data.map((row, i) => (
<tr key={i}>
{Object.values(row).map((s, i) => (
<td key={i}>{s}</td>
))}
</tr>
))}
</tbody>
</table>
);
}
export const Component = withTheme(ComponentRaw);
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"last 10 Firefox versions"
],
"dependencies": {
"@material-table/core": "^2.3.28",
"express": "~4.17.1",
"material-table": "^1.69.2",
"react-google-charts": "^3.0.15",
"socketio": "^1.0.0"
},
"devDependencies": {
Expand Down
Loading