Skip to content

Commit

Permalink
Forking of exercises for superadmins
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Feb 22, 2018
1 parent 39da265 commit 819362a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/components/forms/ForkExerciseForm/ForkExerciseForm.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.formSpace {
padding-left: 10px;
.forkForm {
padding-left: 0px;
display: flex;
}
15 changes: 10 additions & 5 deletions src/components/forms/ForkExerciseForm/ForkExerciseForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SuccessIcon } from '../../../components/icons';
import { forkStatuses } from '../../../redux/modules/exercises';
import { getFork } from '../../../redux/selectors/exercises';
import ResourceRenderer from '../../helpers/ResourceRenderer';
import { getLocalizedName } from '../../../helpers/getLocalizedData';
import { getGroupCanonicalLocalizedName } from '../../../helpers/getLocalizedData';

import withLinks from '../../../hoc/withLinks';

Expand Down Expand Up @@ -41,6 +41,7 @@ class ForkExerciseForm extends Component {
hasSucceeded = false,
invalid,
groups,
groupsAccessor,
intl: { locale }
} = this.props;

Expand Down Expand Up @@ -70,7 +71,7 @@ class ForkExerciseForm extends Component {
defaultMessage="Saving failed. Please try again later."
/>
</Alert>}
<Form inline className="formSpace">
<Form inline className="forkForm">
<ResourceRenderer resource={groups.toArray()}>
{(...groups) =>
<Field
Expand All @@ -79,12 +80,15 @@ class ForkExerciseForm extends Component {
label={''}
options={[{ key: '', name: '_Public_' }].concat(
groups
.sort((a, b) => a.name.localeCompare(b.name, locale))
.filter((item, pos, arr) => arr.indexOf(item) === pos)
.map(group => ({
key: group.id,
name: getLocalizedName(group, locale)
name: getGroupCanonicalLocalizedName(
group,
groupsAccessor,
locale
)
}))
.sort((a, b) => a.name.localeCompare(b.name, locale))
)}
/>}
</ResourceRenderer>
Expand Down Expand Up @@ -140,6 +144,7 @@ ForkExerciseForm.propTypes = {
push: PropTypes.func.isRequired,
links: PropTypes.object,
groups: ImmutablePropTypes.map,
groupsAccessor: PropTypes.func.isRequired,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

Expand Down
53 changes: 39 additions & 14 deletions src/pages/Exercise/Exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '../../components/icons';
import Confirm from '../../components/forms/Confirm';
import PipelinesSimpleList from '../../components/Pipelines/PipelinesSimpleList';
// import ForkExerciseForm from '../../components/forms/ForkExerciseForm';
import ForkExerciseForm from '../../components/forms/ForkExerciseForm';
import AssignExerciseButton from '../../components/buttons/AssignExerciseButton';

import { isSubmitting } from '../../redux/selectors/submission';
Expand All @@ -48,23 +48,31 @@ import { fetchHardwareGroups } from '../../redux/modules/hwGroups';
import { create as assignExercise } from '../../redux/modules/assignments';
import { exerciseSelector } from '../../redux/selectors/exercises';
import { referenceSolutionsSelector } from '../../redux/selectors/referenceSolutions';
import { canEditExercise } from '../../redux/selectors/users';
import {
canEditExercise,
isLoggedAsSuperAdmin
} from '../../redux/selectors/users';
import {
deletePipeline,
fetchExercisePipelines,
create as createPipeline
} from '../../redux/modules/pipelines';
import { exercisePipelinesSelector } from '../../redux/selectors/pipelines';
import { fetchUsersGroupsIfNeeded } from '../../redux/modules/groups';
import {
fetchUsersGroupsIfNeeded,
fetchInstanceGroups
} from '../../redux/modules/groups';

import { loggedInUserIdSelector } from '../../redux/selectors/auth';
import {
supervisorOfSelector,
groupsSelector
groupsSelector,
groupDataAccessorSelector
} from '../../redux/selectors/groups';

import withLinks from '../../hoc/withLinks';
import SupplementaryFilesTableContainer from '../../containers/SupplementaryFilesTableContainer/SupplementaryFilesTableContainer';
import { fetchUser } from '../../redux/modules/users';

const messages = defineMessages({
groupsBox: {
Expand All @@ -90,7 +98,15 @@ class Exercise extends Component {
dispatch(fetchReferenceSolutionsIfNeeded(exerciseId)),
dispatch(fetchHardwareGroups()),
dispatch(fetchExercisePipelines(exerciseId)),
dispatch(fetchUsersGroupsIfNeeded(userId))
dispatch(fetchUsersGroupsIfNeeded(userId)),
dispatch(fetchUser(userId))
.then(res => res.value)
.then(
data =>
data.privateData.role === 'superadmin'
? dispatch(fetchInstanceGroups(data.privateData.instanceId))
: Promise.resolve()
)
]);

componentWillMount() {
Expand Down Expand Up @@ -141,12 +157,14 @@ class Exercise extends Component {
initCreateReferenceSolution,
exercisePipelines,
deleteReferenceSolution,
push
// groups,
// forkExercise
push,
groups,
groupsAccessor,
forkExercise,
isSuperAdmin
} = this.props;

// const { forkId } = this.state;
const { forkId } = this.state;

const {
links: {
Expand Down Expand Up @@ -238,13 +256,16 @@ class Exercise extends Component {
/>
</Button>
</LinkContainer>
{/* <ForkExerciseForm
</ButtonGroup>
<p />
{isSuperAdmin &&
<ForkExerciseForm
exerciseId={exercise.id}
groups={groups}
forkId={forkId}
onSubmit={formData => forkExercise(forkId, formData)}
/> */}
</ButtonGroup>
groupsAccessor={groupsAccessor}
/>}
</div>}
<p />
</Col>
Expand Down Expand Up @@ -489,7 +510,9 @@ Exercise.propTypes = {
links: PropTypes.object,
deleteReferenceSolution: PropTypes.func.isRequired,
forkExercise: PropTypes.func.isRequired,
groups: ImmutablePropTypes.map
groups: ImmutablePropTypes.map,
isSuperAdmin: PropTypes.bool,
groupsAccessor: PropTypes.func.isRequired
};

export default withLinks(
Expand All @@ -507,7 +530,9 @@ export default withLinks(
canEditExercise(userId, exerciseId)(state),
referenceSolutions: referenceSolutionsSelector(exerciseId)(state),
exercisePipelines: exercisePipelinesSelector(exerciseId)(state),
groups: groupsSelector(state)
groups: groupsSelector(state),
groupsAccessor: groupDataAccessorSelector(state),
isSuperAdmin: isLoggedAsSuperAdmin(state)
};
},
(dispatch, { params: { exerciseId } }) => ({
Expand Down
1 change: 1 addition & 0 deletions src/redux/modules/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const fetchAllUsers = actions.fetchMany({
endpoint: fetchManyEndpoint
});
export const loadUserData = actions.pushResource;
export const fetchUser = actions.fetchResource;
export const fetchUserIfNeeded = actions.fetchIfNeeded;
export const validateRegistrationData = (email, password) =>
createApiAction({
Expand Down

0 comments on commit 819362a

Please sign in to comment.