Skip to content

Commit

Permalink
Confirm before stopping app
Browse files Browse the repository at this point in the history
  • Loading branch information
patlub committed Feb 27, 2018
1 parent bd984db commit 55dc1ac
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/js/components/manageApps/ActionAddonModal.jsx
Expand Up @@ -32,7 +32,7 @@ export default class ActionModal extends Component {
className="btn btn-danger"
data-dismiss="modal"
id="cancel-btn"
onClick={() => (action === 'delete') ? handleAction(appUuid, app.name): handleAction(appUuid, action)}
onClick={(event) => (action === 'delete') ? handleAction(event, appUuid, app.name): handleAction(event, appUuid, action)}
>{(action === 'delete') ? 'Delete' : 'Stop'}</button>
</ModalFooter>
</Modal>
Expand All @@ -52,7 +52,7 @@ export default class ActionModal extends Component {
className="btn btn-danger"
data-dismiss="modal"
id="cancel-btn"
onClick={() => (action === 'delete') ? handleAction(appUuid, app.name) : handleAction(appUuid, action)}
onClick={(event) => (action === 'delete') ? handleAction(event, appUuid, app.name) : handleAction(event, appUuid, 'stop-confirmed')}
>{(action === 'delete') ? 'Delete' : 'Stop'}</button>
</ModalFooter>
</Modal>
Expand Down
91 changes: 50 additions & 41 deletions app/js/components/manageApps/Addon.jsx
Expand Up @@ -181,51 +181,60 @@ class Addon extends Component {
if (action === 'stop') {
this.setState((prevState, props) => {
return {
stopping: true,
isOpen: true,
action
};
});
} else if (action === 'start') {
this.setState({
starting: true
});
}
const applicationDistribution = location.href.split('/')[2];
const urlPrefix = location.href.substr(0, location.href.indexOf('//'));
const url = location.href.split('/')[3];
const apiBaseUrl = `/${applicationDistribution}/${url}/ws/rest`;
this.requestUrl = '/v1/moduleaction';
let postData = {};

if (moduleUuid !== null) {
postData = {
"action": action,
"modules": [moduleUuid],
};
}

axios.post(`${urlPrefix}/${apiBaseUrl}${this.requestUrl}`, postData)
.then(response => {
const moduleName = response.data.modules[0].display;
else if (action === 'stop-confirmed' || action === 'start') {
this.hideModal();
action === 'start' ?
this.setState({
stopping: false,
starting: false,
messageBody: response.data.action == 'START' ?
`${moduleName} module has started`
:
`${moduleName} module has stopped`,
messageType: 'success',
showMessage: true,
});
this.fetchAddon();
}).catch((error) => {
error.response.status === 401 ? location.href = `${location.href.substr(0, location.href.indexOf(location.href.split('/')[4]))}login.htm` : null;
starting: true
}):
this.setState({
stopping: false,
starting: false,
stopping: true
});
this.fetchAddon();
const applicationDistribution = location.href.split('/')[2];
const urlPrefix = location.href.substr(0, location.href.indexOf('//'));
const url = location.href.split('/')[3];
const apiBaseUrl = `/${applicationDistribution}/${url}/ws/rest`;
this.requestUrl = '/v1/moduleaction';
let postData = {};

if (moduleUuid !== null) {
postData = {
"action": action === 'start' ? 'start' : 'stop',
"modules": [moduleUuid],
};
}
);

axios.post(`${urlPrefix}/${apiBaseUrl}${this.requestUrl}`, postData)
.then(response => {
const moduleName = response.data.modules[0].display;
this.setState({
stopping: false,
starting: false,
messageBody: response.data.action == 'START' ?
`${moduleName} module has started`
:
`${moduleName} module has stopped`,
messageType: 'success',
showMessage: true,
});
this.fetchAddon();
}).catch((error) => {
error.response.status === 401 ? location.href =
`${location.href.substr(0, location.href.indexOf(location.href.split('/')[4]))}login.htm` : null;
this.setState({
stopping: false,
starting: false,
});
this.fetchAddon();
}
);
}
}

handleMessageClick(event) {
Expand Down Expand Up @@ -350,9 +359,9 @@ class Addon extends Component {
isAdmin,
isOpen,
appType,
showMessageDetail,
affectedModules,
action,
showMessageDetail,
affectedModules,
action,
loadingComplete,
messageBody,
enableDeleteAndStart,
Expand Down Expand Up @@ -484,7 +493,7 @@ class Addon extends Component {
</button>
<span>
{ appType === 'module' ?
app.started ?
app.started ?
<button
type="button"
className="btn btn-primary module-control"
Expand Down

0 comments on commit 55dc1ac

Please sign in to comment.