Skip to content

Commit 8fb805e

Browse files
authored
Merge pull request #63 from rjwats/rename
rename "reset" to "restart"
2 parents 6aede04 + 7bf713d commit 8fb805e

File tree

8 files changed

+75
-75
lines changed

8 files changed

+75
-75
lines changed

interface/src/constants/Endpoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export const SYSTEM_STATUS_ENDPOINT = ENDPOINT_ROOT + "systemStatus";
1313
export const SIGN_IN_ENDPOINT = ENDPOINT_ROOT + "signIn";
1414
export const VERIFY_AUTHORIZATION_ENDPOINT = ENDPOINT_ROOT + "verifyAuthorization";
1515
export const SECURITY_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "securitySettings";
16-
export const RESET_ENDPOINT = ENDPOINT_ROOT + "reset";
16+
export const RESTART_ENDPOINT = ENDPOINT_ROOT + "restart";

interface/src/containers/SystemStatus.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import DataUsageIcon from '@material-ui/icons/DataUsage';
2222
import AutorenewIcon from '@material-ui/icons/Autorenew';
2323
import RefreshIcon from '@material-ui/icons/Refresh';
2424

25-
import { SYSTEM_STATUS_ENDPOINT, RESET_ENDPOINT } from '../constants/Endpoints';
25+
import { SYSTEM_STATUS_ENDPOINT, RESTART_ENDPOINT } from '../constants/Endpoints';
2626
import { restComponent } from '../components/RestComponent';
2727
import LoadingNotification from '../components/LoadingNotification';
2828
import SectionContent from '../components/SectionContent';
@@ -42,7 +42,7 @@ class SystemStatus extends Component {
4242
super(props);
4343

4444
this.state = {
45-
confirmReset: false,
45+
confirmRestart: false,
4646
processing: false
4747
}
4848
}
@@ -112,53 +112,53 @@ class SystemStatus extends Component {
112112
<Button startIcon={<RefreshIcon />} variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
113113
Refresh
114114
</Button>
115-
<Button startIcon={<AutorenewIcon />} variant="contained" color="secondary" className={classes.button} onClick={this.onReset}>
116-
Reset
115+
<Button startIcon={<AutorenewIcon />} variant="contained" color="secondary" className={classes.button} onClick={this.onRestart}>
116+
Restart
117117
</Button>
118118
</div>
119119
);
120120
}
121121

