Skip to content

Commit

Permalink
Download reference solution archive
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Feb 10, 2018
1 parent 8c9bdc2 commit 2e3d02a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const messages = defineMessages({
}
});

const ResultArchiveInfoBox = ({ id, intl: { formatMessage } }) => (
const ResultArchiveInfoBox = ({ id, intl: { formatMessage } }) =>
<SimpleInfoBox
icon="file-archive-o"
title={formatMessage(messages.title)}
description={formatMessage(messages.description)}
/>
);
color="green"
/>;

ResultArchiveInfoBox.propTypes = {
id: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const SolutionArchiveInfoBox = ({ id, intl: { formatMessage } }) =>
icon="file-archive-o"
title={formatMessage(messages.title)}
description={formatMessage(messages.description)}
color="blue"
/>;

SolutionArchiveInfoBox.propTypes = {
Expand Down
17 changes: 16 additions & 1 deletion src/pages/ReferenceSolution/ReferenceSolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import SourceCodeInfoBox from '../../components/widgets/SourceCodeInfoBox';
import SourceCodeViewerContainer from '../../containers/SourceCodeViewerContainer';
import { RefreshIcon, SendIcon } from '../../components/icons';
import ReferenceSolutionEvaluationsContainer from '../../containers/ReferenceSolutionEvaluationsContainer';
import SolutionArchiveInfoBox from '../../components/Submissions/SolutionArchiveInfoBox';
import { downloadSolutionArchive } from '../../redux/modules/referenceSolutionEvaluations';

const messages = defineMessages({
title: {
Expand Down Expand Up @@ -60,6 +62,7 @@ class ReferenceSolution extends Component {
refreshSolutionEvaluations,
evaluateReferenceSolution,
evaluateReferenceSolutionInDebugMode,
downloadSolutionArchive,
intl: { formatMessage },
links: { EXERCISES_URI, EXERCISE_URI_FACTORY }
} = this.props;
Expand Down Expand Up @@ -135,6 +138,13 @@ class ReferenceSolution extends Component {
</Col>
)}
</Row>
<Row>
<Col lg={6} md={12}>
<a href="#" onClick={downloadSolutionArchive}>
<SolutionArchiveInfoBox id={referenceSolution.id} />
</a>
</Col>
</Row>
</Col>
<Col lg={6}>
<Row>
Expand Down Expand Up @@ -221,6 +231,7 @@ ReferenceSolution.propTypes = {
evaluateReferenceSolution: PropTypes.func.isRequired,
evaluateReferenceSolutionInDebugMode: PropTypes.func.isRequired,
referenceSolutions: ImmutablePropTypes.map,
downloadSolutionArchive: PropTypes.func,
intl: intlShape.isRequired,
links: PropTypes.object.isRequired
};
Expand All @@ -239,7 +250,11 @@ export default withLinks(
evaluateReferenceSolution: () =>
dispatch(evaluateReferenceSolution(params.referenceSolutionId)),
evaluateReferenceSolutionInDebugMode: () =>
dispatch(evaluateReferenceSolution(params.referenceSolutionId, true))
dispatch(evaluateReferenceSolution(params.referenceSolutionId, true)),
downloadSolutionArchive: e => {
e.preventDefault();
dispatch(downloadSolutionArchive(params.referenceSolutionId));
}
})
)(ReferenceSolution)
)
Expand Down
13 changes: 11 additions & 2 deletions src/redux/modules/referenceSolutionEvaluations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const { actions, reduceActions } = factory({
*/

export const additionalActionTypes = {
DOWNLOAD_EVALUATION_ARCHIVE: 'recodex/files/DOWNLOAD_EVALUATION_ARCHIVE'
DOWNLOAD_EVALUATION_ARCHIVE: 'recodex/files/DOWNLOAD_EVALUATION_ARCHIVE',
DOWNLOAD_SOLUTION_ARCHIVE: 'recodex/files/DOWNLOAD_SOLUTION_ARCHIVE'
};

export const fetchReferenceSolutionEvaluation = actions.fetchResource;
Expand All @@ -29,12 +30,20 @@ export const fetchReferenceSolutionEvaluationsForSolution = solutionId =>

export const downloadEvaluationArchive = downloadHelper({
actionType: additionalActionTypes.DOWNLOAD_EVALUATION_ARCHIVE,
fetch: fetchReferenceSolutionEvaluationIfNeeded,
fetch: null,
endpoint: id => `/reference-solutions/evaluation/${id}/download-result`,
fileNameSelector: (id, state) => `${id}.zip`,
contentType: 'application/zip'
});

export const downloadSolutionArchive = downloadHelper({
actionType: additionalActionTypes.DOWNLOAD_SOLUTION_ARCHIVE,
fetch: null,
endpoint: id => `/reference-solutions/${id}/download-solution`,
fileNameSelector: (id, state) => `${id}.zip`,
contentType: 'application/zip'
});

/**
* Reducer
*/
Expand Down

0 comments on commit 2e3d02a

Please sign in to comment.