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

Handled YAML Errors for dashboard #20

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f376756
Added sort by key feature in WiFi tab and Improved UI in WiFi tab
hanupratap Mar 17, 2021
d1ee1ca
Highlighted row and added active dot for connected network. Removed u…
hanupratap Mar 18, 2021
433147f
Added Chips for WPA, Updated dependecies, cleaned code
hanupratap Mar 19, 2021
4b06a8e
Added camer load graph
hanupratap Mar 21, 2021
e128d87
Minor UI Changes and code improvement
hanupratap Mar 21, 2021
2bd325f
Minor function name changes
hanupratap Mar 22, 2021
d17e912
Changed graph library to ApexCharts
hanupratap Mar 23, 2021
59d1f6e
graph update
hanupratap Mar 23, 2021
9ad8da4
Added bars icon
hanupratap Mar 23, 2021
8a7d92b
formatted code
hanupratap Mar 23, 2021
317f1e6
Refactored command and graph widget
hanupratap Mar 25, 2021
5b94db9
Fixed graph reset on re-render
hanupratap Mar 25, 2021
f8fe2be
Formatted Code
hanupratap Mar 25, 2021
463328d
Removed ticks and added loading text for no data
hanupratap Mar 26, 2021
7512d10
Changed case for setstate
hanupratap Mar 26, 2021
9afde1a
added showGraph in rebuild list
hanupratap Mar 26, 2021
e359728
Added CanvasJs Charts
hanupratap Mar 27, 2021
eb839ff
Changed lib to chartjs, removed unnecessary libs and files, formatted…
hanupratap Mar 29, 2021
7124ed4
minor improvements
hanupratap Mar 29, 2021
9c4fe9f
minor performance improvement
hanupratap Mar 29, 2021
2ff76b7
Fixed color in tooltip
hanupratap Mar 29, 2021
dd257e0
chartjs replaced with Dygraph charts
hanupratap Mar 30, 2021
04b462d
Graph autoscale x-direction
hanupratap Mar 31, 2021
a0b7b3e
Added open source animation
hanupratap Mar 31, 2021
13308ee
code format
hanupratap Mar 31, 2021
c435618
Added apertus animation
hanupratap Mar 31, 2021
3777914
changed tooltip position, removed hardcoded theme
hanupratap Apr 4, 2021
dfa8512
format code
hanupratap Apr 4, 2021
ddbf771
added accordion on sys-info, improved performanec
hanupratap Apr 4, 2021
8c9ecc8
format code
hanupratap Apr 4, 2021
0685002
small change in accordion
hanupratap Apr 4, 2021
8cc9a8c
added dark mode
hanupratap Apr 7, 2021
efb28fb
color highlight fix
hanupratap Apr 7, 2021
5595900
Handled YAML errors
hanupratap Apr 9, 2021
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
11 changes: 10 additions & 1 deletion frontend/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import MenuIcon from '@material-ui/icons/Menu';
import { useState } from 'react';
import clsx from 'clsx';
import { isDesktop } from './util/isDesktop';
import Brightness4Icon from '@material-ui/icons/Brightness4';
import Brightness7Icon from '@material-ui/icons/Brightness7';