122-
onReset = () => {
123-
this.setState({ confirmReset: true });
122+
onRestart = () => {
123+
this.setState({ confirmRestart: true });
124124
}
125125

126-
onResetRejected = () => {
127-
this.setState({ confirmReset: false });
126+
onRestartRejected = () => {
127+
this.setState({ confirmRestart: false });
128128
}
129129

130-
onResetConfirmed = () => {
130+
onRestartConfirmed = () => {
131131
this.setState({ processing: true });
132-
redirectingAuthorizedFetch(RESET_ENDPOINT, { method: 'POST' })
132+
redirectingAuthorizedFetch(RESTART_ENDPOINT, { method: 'POST' })
133133
.then(response => {
134134
if (response.status === 200) {
135-
this.props.enqueueSnackbar("Device is resetting", { variant: 'info' });
136-
this.setState({ processing: false, confirmReset: false });
135+
this.props.enqueueSnackbar("Device is restarting", { variant: 'info' });
136+
this.setState({ processing: false, confirmRestart: false });
137137
} else {
138138
throw Error("Invalid status code: " + response.status);
139139
}
140140
})
141141
.catch(error => {
142-
this.props.enqueueSnackbar(error.message || "Problem resetting device", { variant: 'error' });
143-
this.setState({ processing: false, confirmReset: false });
142+
this.props.enqueueSnackbar(error.message || "Problem restarting device", { variant: 'error' });
143+
this.setState({ processing: false, confirmRestart: false });
144144
});
145145
}
146146

147-
renderResetDialog() {
147+
renderRestartDialog() {
148148
return (
149149
<Dialog
150-
open={this.state.confirmReset}
151-
onClose={this.onResetRejected}
150+
open={this.state.confirmRestart}
151+
onClose={this.onRestartRejected}
152152
>
153-
<DialogTitle>Confirm Reset</DialogTitle>
153+
<DialogTitle>Confirm Restart</DialogTitle>
154154
<DialogContent dividers={true}>
155-
Are you sure you want to reset the device?
155+
Are you sure you want to restart the device?
156156
</DialogContent>
157157
<DialogActions>
158-
<Button startIcon={<AutorenewIcon />} variant="contained" onClick={this.onResetConfirmed} disabled={this.state.processing} color="primary" autoFocus>
159-
Reset
158+
<Button startIcon={<AutorenewIcon />} variant="contained" onClick={this.onRestartConfirmed} disabled={this.state.processing} color="primary" autoFocus>
159+
Restart
160160
</Button>
161-
<Button variant="contained" onClick={this.onResetRejected} color="secondary">
161+
<Button variant="contained" onClick={this.onRestartRejected} color="secondary">
162162
Cancel
163163
</Button>
164164
</DialogActions>
@@ -171,14 +171,14 @@ class SystemStatus extends Component {
171171
return (
172172
<SectionContent title="System Status">
173173
<LoadingNotification
174-
onReset={loadData}
174+
onRestart={loadData}
175175
fetched={fetched}
176176
errorMessage={errorMessage}
177177
render={
178178
() => this.renderSystemStatus(data, classes)
179179
}
180180
/>
181-
{this.renderResetDialog()}
181+
{this.renderRestartDialog()}
182182
</SectionContent>
183183
)
184184
}

lib/framework/ESP8266React.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs):
66
_apSettingsService(server, fs, &_securitySettingsService),
77
_ntpSettingsService(server, fs, &_securitySettingsService),
88
_otaSettingsService(server, fs, &_securitySettingsService),
9-
_ResetService(server, &_securitySettingsService),
9+
_restartService(server, &_securitySettingsService),
1010
_authenticationService(server, &_securitySettingsService),
1111
_wifiScanner(server, &_securitySettingsService),
1212
_wifiStatus(server, &_securitySettingsService),

lib/framework/ESP8266React.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <NTPStatus.h>
2525
#include <APStatus.h>
2626
#include <SystemStatus.h>
27-
#include <ResetService.h>
27+
#include <RestartService.h>
2828

2929
class ESP8266React {
3030

@@ -47,7 +47,7 @@ class ESP8266React {
4747
APSettingsService _apSettingsService;
4848
NTPSettingsService _ntpSettingsService;
4949
OTASettingsService _otaSettingsService;
50-
ResetService _ResetService;
50+
RestartService _restartService;
5151
AuthenticationService _authenticationService;
5252

5353

lib/framework/ResetService.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/framework/ResetService.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/framework/RestartService.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <RestartService.h>
2+
3+
RestartService::RestartService(AsyncWebServer* server, SecurityManager* securityManager) {
4+
server->on(RESTART_SERVICE_PATH, HTTP_POST, securityManager->wrapRequest(
5+
std::bind(&RestartService::restart, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN
6+
));
7+
}
8+
9+
void RestartService::restart(AsyncWebServerRequest* request) {
10+
request->onDisconnect([]() {
11+
#if defined(ESP8266)
12+
ESP.reset();
13+
#elif defined(ESP_PLATFORM)
14+
ESP.restart();
15+
#endif
16+
});
17+
request->send(200);
18+
}

lib/framework/RestartService.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef RestartService_h
2+
#define RestartService_h
3+
4+
#if defined(ESP8266)
5+
#include <ESP8266WiFi.h>
6+
#include <ESPAsyncTCP.h>
7+
#elif defined(ESP_PLATFORM)
8+
#include <WiFi.h>
9+
#include <AsyncTCP.h>
10+
#endif
11+
12+
#include <ESPAsyncWebServer.h>
13+
#include <SecurityManager.h>
14+
15+
#define RESTART_SERVICE_PATH "/rest/restart"
16+
17+
class RestartService {
18+
19+
public:
20+
21+
RestartService(AsyncWebServer* server, SecurityManager* securityManager);
22+
23+
private:
24+
25+
void restart(AsyncWebServerRequest *request);
26+
27+
};
28+
29+
#endif // end RestartService_h

0 commit comments

Comments
 (0)