2018-02-26 00:11:31 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { OTA_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
2018-03-03 22:41:57 +00:00
|
|
|
import {withNotifier} from '../components/SnackbarNotification';
|
2018-02-26 00:11:31 +00:00
|
|
|
import SectionContent from '../components/SectionContent';
|
|
|
|
import OTASettingsForm from '../forms/OTASettingsForm';
|
|
|
|
import { simpleGet } from '../helpers/SimpleGet';
|
|
|
|
import { simplePost } from '../helpers/SimplePost';
|
|
|
|
|
|
|
|
class OTASettings extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
otaSettings:null,
|
|
|
|
otaSettingsFetched: false,
|
|
|
|
errorMessage:null
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setState = this.setState.bind(this);
|
|
|
|
this.loadOTASettings = this.loadOTASettings.bind(this);
|
|
|
|
this.saveOTASettings = this.saveOTASettings.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.loadOTASettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
loadOTASettings() {
|
|
|
|
simpleGet(
|
|
|
|
OTA_SETTINGS_ENDPOINT,
|
|
|
|
this.setState,
|
2018-03-03 22:41:57 +00:00
|
|
|
this.props.raiseNotification,
|
2018-02-26 00:11:31 +00:00
|
|
|
"otaSettings",
|
|
|
|
"otaSettingsFetched"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveOTASettings(e) {
|
|
|
|
simplePost(
|
|
|
|
OTA_SETTINGS_ENDPOINT,
|
|
|
|
this.state,
|
|
|
|
this.setState,
|
2018-03-03 22:41:57 +00:00
|
|
|
this.props.raiseNotification,
|
2018-02-26 00:11:31 +00:00
|
|
|
"otaSettings",
|
|
|
|
"otaSettingsFetched"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
otaSettingValueChange = name => event => {
|
|
|
|
const { otaSettings } = this.state;
|
|
|
|
otaSettings[name] = event.target.value;
|
|
|
|
this.setState({otaSettings});
|
|
|
|
};
|
|
|
|
|
|
|
|
otaSettingCheckboxChange = name => event => {
|
|
|
|
const { otaSettings } = this.state;
|
|
|
|
otaSettings[name] = event.target.checked;
|
|
|
|
this.setState({otaSettings});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { otaSettingsFetched, otaSettings, errorMessage } = this.state;
|
|
|
|
return (
|
|
|
|
<SectionContent title="OTA Settings">
|
|
|
|
<OTASettingsForm otaSettingsFetched={otaSettingsFetched} otaSettings={otaSettings} errorMessage={errorMessage}
|
|
|
|
onSubmit={this.saveOTASettings} onReset={this.loadOTASettings} handleValueChange={this.otaSettingValueChange}
|
|
|
|
handleCheckboxChange={this.otaSettingCheckboxChange} />
|
|
|
|
</SectionContent>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-03 22:41:57 +00:00
|
|
|
export default withNotifier(OTASettings);
|