Skip to content

Commit

Permalink
Pre Render and Edit Submission Fix
Browse files Browse the repository at this point in the history
Pre Rendering support implemented with option to turn it on and off.

Fixed issue with the notebook not being updated when a user tries to edit a submission.
  • Loading branch information
tlyon3 committed Nov 2, 2017
1 parent 84b1f9d commit 8d6fc53
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 13 deletions.
95 changes: 95 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react-bootstrap": "^0.31.0",
"react-dom": "^16.0.0",
"react-dropzone": "^4.2.0",
"react-html-parser": "^2.0.1",
"react-icons": "^2.2.5",
"react-markdown": "^2.5.0",
"react-modal": "^3.0.0",
Expand Down
14 changes: 14 additions & 0 deletions client/src/components/NotebookFromHTML.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, {Component} from 'react';
import ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 } from 'react-html-parser';

class NotebookFromHTML extends Component {
render() {
return (
<div>
{ReactHtmlParser(this.props.html)}
</div>
)
}
}

export default NotebookFromHTML
9 changes: 4 additions & 5 deletions client/src/components/submissions/Submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Markdown from 'react-markdown';
import Time from 'react-time';
import {Link} from 'react-router-dom'
import Modal from 'react-modal'
import renderHTML from 'react-render-html'
import ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 } from 'react-html-parser';


import 'normalize-css'
import 'typeface-source-code-pro'
Expand All @@ -30,6 +31,7 @@ import DeleteIcon from 'react-icons/lib/md/delete';
import HeadContainer from '../../containers/HeadContainer';
import CommentsThread from '../comments/CommentsThread'
import Breadcrumbs from '../partials/Breadcrumbs'
import NotebookFromHTML from '../NotebookFromHTML';

class Submission extends Component {

Expand Down Expand Up @@ -435,10 +437,7 @@ class Submission extends Component {
</div>

{this.props.submission.data.html
? <div
dangerouslySetInnerHTML={{
__html: this.props.submission.data.html
}}></div>
? <NotebookFromHTML html={this.props.submission.data.html}/>
: <div id='notebook'>
<NotebookPreview
notebook={this.props.submission.data.notebookJSON}
Expand Down
9 changes: 9 additions & 0 deletions js/notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function sendEmail(to, message){

}

function addNotifcation(to, message){

}

module.exports = [sendEmail, addNotifcation]
10 changes: 5 additions & 5 deletions js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ var fs = require('fs');
postfix: '.json'
});

console.log('tmpObj: ', tmpObj);
console.log('Output dir: ', outputDir);
console.log('\ttmpObj: ', tmpObj);
console.log('\tOutput dir: ', outputDir);

fs.writeFileSync(tmpObj.name, json);

var command = sprintf('jupyter nbconvert %s --output=%s --output-dir=%s --template=%s', tmpObj.name, outputName, outputDir, templateLocation);

console.log('Execute command');
console.log('\tExecute command');
exec(command, {
maxBuffer: 1024*500
}, (err, stdout, stderr) => {
if(err){
console.log('Error executing command: ', err);
console.log('\tError executing command: ', err);
return {error: err}
} else {
console.log('No error executing command');
console.log('\tNo error executing command');
}
})
}
Expand Down
1 change: 0 additions & 1 deletion routes/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ app.get('/notebook/:nbid', isAuthenticated, function (req, res) {
});
});
mergedReplyIDs = [].concat.apply([], replyIDs);
console.log('reply ids', replyIDs);

callback(null, comments)
}
Expand Down
9 changes: 7 additions & 2 deletions routes/submit/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,17 @@ app.post('/edit-submission', passport.authenticate('jwt', {
Submission.findById(req.body.submissionData._id, (err, submission) => {
if (err) {
res.status(500);
console.log("Error finding submission: ", err);
res.send({
error: err
});
} else if (submission) {
//TODO:
submission.notebookJSON = JSON.stringify(req.body.submissionData.notebookJSON);
submission.notebookJSONString = JSON.stringify(req.body.submissionData.notebookJSON);
// TODO insert pre-render support here========================================
if (config.preRender) {
var filePath = renderer.renderHTMLFromJSON(submission.notebookJSONString, submission._id);
console.log("Pre-rendering submission...");
var filePath = renderer.renderHTMLFromJSON(submission.notebookJSON, submission._id);
submission.htmlFilePath = filePath;
submission.save();
}
Expand All @@ -259,15 +261,18 @@ app.post('/edit-submission', passport.authenticate('jwt', {

submission.save((err) => {
if (err) {
console.log('Error saving submission: ', err)
res.status(500);
res.send({
error: err
});
} else {
console.log('Submission saved!')
res.sendStatus(200);
}
});
} else {
console.log("Couldn't find submission");
res.status(500);
res.send({
error: 'Coulnd\'t find submission'
Expand Down

0 comments on commit 8d6fc53

Please sign in to comment.