From 8d6fc5338c98e26b1a685ec7c39abe20f591bcf2 Mon Sep 17 00:00:00 2001 From: Trevor Lyon Date: Thu, 2 Nov 2017 11:32:21 -0600 Subject: [PATCH] Pre Render and Edit Submission Fix 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. --- client/package-lock.json | 95 +++++++++++++++++++ client/package.json | 1 + client/src/components/NotebookFromHTML.jsx | 14 +++ .../src/components/submissions/Submission.js | 9 +- js/notifications.js | 9 ++ js/render.js | 10 +- routes/search/search.js | 1 - routes/submit/submit.js | 9 +- 8 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 client/src/components/NotebookFromHTML.jsx create mode 100644 js/notifications.js diff --git a/client/package-lock.json b/client/package-lock.json index c74b9de..20ed764 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -3888,6 +3888,11 @@ "version": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz", "integrity": "sha1-TekR5mew6ukSTjQlS1OupvxhjT4=" }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, "cosmiconfig": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-2.2.2.tgz", @@ -5341,6 +5346,11 @@ } } }, + "entities": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", + "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=" + }, "errno": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.4.tgz", @@ -13089,6 +13099,11 @@ "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=" }, + "process-nextick-args": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" + }, "progress": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", @@ -14024,6 +14039,42 @@ } } }, + "react-html-parser": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/react-html-parser/-/react-html-parser-2.0.1.tgz", + "integrity": "sha512-dTd0iK+DpcIJ68hVMQHXdG8qi0gzuPTCoqV3l2h+CFBEO4WEH7TmjIgjputJI8Ry95Tu9XTjGnyP5Z+MMl35Rw==", + "requires": { + "htmlparser2": "3.9.2" + }, + "dependencies": { + "domhandler": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.1.tgz", + "integrity": "sha1-iS5HAAqZvlW783dP/qBWHYh5wlk=", + "requires": { + "domelementtype": "1.3.0" + } + }, + "htmlparser2": { + "version": "3.9.2", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.9.2.tgz", + "integrity": "sha1-G9+HrMoPP55T+k/M6w9LTLsAszg=", + "requires": { + "domelementtype": "1.3.0", + "domhandler": "2.4.1", + "domutils": "1.5.1", + "entities": "1.1.1", + "inherits": "2.0.3", + "readable-stream": "2.3.3" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + } + } + }, "react-icon-base": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/react-icon-base/-/react-icon-base-2.1.0.tgz", @@ -15010,6 +15061,32 @@ } } }, + "readable-stream": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", + "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "safe-buffer": "5.1.1", + "string_decoder": "1.0.3", + "util-deprecate": "1.0.2" + }, + "dependencies": { + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + } + } + }, "readdirp": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.1.0.tgz", @@ -15585,6 +15662,11 @@ "symbol-observable": "1.0.4" } }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, "sane": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/sane/-/sane-1.6.0.tgz", @@ -16552,6 +16634,14 @@ } } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, "strip-eof": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", @@ -17678,6 +17768,11 @@ } } }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, "utila": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/utila/-/utila-0.4.0.tgz", diff --git a/client/package.json b/client/package.json index 41c9b1d..27a2669 100644 --- a/client/package.json +++ b/client/package.json @@ -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", diff --git a/client/src/components/NotebookFromHTML.jsx b/client/src/components/NotebookFromHTML.jsx new file mode 100644 index 0000000..20fd9cf --- /dev/null +++ b/client/src/components/NotebookFromHTML.jsx @@ -0,0 +1,14 @@ +import React, {Component} from 'react'; +import ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 } from 'react-html-parser'; + +class NotebookFromHTML extends Component { + render() { + return ( +
+ {ReactHtmlParser(this.props.html)} +
+ ) + } +} + +export default NotebookFromHTML \ No newline at end of file diff --git a/client/src/components/submissions/Submission.js b/client/src/components/submissions/Submission.js index 9416fe9..9cef423 100644 --- a/client/src/components/submissions/Submission.js +++ b/client/src/components/submissions/Submission.js @@ -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' @@ -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 { @@ -435,10 +437,7 @@ class Submission extends Component { {this.props.submission.data.html - ?
+ ? :
{ 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'); } }) } diff --git a/routes/search/search.js b/routes/search/search.js index b2ad795..9237271 100644 --- a/routes/search/search.js +++ b/routes/search/search.js @@ -251,7 +251,6 @@ app.get('/notebook/:nbid', isAuthenticated, function (req, res) { }); }); mergedReplyIDs = [].concat.apply([], replyIDs); - console.log('reply ids', replyIDs); callback(null, comments) } diff --git a/routes/submit/submit.js b/routes/submit/submit.js index 9b8d9b8..6628e50 100644 --- a/routes/submit/submit.js +++ b/routes/submit/submit.js @@ -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(); } @@ -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'