rename "reset" to "restart"
This commit is contained in:
parent
6aede04282
commit
7bf713dfea
@ -13,4 +13,4 @@ export const SYSTEM_STATUS_ENDPOINT = ENDPOINT_ROOT + "systemStatus";
|
|||||||
export const SIGN_IN_ENDPOINT = ENDPOINT_ROOT + "signIn";
|
export const SIGN_IN_ENDPOINT = ENDPOINT_ROOT + "signIn";
|
||||||
export const VERIFY_AUTHORIZATION_ENDPOINT = ENDPOINT_ROOT + "verifyAuthorization";
|
export const VERIFY_AUTHORIZATION_ENDPOINT = ENDPOINT_ROOT + "verifyAuthorization";
|
||||||
export const SECURITY_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "securitySettings";
|
export const SECURITY_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "securitySettings";
|
||||||
export const RESET_ENDPOINT = ENDPOINT_ROOT + "reset";
|
export const RESTART_ENDPOINT = ENDPOINT_ROOT + "restart";
|
||||||
|
@ -22,7 +22,7 @@ import DataUsageIcon from '@material-ui/icons/DataUsage';
|
|||||||
import AutorenewIcon from '@material-ui/icons/Autorenew';
|
import AutorenewIcon from '@material-ui/icons/Autorenew';
|
||||||
import RefreshIcon from '@material-ui/icons/Refresh';
|
import RefreshIcon from '@material-ui/icons/Refresh';
|
||||||
|
|
||||||
import { SYSTEM_STATUS_ENDPOINT, RESET_ENDPOINT } from '../constants/Endpoints';
|
import { SYSTEM_STATUS_ENDPOINT, RESTART_ENDPOINT } from '../constants/Endpoints';
|
||||||
import { restComponent } from '../components/RestComponent';
|
import { restComponent } from '../components/RestComponent';
|
||||||
import LoadingNotification from '../components/LoadingNotification';
|
import LoadingNotification from '../components/LoadingNotification';
|
||||||
import SectionContent from '../components/SectionContent';
|
import SectionContent from '../components/SectionContent';
|
||||||
@ -42,7 +42,7 @@ class SystemStatus extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
confirmReset: false,
|
confirmRestart: false,
|
||||||
processing: false
|
processing: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,53 +112,53 @@ class SystemStatus extends Component {
|
|||||||
<Button startIcon={<RefreshIcon />} variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
<Button startIcon={<RefreshIcon />} variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
<Button startIcon={<AutorenewIcon />} variant="contained" color="secondary" className={classes.button} onClick={this.onReset}>
|
<Button startIcon={<AutorenewIcon />} variant="contained" color="secondary" className={classes.button} onClick={this.onRestart}>
|
||||||
Reset
|
Restart
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onReset = () => {
|
onRestart = () => {
|
||||||
this.setState({ confirmReset: true });
|
this.setState({ confirmRestart: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
onResetRejected = () => {
|
onRestartRejected = () => {
|
||||||
this.setState({ confirmReset: false });
|
this.setState({ confirmRestart: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
onResetConfirmed = () => {
|
onRestartConfirmed = () => {
|
||||||
this.setState({ processing: true });
|
this.setState({ processing: true });
|
||||||
redirectingAuthorizedFetch(RESET_ENDPOINT, { method: 'POST' })
|
redirectingAuthorizedFetch(RESTART_ENDPOINT, { method: 'POST' })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this.props.enqueueSnackbar("Device is resetting", { variant: 'info' });
|
this.props.enqueueSnackbar("Device is restarting", { variant: 'info' });
|
||||||
this.setState({ processing: false, confirmReset: false });
|
this.setState({ processing: false, confirmRestart: false });
|
||||||
} else {
|
} else {
|
||||||
throw Error("Invalid status code: " + response.status);
|
throw Error("Invalid status code: " + response.status);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.props.enqueueSnackbar(error.message || "Problem resetting device", { variant: 'error' });
|
this.props.enqueueSnackbar(error.message || "Problem restarting device", { variant: 'error' });
|
||||||
this.setState({ processing: false, confirmReset: false });
|
this.setState({ processing: false, confirmRestart: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderResetDialog() {
|
renderRestartDialog() {
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={this.state.confirmReset}
|
open={this.state.confirmRestart}
|
||||||
onClose={this.onResetRejected}
|
onClose={this.onRestartRejected}
|
||||||
>
|
>
|
||||||
<DialogTitle>Confirm Reset</DialogTitle>
|
<DialogTitle>Confirm Restart</DialogTitle>
|
||||||
<DialogContent dividers={true}>
|
<DialogContent dividers={true}>
|
||||||
Are you sure you want to reset the device?
|
Are you sure you want to restart the device?
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button startIcon={<AutorenewIcon />} variant="contained" onClick={this.onResetConfirmed} disabled={this.state.processing} color="primary" autoFocus>
|
<Button startIcon={<AutorenewIcon />} variant="contained" onClick={this.onRestartConfirmed} disabled={this.state.processing} color="primary" autoFocus>
|
||||||
Reset
|
Restart
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="contained" onClick={this.onResetRejected} color="secondary">
|
<Button variant="contained" onClick={this.onRestartRejected} color="secondary">
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
@ -171,14 +171,14 @@ class SystemStatus extends Component {
|
|||||||
return (
|
return (
|
||||||
<SectionContent title="System Status">
|
<SectionContent title="System Status">
|
||||||
<LoadingNotification
|
<LoadingNotification
|
||||||
onReset={loadData}
|
onRestart={loadData}
|
||||||
fetched={fetched}
|
fetched={fetched}
|
||||||
errorMessage={errorMessage}
|
errorMessage={errorMessage}
|
||||||
render={
|
render={
|
||||||
() => this.renderSystemStatus(data, classes)
|
() => this.renderSystemStatus(data, classes)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{this.renderResetDialog()}
|
{this.renderRestartDialog()}
|
||||||
</SectionContent>
|
</SectionContent>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs):
|
|||||||
_apSettingsService(server, fs, &_securitySettingsService),
|
_apSettingsService(server, fs, &_securitySettingsService),
|
||||||
_ntpSettingsService(server, fs, &_securitySettingsService),
|
_ntpSettingsService(server, fs, &_securitySettingsService),
|
||||||
_otaSettingsService(server, fs, &_securitySettingsService),
|
_otaSettingsService(server, fs, &_securitySettingsService),
|
||||||
_ResetService(server, &_securitySettingsService),
|
_restartService(server, &_securitySettingsService),
|
||||||
_authenticationService(server, &_securitySettingsService),
|
_authenticationService(server, &_securitySettingsService),
|
||||||
_wifiScanner(server, &_securitySettingsService),
|
_wifiScanner(server, &_securitySettingsService),
|
||||||
_wifiStatus(server, &_securitySettingsService),
|
_wifiStatus(server, &_securitySettingsService),
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include <NTPStatus.h>
|
#include <NTPStatus.h>
|
||||||
#include <APStatus.h>
|
#include <APStatus.h>
|
||||||
#include <SystemStatus.h>
|
#include <SystemStatus.h>
|
||||||
#include <ResetService.h>
|
#include <RestartService.h>
|
||||||
|
|
||||||
class ESP8266React {
|
class ESP8266React {
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class ESP8266React {
|
|||||||
APSettingsService _apSettingsService;
|
APSettingsService _apSettingsService;
|
||||||
NTPSettingsService _ntpSettingsService;
|
NTPSettingsService _ntpSettingsService;
|
||||||
OTASettingsService _otaSettingsService;
|
OTASettingsService _otaSettingsService;
|
||||||
ResetService _ResetService;
|
RestartService _restartService;
|
||||||
AuthenticationService _authenticationService;
|
AuthenticationService _authenticationService;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
#include <ResetService.h>
|
|
||||||
|
|
||||||
ResetService::ResetService(AsyncWebServer* server, SecurityManager* securityManager) {
|
|
||||||
server->on(RESET_SERVICE_PATH, HTTP_POST, securityManager->wrapRequest(
|
|
||||||
std::bind(&ResetService::reset, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResetService::reset(AsyncWebServerRequest* request) {
|
|
||||||
request->onDisconnect([]() {
|
|
||||||
#if defined(ESP8266)
|
|
||||||
ESP.reset();
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
ESP.restart();
|
|
||||||
#endif
|
|
||||||
});
|
|
||||||
request->send(200);
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
#ifndef ResetService_h
|
|
||||||
#define ResetService_h
|
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
|
||||||
#include <SecurityManager.h>
|
|
||||||
|
|
||||||
#define RESET_SERVICE_PATH "/rest/reset"
|
|
||||||
|
|
||||||
class ResetService {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ResetService(AsyncWebServer* server, SecurityManager* securityManager);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void reset(AsyncWebServerRequest *request);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // end ResetService_h
|
|
18
lib/framework/RestartService.cpp
Normal file
18
lib/framework/RestartService.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <RestartService.h>
|
||||||
|
|
||||||
|
RestartService::RestartService(AsyncWebServer* server, SecurityManager* securityManager) {
|
||||||
|
server->on(RESTART_SERVICE_PATH, HTTP_POST, securityManager->wrapRequest(
|
||||||
|
std::bind(&RestartService::restart, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RestartService::restart(AsyncWebServerRequest* request) {
|
||||||
|
request->onDisconnect([]() {
|
||||||
|
#if defined(ESP8266)
|
||||||
|
ESP.reset();
|
||||||
|
#elif defined(ESP_PLATFORM)
|
||||||
|
ESP.restart();
|
||||||
|
#endif
|
||||||
|
});
|
||||||
|
request->send(200);
|
||||||
|
}
|
29
lib/framework/RestartService.h
Normal file
29
lib/framework/RestartService.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef RestartService_h
|
||||||
|
#define RestartService_h
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESPAsyncTCP.h>
|
||||||
|
#elif defined(ESP_PLATFORM)
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <SecurityManager.h>
|
||||||
|
|
||||||
|
#define RESTART_SERVICE_PATH "/rest/restart"
|
||||||
|
|
||||||
|
class RestartService {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RestartService(AsyncWebServer* server, SecurityManager* securityManager);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void restart(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // end RestartService_h
|
Loading…
Reference in New Issue
Block a user