Skip to content

Commit

Permalink
Merge pull request #186 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
adrianq authored Jan 13, 2021
2 parents 8b05512 + d1b14ad commit f7afd23
Show file tree
Hide file tree
Showing 16 changed files with 462 additions and 152 deletions.
6 changes: 0 additions & 6 deletions config.js.template

This file was deleted.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d2-user-extended-app",
"version": "0.3.0",
"version": "0.4.0",
"description": "DHIS2 Extended User app",
"main": "src/index.html",
"license": "GPL-3.0",
Expand Down Expand Up @@ -55,7 +55,6 @@
"karma-coverage": "0.5.0",
"karma-mocha": "0.2.0",
"karma-mocha-reporter": "1.1.1",
"karma-phantomjs-launcher": "0.2.1",
"karma-sinon": "1.0.4",
"karma-sinon-chai": "1.0.0",
"karma-sourcemap-loader": "0.3.5",
Expand All @@ -68,7 +67,6 @@
"mocha": "2.2.5",
"moment": "^2.19.1",
"node-sass": "^3.7.0",
"phantomjs": "1.9.18",
"phantomjs-polyfill": "0.0.1",
"precommit-hook": "3.0.0",
"prettier": "^1.18.2",
Expand Down
25 changes: 24 additions & 1 deletion src/List/List.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import replicateUserStore from "./replicateUser.store";
import OrgUnitDialog from "./organisation-unit-dialog/OrgUnitDialog.component";
import UserRolesDialog from "../components/UserRolesDialog.component";
import UserGroupsDialog from "../components/UserGroupsDialog.component";
import CopyInUserDialog from "../components/CopyInUserDialog.component";
import ReplicateUserFromTemplate from "../components/ReplicateUserFromTemplate.component";
import ReplicateUserFromTable from "../components/ReplicateUserFromTable.component";
import snackActions from "../Snackbar/snack.actions";
Expand All @@ -43,6 +44,7 @@ import ModalLoadingMask from "../components/ModalLoadingMask.component";
import SettingsDialog from "../components/SettingsDialog.component";
import Filters from "./Filters.component";
import DetailsBoxWithScroll from "./DetailsBoxWithScroll.component";
import copyInUserStore from "./copyInUser.store";

const pageSize = 50;

Expand Down Expand Up @@ -151,6 +153,9 @@ const List = React.createClass({
importUsers: {
open: false,
},
copyUsers: {
open: false,
},
};
},