const drawerWidth = 240;
const useStyles = makeStyles(theme => ({
Expand All @@ -25,6 +27,7 @@ const useStyles = makeStyles(theme => ({
backgroundColor: theme.palette.background.default,
width: '100vw',
minHeight: '100vh',
flexGrow: 1,
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
Expand Down Expand Up @@ -57,6 +60,9 @@ const useStyles = makeStyles(theme => ({
marginLeft: 0,
},
toolbar: theme.mixins.toolbar,
title: {
flexGrow: 1,
},
}));

export function App(props) {
Expand All @@ -77,7 +83,7 @@ export function App(props) {
<MenuIcon />
</IconButton>

<Typography variant="h6" noWrap>
<Typography variant="h6" noWrap className={classes.title}>
{process.env.MOCK ? 'Mock' : ''} AXIOM WebUi -&nbsp;
<Switch>
{Object.values(routes).map(({ route, title }) => (
Expand All @@ -87,6 +93,9 @@ export function App(props) {
))}
</Switch>
</Typography>
<IconButton aria-label="dark" onClick={props.changeTheme}>
{props.isDark ? <Brightness7Icon /> : <Brightness4Icon />}
</IconButton>
</Toolbar>
</AppBar>

Expand Down
28 changes: 28 additions & 0 deletions frontend/Themer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useState } from 'react';
import { createMuiTheme } from '@material-ui/core';
import { green } from '@material-ui/core/colors';
import { ThemeProvider } from '@material-ui/core/styles';
import { App } from './App';

export default function Themer() {
const [isDark, setDark] = useState(false);
function changeTheme() {
setDark(!isDark);
}
const theme = createMuiTheme({
palette: {
primary: {
main: '#FA8756',
contrastText: '#ffffff',
},
secondary: green,
type: isDark ? 'dark' : 'light',
},
});

return (
<ThemeProvider theme={theme}>
<App isDark={isDark} changeTheme={changeTheme} />
</ThemeProvider>
);
}
2 changes: 1 addition & 1 deletion frontend/components/CommandWidgets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { exec } from '../util/exec';

export function Command(props) {
return (
<pre style={{ backgroundColor: '#eee', overflowX: 'auto' }}>
<pre style={{ overflowX: 'auto' }}>
$ {props.command} {`\n`} <PlainCommand {...props} />
</pre>
);
Expand Down
92 changes: 92 additions & 0 deletions frontend/components/LoadGraph.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useEffect, useRef } from 'react';
import Dygraph from 'dygraphs';
import { Container, makeStyles, Paper } from '@material-ui/core';
import { blue, green, red } from '@material-ui/core/colors';
import { Alert } from '@material-ui/lab';

const update_interval = 1000;
const command = 'uptime';
const chart_title = 'Load averages';

const chart_config = {
legend: 'always',
labelsSeparateLines: true,
colors: [red.A200, green.A200, blue.A200],
strokeWidth: 1.5,
xlabel: 'Time',
xLabelHeight: 16,
title: chart_title,
};

const useStyles = makeStyles(theme => ({
chart_paper: {
height: '350px',
margin: theme.spacing(2),
padding: theme.spacing(2),
},
chart: {
width: '100%',
height: '100%',
},
box_wrapper: {
width: '100%',
marginBottom: theme.spacing(4),
fontFamily: theme.typography.fontFamily,
},
tooltip: {
margin: theme.spacing(2),
padding: theme.spacing(2),
},
}));

let data = 'date, 1 minute, 5 minute, 15 minute\n';
let chart = null;

export default function LoadGraph(props) {
const chartRef = useRef();
const tooltip_ref = useRef();
const classes = useStyles();

function addData(str = '') {
if (str.length == 0) return;
const list = str.split('load average: ');
data += `${new Date()}, ${list[1].trim()}\n`;
const row = chart.getSelection();
chart.updateOptions({ file: data });
chart.setSelection(row);
}

useEffect(() => {
chart = new Dygraph(chartRef.current, data, {
...chart_config,
labelsDiv: tooltip_ref.current,
});

const callback = () =>
exec(command)
.then(result => {
addData(result[0]);
})
.catch(err => {
<Alert severity="error">{err[1]}</Alert>;
console.log(err[1]);
});
const interval_handle = setInterval(
callback,
props.interval ? props.interval : update_interval
);
callback();
return () => clearInterval(interval_handle);
}, []);

return (
<Container className={classes.box_wrapper}>
<Paper className={classes.chart_paper} variant="outlined">
<div ref={chartRef} className={classes.chart} />
</Paper>
<Paper className={classes.tooltip} variant="outlined">
<div ref={tooltip_ref} />
</Paper>
</Container>
);
}
20 changes: 2 additions & 18 deletions frontend/index.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { App } from './App';
import Themer from './Themer';
import { HashRouter as Router } from 'react-router-dom';
import { createMuiTheme } from '@material-ui/core';
import { amber, green } from '@material-ui/core/colors';
import { ThemeProvider } from '@material-ui/core/styles';

const theme = createMuiTheme({
palette: {
primary: {
main: '#FA8756',
contrastText: 'white',
},
secondary: green,
},
});

ReactDOM.render(
<Router>
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
<Themer />
</Router>,
document.getElementById('root')
);
119 changes: 91 additions & 28 deletions frontend/routes/Dashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import {
Box,
Button,
Dialog,
DialogActions,
Expand All @@ -19,7 +20,11 @@ import { usePromiseGenerator } from '../util/usePromiseGenerator';
import { NctrlValueWidgets } from '../components/*.jsx';
import Typography from '@material-ui/core/Typography';
import { NCTRL_BASE_PATH } from '../util/nctrl';
import { Player } from '@lottiefiles/react-lottie-player';
import { classicNameResolver } from 'typescript';

const apertus_animation = require('../util/animations/aperture.json');
const yaml_error = require('../util/animations/error.json');
export const title = 'Dashboard';
export const route = '/dashboard';
export const explanation = `
Expand All @@ -35,6 +40,25 @@ const useStyles = makeStyles(theme => ({
right: 0,
margin: '50px',
},
error_message: {
padding: theme.spacing(2),
},
error_wrapper: {
textAlign: 'left',
width: '100%',
},
error_player: {
height: '10px',
width: '10px',
alignItems: 'center',
display: 'flex',
},
load_player: {
height: '10px',
width: '10px',
alignItems: 'center',
display: 'flex',
},
ul: {
listStyle: 'none',
padding: 0,
Expand Down Expand Up @@ -62,13 +86,13 @@ export function Component(props) {
}
}, [file_yml]);

const parsed = useYaml(yaml) || [];
const parsed = useYaml(yaml);

const [rerenderDep, setRerenderDep] = useState(0);
const rerender = () => setRerenderDep(rerenderDep + 1);

return (
<div>
<Box>
{
<EditDashboard
current_yml={yaml}
Expand All @@ -79,32 +103,62 @@ export function Component(props) {
/>
}
<div className={classes.ul}>
{Object.keys(parsed).map((heading, i) => {
return (
<div className={classes.notWide} key={i}>
<Typography variant="h6">{heading}:</Typography>
<Paper className={classes.paper}>
{parsed[heading].map((x, i) => {
const InputWidget =
NctrlValueWidgets[
`NctrlValue${x.widget.replace(/^(.)/, v => v.toUpperCase())}`
];
return (
<InputWidget
key={i}
rerender={rerender}
rerenderDep={rerenderDep}
{...x}
path={`${NCTRL_BASE_PATH}${x.path}`}
/>
);
})}
</Paper>
</div>
);
})}
{!parsed ? (
<Player
src={apertus_animation}
autoplay={true}
loop={true}
controls={false}
style={{ height: '500px', width: '500px', alignItems: 'center', display: 'flex' }}
speed={3}
/>
) : parsed.error_message ? (
<div className={classes.error_wrapper}>
<Player
src={yaml_error}
autoplay={true}
loop={true}
controls={false}
style={{ height: '200px', width: '200px', alignItems: 'center', display: 'flex' }}
/>
<Typography color="error" className={classes.error_message}>
An Error has Occured : <br />
<br />
<b>Name</b> : {parsed.error_name} <br />
<br />
<b>Message</b> : {parsed.error_message} <br />
<br />
<b>Stack</b> : {parsed.error_stack}
</Typography>
</div>
) : (
Object.keys(parsed).map((heading, i) => {
return (
<div className={classes.notWide} key={i}>
<Typography variant="h6">{heading}:</Typography>
<Paper className={classes.paper}>
{parsed[heading].map((x, i) => {
const InputWidget =
NctrlValueWidgets[
`NctrlValue${x.widget.replace(/^(.)/, v => v.toUpperCase())}`
];
return (
<InputWidget
key={i}
rerender={rerender}
rerenderDep={rerenderDep}
{...x}
path={`${NCTRL_BASE_PATH}${x.path}`}
/>
);
})}
</Paper>
</div>
);
})
)}
</div>
</div>
</Box>
);
}

Expand Down Expand Up @@ -166,7 +220,16 @@ function EditDashboard({ current_yml: currentYaml, setYaml }) {
function useYaml(yamlString) {
const [deserialized, setDeserialized] = useState(null);
useEffect(() => {
setDeserialized(safeLoad(yamlString));
try {
setDeserialized(safeLoad(yamlString));
} catch (error) {
console.log(error);
return setDeserialized({
error_name: error.name,
error_message: error.message,
error_stack: error.stack,
});
}
}, [yamlString]);
return deserialized;
}
Expand Down
Loading