Added a button to start a new scan

This commit is contained in:
Henry Whitaker
2020-04-08 19:24:45 +01:00
parent c2c418947c
commit bff43c205c
3 changed files with 101 additions and 9 deletions

56
public/js/app.js vendored
View File

@@ -126741,6 +126741,15 @@ var HistoryGraph = /*#__PURE__*/function (_Component) {
title: {
display: false,
text: 'Speedtests results for the last ' + days + ' days'
},
scales: {
xAxes: [{
display: false,
scaleLabel: {
display: true,
labelString: 'DateTime'
}
}]
}
};
var pingData = {
@@ -126763,6 +126772,15 @@ var HistoryGraph = /*#__PURE__*/function (_Component) {
title: {
display: false,
text: 'Ping results for the last ' + days + ' days'
},
scales: {
xAxes: [{
display: false,
scaleLabel: {
display: true,
labelString: 'DateTime'
}
}]
}
};
resp.data.data.forEach(function (e) {
@@ -126781,8 +126799,8 @@ var HistoryGraph = /*#__PURE__*/function (_Component) {
duData.datasets[0].data.push(download);
duData.datasets[1].data.push(upload);
pingData.datasets[0].data.push(ping);
duData.labels.push(new Date(e.created_at).toLocaleString());
pingData.labels.push(new Date(e.created_at).toLocaleString());
duData.labels.push(new Date(e.created_at).toLocaleDateString());
pingData.labels.push(new Date(e.created_at).toLocaleDateString());
});
_this.setState({
@@ -126845,7 +126863,7 @@ var HistoryGraph = /*#__PURE__*/function (_Component) {
}));
} else {
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_3__["Container"], {
className: "my-4",
className: "mb-4 mt-3",
fluid: true
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_3__["Row"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_3__["Col"], {
sm: {
@@ -126938,6 +126956,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _Widget__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Widget */ "./resources/js/components/Graphics/Widget.js");
/* harmony import */ var react_bootstrap__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! react-bootstrap */ "./node_modules/react-bootstrap/esm/index.js");
/* harmony import */ var react_toastify__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! react-toastify */ "./node_modules/react-toastify/esm/react-toastify.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -126969,6 +126988,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
var LatestResults = /*#__PURE__*/function (_Component) {
_inherits(LatestResults, _Component);
@@ -127003,6 +127024,23 @@ var LatestResults = /*#__PURE__*/function (_Component) {
});
});
_defineProperty(_assertThisInitialized(_this), "newScan", function () {
var url = '/api/speedtest/run?token=' + _this.state.token.access_token;
axios__WEBPACK_IMPORTED_MODULE_2___default.a.get(url).then(function (resp) {
react_toastify__WEBPACK_IMPORTED_MODULE_5__["toast"].info('A scan has been queued. This page will refresh when the scan has finished.');
})["catch"](function (err) {
if (err.response) {
if (err.response.status == 429) {
react_toastify__WEBPACK_IMPORTED_MODULE_5__["toast"].error('You are doing that too much. Try again later.');
}
console.log(err.response);
} else {
console.log(err.data);
}
});
});
_this.state = {
token: _this.props.token,
data: {},
@@ -127089,10 +127127,18 @@ var LatestResults = /*#__PURE__*/function (_Component) {
sm: {
span: 12
},
className: "text-center"
className: "text-center mb-2"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("p", {
className: "text-muted mb-0"
}, "Last scan performed at: ", new Date(data.data.created_at).toLocaleString()))));
}, "Last scan performed at: ", new Date(data.data.created_at).toLocaleString()))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_4__["Row"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_4__["Col"], {
sm: {
span: 12
},
className: "text-center"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_4__["Button"], {
variant: "primary",
onClick: this.newScan
}, "Scan again")))));
}
}
}]);

View File

@@ -62,6 +62,15 @@ export default class HistoryGraph extends Component {
display: false,
text: 'Speedtests results for the last ' + days + ' days',
},
scales: {
xAxes: [{
display: false,
scaleLabel: {
display: true,
labelString: 'DateTime'
}
}],
},
};
var pingData = {
@@ -85,6 +94,15 @@ export default class HistoryGraph extends Component {
display: false,
text: 'Ping results for the last ' + days + ' days',
},
scales: {
xAxes: [{
display: false,
scaleLabel: {
display: true,
labelString: 'DateTime'
}
}],
},
}
resp.data.data.forEach(e => {
@@ -103,8 +121,8 @@ export default class HistoryGraph extends Component {
duData.datasets[0].data.push(download);
duData.datasets[1].data.push(upload);
pingData.datasets[0].data.push(ping);
duData.labels.push(new Date(e.created_at).toLocaleString());
pingData.labels.push(new Date(e.created_at).toLocaleString());
duData.labels.push(new Date(e.created_at).toLocaleDateString());
pingData.labels.push(new Date(e.created_at).toLocaleDateString());
});
this.setState({
@@ -150,7 +168,7 @@ export default class HistoryGraph extends Component {
)
} else {
return (
<Container className="my-4" fluid>
<Container className="mb-4 mt-3" fluid>
<Row>
<Col sm={{ span: 12 }}>
<div className="text-center">

View File

@@ -4,6 +4,8 @@ import Axios from 'axios';
import Widget from './Widget';
import { Container, Row, Spinner } from 'react-bootstrap';
import { Col } from 'react-bootstrap';
import { Button } from 'react-bootstrap';
import { toast } from 'react-toastify';
export default class LatestResults extends Component {
constructor(props) {
@@ -40,6 +42,25 @@ export default class LatestResults extends Component {
})
}
newScan = () => {
var url = '/api/speedtest/run?token=' + this.state.token.access_token;
Axios.get(url)
.then((resp) => {
toast.info('A scan has been queued. This page will refresh when the scan has finished.');
})
.catch((err) => {
if(err.response) {
if(err.response.status == 429) {
toast.error('You are doing that too much. Try again later.');
}
console.log(err.response);
} else {
console.log(err.data);
}
})
}
render() {
var loading = this.state.loading;
var data = this.state.data;
@@ -104,10 +125,17 @@ export default class LatestResults extends Component {
</Col>
</Row>
<Row>
<Col sm={{ span: 12 }} className="text-center">
<Col sm={{ span: 12 }} className="text-center mb-2">
<p className="text-muted mb-0">Last scan performed at: {new Date(data.data.created_at).toLocaleString()}</p>
</Col>
</Row>
<Row>
<Col sm={{ span: 12 }} className="text-center">
<div>
<Button variant="primary" onClick={this.newScan}>Scan again</Button>
</div>
</Col>
</Row>
</Container>
);
}