Expand Down Expand Up @@ -248,13 +253,18 @@ const List = React.createClass({

const deleteUserStoreDisposable = deleteUserStore.subscribe(users => this.filterList());

const userCopyUserDialogStoreDisposable = copyInUserStore.subscribe(copyUsers => {
this.setAssignState("copyUsers", copyUsers);
});

this.registerDisposable(detailsStoreDisposable);
this.registerDisposable(orgUnitAssignmentStoreDisposable);
this.registerDisposable(userRolesAssignmentDialogStoreDisposable);
this.registerDisposable(userGroupsAssignmentDialogStoreDisposable);
this.registerDisposable(replicateUserDialogStoreDisposable);
this.registerDisposable(deleteUserStoreDisposable);
this.registerDisposable(enableStoreDisposable);
this.registerDisposable(userCopyUserDialogStoreDisposable);

this.filterList();
},
Expand Down Expand Up @@ -456,7 +466,13 @@ const List = React.createClass({
};

const rows = this.getDataTableRows(this.state.dataRows);
const { assignUserRoles, assignUserGroups, replicateUser, listFilterOptions } = this.state;
const {
assignUserRoles,
assignUserGroups,
replicateUser,
listFilterOptions,
copyUsers,
} = this.state;
const {
showAllUsers,
filterByGroups,
Expand Down Expand Up @@ -555,6 +571,13 @@ const List = React.createClass({
/>
) : null}

{copyUsers.open ? (
<CopyInUserDialog
user={copyUsers.user}
onRequestClose={() => copyInUserStore.setState({ open: false })}
/>
) : null}

{assignUserGroups.open ? (
<UserGroupsDialog
users={assignUserGroups.users}
Expand Down
9 changes: 9 additions & 0 deletions src/List/context.actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from "lodash";
import detailsStore from "./details.store";
import { config, getInstance as getD2 } from "d2/lib/d2";
import orgUnitAssignmentDialogStore from "./organisation-unit-dialog/organisationUnitDialogStore";
Expand All @@ -6,6 +7,7 @@ import userRolesAssignmentDialogStore from "./userRoles.store";
import userGroupsAssignmentDialogStore from "./userGroups.store";
import replicateUserStore from "./replicateUser.store";
import deleteUserStore from "./deleteUser.store";
import copyInUserStore from "./copyInUser.store";
import _m from "../utils/lodash-mixins";
import { getOrgUnitsRoots } from "../utils/dhis2Helpers";

Expand Down Expand Up @@ -95,6 +97,13 @@ const contextActions = [
onClick: user => detailsStore.setState(user),
primary: true,
},
{
name: "copyInUser",
multiple: false,
icon: "content_copy",
onClick: user => copyInUserStore.setState({ user, open: true }),
allowed: checkAccess(["update"]),
},
{
name: "assignToOrgUnits",
multiple: true,
Expand Down
3 changes: 3 additions & 0 deletions src/List/copyInUser.store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Store from "d2-ui/lib/store/Store";

export default Store.create();
46 changes: 46 additions & 0 deletions src/components/CopyInUserDialog.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from "react";
import PropTypes from "prop-types";
import CopyInUserBatchModelsMultiSelectComponent from "./batch-models-multi-select/CopyInUserBatchModelsMultiSelect.component";
import CopyInUserBatchModelsMultiSelectModel from "./batch-models-multi-select/CopyInUserBatchModelsMultiSelect.model";
import _m from "../utils/lodash-mixins";
import { getPayload } from "../models/userHelpers";

function getTitle(getTranslation, users) {
const usernames = users && users.map(user => user.userCredentials.username);
const info = usernames ? _m.joinString(getTranslation, usernames, 3, ", ") : "...";
return getTranslation("copyInUser") + ": " + info;
}

function CopyInUserDialog(props, context) {
const { d2 } = context;
const getTranslation = context.d2.i18n.getTranslation.bind(context.d2.i18n);
const modelOptions = {
parentModel: d2.models.users,
parentFields: ":owner,userCredentials[id,username,userRoles[id,name],lastLogin]",
childrenModel: d2.models.users,
getChildren: user => user.userCredentials.userRoles,
getPayload: getPayload,
};

return (
<CopyInUserBatchModelsMultiSelectComponent
model={new CopyInUserBatchModelsMultiSelectModel(context.d2, modelOptions)}
parents={[{ ...props.user }]}
onRequestClose={props.onRequestClose}
getTitle={users => getTitle(getTranslation, users)}
onSuccess={getTranslation("user_configuration_copied")}
onError={getTranslation("user_configuration_copied_error")}
/>
);
}

CopyInUserDialog.contextTypes = {
d2: PropTypes.object.isRequired,
};

CopyInUserDialog.propTypes = {
user: PropTypes.object.isRequired,
onRequestClose: PropTypes.func.isRequired,
};

export default CopyInUserDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default class BatchModelsMultiSelectComponent extends React.Component {

componentDidMount() {
const { parents, model } = this.props;

return Promise.all([model.getAllChildren(), model.getParents(parents)])
.then(([allChildren, parentsLoaded]) =>
this.setState({
Expand Down Expand Up @@ -111,7 +110,6 @@ export default class BatchModelsMultiSelectComponent extends React.Component {
.then(() => this.close(this.props.onSuccess))
.catch(err => this.close(this.props.onError));
}

onChange(selectedIds) {
this.setState({ selectedIds });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from "lodash";

const toArray = obj => (obj.toArray ? obj.toArray() : obj || []);

export default class BatchModelsMultiSelectModel {
Expand Down
Loading

0 comments on commit f7afd23

Please sign in to comment.