Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ReCodEx/web-app into exer…
Browse files Browse the repository at this point in the history
…cise-rights-tuning
  • Loading branch information
Martin Krulis committed Oct 28, 2017
2 parents 55cafa3 + b878fcf commit 57d01d7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ class EvaluationProgress extends Component {
completed = 0,
skipped = 0,
failed = 0,
finishProcessing
finishProcessing,
onClose
} = this.props;

return (
<Modal show={isOpen} backdrop="static">
<Modal show={isOpen} backdrop="static" onHide={onClose}>
<Modal.Header closeButton>
<Modal.Title>
<FormattedMessage
Expand Down Expand Up @@ -130,7 +131,8 @@ EvaluationProgress.propTypes = {
completed: PropTypes.number.isRequired,
skipped: PropTypes.number.isRequired,
failed: PropTypes.number.isRequired,
finishProcessing: PropTypes.func.isRequired
finishProcessing: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired
};

export default EvaluationProgress;
2 changes: 1 addition & 1 deletion src/components/layout/Sidebar/sidebar.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.mainSidebar {
height: 100%;
overflow-y: scroll;
overflow-y: auto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@ import EvaluationProgress from '../../components/Assignments/EvaluationProgress'
import randomMessages, { extraMessages } from './randomMessages';

class EvaluationProgressContainer extends Component {
state = { realTimeProcessing: true, monitor: null };
state = { realTimeProcessing: true, monitor: null, isUserClosed: false };
socket = null;
componentWillMount = () => this.init(this.props);
componentWillReceiveProps = props => this.init(props);
componentWillReceiveProps = newProps => {
if (newProps.monitor && newProps.monitor.id) {
if (this.props.monitor && this.props.monitor.id) {
if (newProps.monitor.id === this.props.monitor.id) {
return;
}
}
this.init(newProps);
}
};
componentWillUnmount = () => {
this.closeSocket();
this.socket = null;
};

init = props => {
const { monitor } = props;
if (
this.socket == null &&
monitor !== null &&
monitor !== this.state.monitor
) {

if (this.socket !== null) {
this.closeSocket();
}
this.setState({ isUserClosed: false, realTimeProcessing: true });

if (monitor !== null && monitor !== this.state.monitor) {
if (typeof WebSocket === 'function') {
this.socket = new WebSocket(monitor.url);
this.socket.onopen = () => this.socket.send(monitor.id);
Expand Down Expand Up @@ -138,11 +149,18 @@ class EvaluationProgressContainer extends Component {
finish = () => {
const { push, link, finishProcessing } = this.props;
finishProcessing();
this.closeSocket();
push(link);
};

onUserClose = () => {
this.closeSocket();
this.setState({ isUserClosed: true, monitor: null });
};

render = () => {
const { isOpen, messages, progress, isFinished } = this.props;
const { isUserClosed } = this.state;
let displayedMessages = new List();
const now = new Date();
if (now.getDate() === 1 && now.getMonth() === 3) {
Expand All @@ -152,23 +170,25 @@ class EvaluationProgressContainer extends Component {

return this.state.realTimeProcessing === true
? <EvaluationProgress
isOpen={isOpen}
isOpen={isOpen && !isUserClosed}
messages={displayedMessages}
completed={progress.completed}
skipped={progress.skipped}
failed={progress.failed}
finished={isFinished}
showContinueButton={isFinished || this.isClosed}
finishProcessing={this.finish}
onClose={this.onUserClose}
/>
: <EvaluationProgress
isOpen={isOpen}
isOpen={isOpen && !isUserClosed}
completed={0}
skipped={100}
failed={0}
finished={false}
showContinueButton={true}
finishProcessing={this.finish}
onClose={this.onUserClose}
messages={List([
this.formatMessage({
command: 'TASK',
Expand Down
6 changes: 5 additions & 1 deletion src/redux/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const getMiddleware = history => [
storage.createMiddleware(
engine,
[],
[authActionTypes.LOGIN_SUCCESS, switchingActionTypes.REMOVE_USER]
[
authActionTypes.LOGIN_SUCCESS,
authActionTypes.LOGOUT,
switchingActionTypes.REMOVE_USER
]
)
];

Expand Down

0 comments on commit 57d01d7

Please sign in to comment.