//
// PTP.jsx
//
// Copyright (c) 2019 2020 Andrea Bondavalli. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
//
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {toast} from 'react-toastify';
import RestAPI from './Services';
import Loader from './Loader';
class PTPConfig extends Component {
static propTypes = {
domain: PropTypes.number.isRequired,
dscp: PropTypes.number.isRequired,
};
constructor(props) {
super(props);
this.state = {
domain: this.props.domain,
dscp: this.props.dscp,
domainErr: false,
};
this.onSubmit = this.onSubmit.bind(this);
this.inputIsValid = this.inputIsValid.bind(this);
}
inputIsValid() {
return !this.state.domainErr;
}
onSubmit(event) {
event.preventDefault();
RestAPI.setPTPConfig(this.state.domain, this.state.dscp)
.then(response => toast.success('PTP config updated'));
}
render() {
return (
)
}
}
class PTPStatus extends Component {
static propTypes = {
status: PropTypes.string.isRequired,
gmid: PropTypes.string.isRequired,
jitter: PropTypes.number.isRequired,
};
render() {
return (
)
}
}
class PTP extends Component {
constructor(props) {
super(props);
this.state = {
domain: 0,
domainErr: false,
dscp: 0,
status: '',
gmid: '',
jitter: 0,
isConfigLoading: false,
isStatusLoading: false,
};
}
fetchStatus() {
this.setState({isStatusLoading: true});
RestAPI.getPTPStatus()
.then(response => response.json())
.then(
data => this.setState({
status: data.status,
gmid: data.gmid,
jitter: parseInt(data.jitter, 10),
isStatusLoading: false
}))
.catch(err => this.setState({isStatusLoading: false}));
}
fetchConfig() {
this.setState({isConfigLoading: true});
RestAPI.getPTPConfig()
.then(response => response.json())
.then(
data => this.setState({
domain: parseInt(data.domain, 10),
dscp: parseInt(data.dscp, 10),
isConfigLoading: false
}))
.catch(err => this.setState({isConfigLoading: false}));
}
componentDidMount() {
this.fetchStatus();
this.fetchConfig();
this.interval = setInterval(() => { this.fetchStatus() }, 10000)
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
{ this.state.isConfigLoading ?
:
}
{ this.state.isStatusLoading ? :
}
)
}
}
export default PTP;