Skip to content

Commit

Permalink
Merge 931ff3f into 5116316
Browse files Browse the repository at this point in the history
  • Loading branch information
_justmesam committed Jan 31, 2018
2 parents 5116316 + 931ff3f commit 2d3b4f7
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 62 deletions.
7 changes: 6 additions & 1 deletion app/css/openmrs-addonmanager.css
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,9 @@ body.loading .waiting-modal {

.main-row {
width: 30vw;
}
}

.none-user-page {
text-align: center;
padding: 4%;
}
136 changes: 102 additions & 34 deletions app/js/components/manageApps/Addon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class Addon extends Component {
starting: false,
isOpen: false,
showMessageDetail: false,
isAdmin: false,
loadingComplete: false,
enableDeleteAndStart: true,
messageBody: '',
messageType: 'success',
showMessage: false,
Expand All @@ -32,6 +34,9 @@ class Addon extends Component {
this.handleAction = this.handleAction.bind(this);
this.actionRunning = this.actionRunning.bind(this);
this.handleAddonAction = this.handleAddonAction.bind(this);
this.checkIsAdmin = this.checkIsAdmin.bind(this);
this.fetchCurrentUser = this.fetchCurrentUser.bind(this);
this.enableAdminDeleteAndStart = this.enableAdminDeleteAndStart.bind(this);
this.hideModal = this.hideModal.bind(this);
this.handleDelete = this.handleDelete.bind(this);
this.getAffectedModules = this.getAffectedModules.bind(this);
Expand All @@ -41,6 +46,8 @@ class Addon extends Component {

componentWillMount(){
this.props.checkLoginStatus();
this.checkIsAdmin();
this.enableAdminDeleteAndStart();
}

componentDidMount() {
Expand Down Expand Up @@ -80,6 +87,61 @@ class Addon extends Component {

}

fetchCurrentUser(){
const apiHelper = new ApiHelper(null);
const getUserData = new Promise(function(resolve, reject) {
apiHelper.get('/v1/session').then(response => {
resolve(response);
});
});
return getUserData;
}

checkIsAdmin() {
this.fetchCurrentUser().then((response) => {
if (response.user) {
const user = response.user;
let userPrivileges = [];
let userCanManageModules;
userPrivileges = userPrivileges.concat(user.privileges);
if (userPrivileges.length > 0) {
const managePrivilege = userPrivileges.find((managemodules) => {
if (managemodules.display === "Manage Modules") {
return userCanManageModules = true;
}
return userCanManageModules = false;
});
}
if (user.systemId === "admin" || user.display === "admin" || userCanManageModules){
this.setState((prevState, props) => {
return {
isAdmin : true,
};
});
}
}
});
}

enableAdminDeleteAndStart () {
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`;
const requestUrl = '/owa/allowModuleWebUpload';
axios.get(`${urlPrefix}/${apiBaseUrl}${requestUrl}`)
.then(response => {
this.setState((prevState, props) => {
return {
enableDeleteAndStart : response.data,
};
});
})
.catch(error => {
toastr.error(error.message);
});
}

fetchOwa(fileName) {
this.state.loadingComplete === true ? this.setState({ loadingComplete: false }) : null;
const owaName = fileName.substr(fileName.indexOf('-') + 1, fileName.length - 1);
Expand Down Expand Up @@ -126,14 +188,14 @@ class Addon extends Component {
}

axios.post(`${urlPrefix}/${apiBaseUrl}${this.requestUrl}`, postData)
.then(response => {
.then(response => {
const moduleName = response.data.modules[0].display;
this.setState({
stopping: false,
starting: false,
messageBody: response.data.action == 'START' ?
`${moduleName} module has started`
:
messageBody: response.data.action == 'START' ?
`${moduleName} module has started`
:
`${moduleName} module has stopped`,
messageType: 'success',
showMessage: true,
Expand Down Expand Up @@ -268,16 +330,18 @@ class Addon extends Component {

render() {
const {
app,
isOpen,
showMessageDetail,
affectedModules,
action,
app,
isOpen,
isAdmin,
showMessageDetail,
affectedModules,
action,
loadingComplete,
messageBody,
enableDeleteAndStart,
messageType,
showMessage } = this.state;

const message = app.startupErrorMessage && app.startupErrorMessage.length > 0 ?
'Error starting '
: null;
Expand Down Expand Up @@ -380,34 +444,38 @@ class Addon extends Component {
</tbody>
</table>

<button
type="button"
className="btn btn-danger btn-delete btn-lower-margin"
onClick={(event) => this.handleAddonAction(event, "delete")}
>
Delete
</button>

{
app.uuid ?
app.started ?
{ enableDeleteAndStart ?
isAdmin ?
<span>
<button
type="button"
className="btn btn-primary module-control btn-lower-margin"
onClick={(event) => this.handleAddonAction(event, "stop")}
className="btn btn-danger btn-delete"
onClick={(event) => this.handleAddonDelete(event)}
>
Stop
Delete
</button>
:
<button
type="button"
className="btn btn-success module-control btn-lower-margin"
onClick={(event) => this.handleAction(app.uuid, "start", event)}
>
Start
</button>
:
<span />
<span>
{ app.uuid ?
app.started ?
<button
type="button"
className="btn btn-primary module-control"
onClick={(event) => this.handleAction(event, app.uuid, "stop")}
>
Stop
</button>
:
<button
type="button"
className="btn btn-success module-control"
onClick={(e) => this.handleAction(e, app.uuid, "start")}
>
Start
</button>
: null}
</span>
</span>
: null :null
}
{isOpen ? (
<ActionAddonModal
Expand Down

0 comments on commit 2d3b4f7

Please sign in to comment.