From 8685e31b578f63f7f527ad67275e9d600254391b Mon Sep 17 00:00:00 2001 From: David Erwin Date: Mon, 7 Nov 2016 15:31:12 -0500 Subject: [PATCH 01/27] Integrating webpack build files, working commit --- client/coral-admin/config.sample.json | 2 +- client/coral-admin/public/index.html | 2 +- client/coral-admin/webpack.config.dev.js | 10 +++++----- client/coral-admin/webpack.config.js | 10 +++++----- package.json | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/client/coral-admin/config.sample.json b/client/coral-admin/config.sample.json index f5b9ad5f8..55d39db05 100644 --- a/client/coral-admin/config.sample.json +++ b/client/coral-admin/config.sample.json @@ -1,3 +1,3 @@ { - "base": "client/coral-admin" + "basePath": "client/coral-admin" } diff --git a/client/coral-admin/public/index.html b/client/coral-admin/public/index.html index c31c22a6d..ef1adffec 100644 --- a/client/coral-admin/public/index.html +++ b/client/coral-admin/public/index.html @@ -17,6 +17,6 @@
- + diff --git a/client/coral-admin/webpack.config.dev.js b/client/coral-admin/webpack.config.dev.js index ca3b5cab5..421da4bb7 100644 --- a/client/coral-admin/webpack.config.dev.js +++ b/client/coral-admin/webpack.config.dev.js @@ -9,9 +9,9 @@ const config = require('./config.json') // doing a string replace here because I spent a day trying to do it the "webpack" way // ond nothing works. just trying to replace a string in an index.html file is // apparently something no one has ever done in the js community. -let templateString = fs.readFileSync('./index.ejs').toString() +let templateString = fs.readFileSync(path.join(__dirname, 'index.ejs')).toString() templateString = templateString.replace('<%= basePath %>', config.basePath) -fs.writeFileSync('./public/index.html', templateString) +fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) console.log(templateString) @@ -24,9 +24,9 @@ module.exports = { filename: '[name].js' }, module: { - loaders: [ - { test: /.js$/, loaders: 'buble', include: path.join(__dirname, 'src') }, - { test: /.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, + loader: [ + { test: /\.js$/, loaders: 'buble', include: path.join(__dirname, 'src') }, + { test: /\.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, { test: /\.css$/, loader: 'style-loader!css-loader?modules&importLoaders=1!postcss-loader' } ] }, diff --git a/client/coral-admin/webpack.config.js b/client/coral-admin/webpack.config.js index 67d5aef22..78585038a 100644 --- a/client/coral-admin/webpack.config.js +++ b/client/coral-admin/webpack.config.js @@ -10,15 +10,15 @@ const config = require('./config.json') // doing a string replace here because I spent a day trying to do it the "webpack" way // ond nothing works. just trying to replace a string in an index.html file is // apparently something no one has ever done in the js community. -let templateString = fs.readFileSync('./index.ejs').toString() +let templateString = fs.readFileSync(path.join(__dirname, 'index.ejs')).toString() templateString = templateString.replace('<%= basePath %>', config.basePath) -fs.writeFileSync('./public/index.html', templateString) +fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) module.exports = Object.assign({}, devConfig, { module: { - loaders: [ - { test: /.js$/, loaders: 'buble', include: [path.join(__dirname, 'src'), path.join(__dirname, '../', 'coral-framework')] }, - { test: /.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, + loader: [ + { test: /\.js$/, loaders: 'buble', include: [path.join(__dirname, 'src'), path.join(__dirname, '../', 'coral-framework')] }, + { test: /\.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, { test: /\.css$/, loader: 'style-loader!css-loader?modules&importLoaders=1!postcss-loader' } ] }, diff --git a/package.json b/package.json index 856db50c6..99ac9edfd 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "app.js", "scripts": { "start": "./bin/www", - "build": "webpack --config ./client/coral-embed-stream/webpack.config.js", + "build": "webpack --config ./client/coral-embed-stream/webpack.config.js && webpack --config ./client/coral-admin/webpack.config.js", "lint": "eslint .", "pretest": "npm install", "test": "mocha tests --recursive", From 018784d72522f9b10251c40a4b16d3b7e37b6770 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Mon, 7 Nov 2016 16:26:49 -0500 Subject: [PATCH 02/27] fix(coral-admin): building, no css --- client/coral-admin/package.json | 6 +++--- client/coral-admin/src/components/App.js | 8 ++++---- client/coral-admin/src/components/Header.js | 8 ++++---- .../coral-admin/src/containers/Configure.css | 5 ++++- client/coral-admin/webpack.config.dev.js | 20 ++++++------------- client/coral-admin/webpack.config.js | 19 ++++++------------ 6 files changed, 27 insertions(+), 39 deletions(-) diff --git a/client/coral-admin/package.json b/client/coral-admin/package.json index ced6a3512..048359526 100644 --- a/client/coral-admin/package.json +++ b/client/coral-admin/package.json @@ -26,8 +26,8 @@ }, "devDependencies": { "autoprefixer": "6.5.0", - "buble": "0.13.0", - "buble-loader": "0.3.0", + "babel-core": "^6.18.2", + "babel-loader": "^6.2.7", "copy-webpack-plugin": "3.0.1", "css-loader": "0.25.0", "json-loader": "0.5.4", @@ -36,7 +36,7 @@ "precss": "1.4.0", "standard": "8.2.0", "style-loader": "0.13.1", - "webpack": "2.1.0-beta.25", + "webpack": "^1.13.3", "webpack-dev-server": "1.16.1" } } diff --git a/client/coral-admin/src/components/App.js b/client/coral-admin/src/components/App.js index 545cd80a4..2c77fe900 100644 --- a/client/coral-admin/src/components/App.js +++ b/client/coral-admin/src/components/App.js @@ -20,10 +20,10 @@ export default class App extends React.Component {
- - - - + + + +
diff --git a/client/coral-admin/src/components/Header.js b/client/coral-admin/src/components/Header.js index 8aebe7864..ed8bfc9bd 100644 --- a/client/coral-admin/src/components/Header.js +++ b/client/coral-admin/src/components/Header.js @@ -9,14 +9,14 @@ export default (props) => (
- Moderate - Configure + Moderate + Configure
- Moderate - Configure + Moderate + Configure {props.children} diff --git a/client/coral-admin/src/containers/Configure.css b/client/coral-admin/src/containers/Configure.css index 2f98a8b99..2c65fd5bc 100644 --- a/client/coral-admin/src/containers/Configure.css +++ b/client/coral-admin/src/containers/Configure.css @@ -23,7 +23,10 @@ } .configSettingEmbed { - composes: configSetting; + border: 1px solid #ccc; + border-radius: 4px; + height: 90px; + margin-bottom: 10px; display: block; height: 170px; } diff --git a/client/coral-admin/webpack.config.dev.js b/client/coral-admin/webpack.config.dev.js index 421da4bb7..e8b0c86f0 100644 --- a/client/coral-admin/webpack.config.dev.js +++ b/client/coral-admin/webpack.config.dev.js @@ -24,25 +24,17 @@ module.exports = { filename: '[name].js' }, module: { - loader: [ - { test: /\.js$/, loaders: 'buble', include: path.join(__dirname, 'src') }, + loaders: [ + { test: /.js$/, loader: 'babel', include: path.join(__dirname, 'src'), exclude: /node_modules/ }, { test: /\.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, - { test: /\.css$/, loader: 'style-loader!css-loader?modules&importLoaders=1!postcss-loader' } + { test: /\.css$/, loaders: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader'] } ] }, - plugins: [ - new webpack.LoaderOptionsPlugin({ - options: { - context: __dirname, - postcss: [autoprefixer, precss] - } - }) - ], + plugins: [ autoprefixer, precss ], resolve: { - modules: [ + root: [ path.resolve('./src'), - path.resolve('../'), - 'node_modules' + path.resolve('../') ] }, devServer: { diff --git a/client/coral-admin/webpack.config.js b/client/coral-admin/webpack.config.js index 78585038a..1f3d81500 100644 --- a/client/coral-admin/webpack.config.js +++ b/client/coral-admin/webpack.config.js @@ -16,10 +16,11 @@ fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) module.exports = Object.assign({}, devConfig, { module: { - loader: [ - { test: /\.js$/, loaders: 'buble', include: [path.join(__dirname, 'src'), path.join(__dirname, '../', 'coral-framework')] }, - { test: /\.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, - { test: /\.css$/, loader: 'style-loader!css-loader?modules&importLoaders=1!postcss-loader' } + context: __dirname, + loaders: [ + { test: /.js$/, loader: 'babel', include: [path.join(__dirname, 'src'), path.join(__dirname, '../', 'coral-framework')], exclude: /node_modules/ }, + { test: /.json$/, loader: 'json', include: __dirname, exclude: /node_modules/ }, + { test: /.css$/, loaders: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader'] } ] }, plugins: [ @@ -27,14 +28,6 @@ module.exports = Object.assign({}, devConfig, { from: path.join(__dirname, '..', 'coral-embed-stream', 'dist'), to: './embed/comment-stream' }]), - new webpack.LoaderOptionsPlugin({ - options: { - context: __dirname, - postcss: [autoprefixer, precss], - minimize: true, - debug: false - } - }), - new webpack.optimize.UglifyJsPlugin() + autoprefixer, precss ] }) From 626687f05b92115d44e470e6c25650f874fbc13e Mon Sep 17 00:00:00 2001 From: gaba Date: Mon, 7 Nov 2016 14:18:43 -0800 Subject: [PATCH 03/27] Adds moderations queues. --- routes/api/comments/index.js | 57 +++++++++++++++++++++---- tests/routes/api/comments/index.js | 68 ++++++++++++++++++++++++++++++ tests/routes/api/stream/index.js | 1 - 3 files changed, 116 insertions(+), 10 deletions(-) diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 3acca5b3e..4753b0355 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -1,10 +1,11 @@ const express = require('express'); const Comment = require('../../../models/comment'); +const Action = require('../../../models/action'); const router = express.Router(); //============================================================================== -// Routes +// Get Routes //============================================================================== router.get('/', (req, res, next) => { @@ -23,6 +24,40 @@ router.get('/:comment_id', (req, res, next) => { }); }); +//============================================================================== +// Moderation Queues Routes +//============================================================================== + +router.get('/action/:action_type', (req, res, next) => { + Action.find({'action_type': req.params.action_type, 'item_type': 'comment'}).then((actions) => { + // search all the comments that are in actions by id: item_id + // populate user by user_id + res.status(200).json(actions); + }).catch(error => { + next(error); + }); +}); + +router.get('/status/rejected', (req, res, next) => { + Comment.find({'status': 'rejected'}).then((comments) => { + res.status(200).json(comments); + }).catch(error => { + next(error); + }); +}); + +router.get('/status/pending', (req, res, next) => { + Comment.find({'status': ''}).then((comments) => { + res.status(200).json(comments); + }).catch(error => { + next(error); + }); +}); + +//============================================================================== +// Post Routes +//============================================================================== + router.post('/', (req, res, next) => { const {body, author_id, asset_id, parent_id, status} = req.body; let comment = new Comment({body, author_id, asset_id, parent_id, status}); @@ -48,14 +83,6 @@ router.post('/:comment_id', (req, res, next) => { }); }); -router.delete('/:comment_id', (req, res, next) => { - Comment.remove(req.params.comment_id).then(() => { - res.status(201).send('OK. Deleted'); - }).catch(error => { - next(error); - }); -}); - router.post('/:comment_id/status', (req, res, next) => { Comment.changeStatus(req.params.comment_id, req.body.status).then((comment) => { res.status(200).send(comment); @@ -72,4 +99,16 @@ router.post('/:comment_id/actions', (req, res, next) => { }); }); +//============================================================================== +// Delete Routes +//============================================================================== + +router.delete('/:comment_id', (req, res, next) => { + Comment.remove(req.params.comment_id).then(() => { + res.status(201).send('OK. Deleted'); + }).catch(error => { + next(error); + }); +}); + module.exports = router; diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index 4fbe52e94..6416d1412 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -66,6 +66,74 @@ describe('Get /comments', () => { }); }); +describe('Get moderation queues rejected, pending', () => { + const comments = [{ + id: 'abc', + body: 'comment 10', + asset_id: 'asset', + author_id: '123', + status: 'rejected' + }, { + id: 'def', + body: 'comment 20', + asset_id: 'asset', + author_id: '456' + }, { + id: 'hij', + body: 'comment 30', + asset_id: '456', + status: 'accepted' + }]; + + const users = [{ + id: '123', + display_name: 'Ana', + }, { + id: '456', + display_name: 'Maria', + }]; + + const actions = [{ + action_type: 'flag', + item_id: 'abc' + }, { + action_type: 'like', + item_id: 'hij' + }]; + + beforeEach(() => { + return Comment.create(comments).then(() => { + return User.create(users); + }).then(() => { + return Action.create(actions); + }); + }); + + it('should return all the rejected comments', function(done){ + chai.request(app) + .get('/api/v1/comments/status/rejected') + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res.body[0]).to.have.property('id'); + expect(res.body[0].id).to.equal('abc'); + done(); + }); + }); + + it('should return all the pending comments', function(done){ + chai.request(app) + .get('/api/v1/comments/status/pending') + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res.body[0]).to.have.property('id'); + expect(res.body[0].id).to.equal('def'); + done(); + }); + }); +}); + describe('Post /comments', () => { const users = [{ id: '123', diff --git a/tests/routes/api/stream/index.js b/tests/routes/api/stream/index.js index 9744abb0c..b1348e88a 100644 --- a/tests/routes/api/stream/index.js +++ b/tests/routes/api/stream/index.js @@ -60,7 +60,6 @@ describe('api/stream: routes', () => { .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - if (err) {return done(err);} done(); }); }); From 0c04e765d683e97991845ff8fdce5e39f4887645 Mon Sep 17 00:00:00 2001 From: gaba Date: Mon, 7 Nov 2016 15:10:56 -0800 Subject: [PATCH 04/27] Moderation queue on flagged comments. --- routes/api/comments/index.js | 6 +++--- tests/routes/api/comments/index.js | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index f2166d34e..e1f3ab9c9 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -30,9 +30,9 @@ router.get('/:comment_id', (req, res, next) => { router.get('/action/:action_type', (req, res, next) => { Action.find({'action_type': req.params.action_type, 'item_type': 'comment'}).then((actions) => { - // search all the comments that are in actions by id: item_id - // populate user by user_id - res.status(200).json(actions); + Comment.find({'id': {'$in': actions.map(function(a){return a.item_id;})}}).exec(function(err, comments){ + res.status(200).json(comments); + }); }).catch(error => { next(error); }); diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index 6416d1412..9b43a97c4 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -66,7 +66,7 @@ describe('Get /comments', () => { }); }); -describe('Get moderation queues rejected, pending', () => { +describe('Get moderation queues rejected, pending, flags', () => { const comments = [{ id: 'abc', body: 'comment 10', @@ -95,10 +95,12 @@ describe('Get moderation queues rejected, pending', () => { const actions = [{ action_type: 'flag', - item_id: 'abc' + item_id: 'abc', + item_type: 'comment' }, { action_type: 'like', - item_id: 'hij' + item_id: 'hij', + item_type: 'comment' }]; beforeEach(() => { @@ -132,6 +134,19 @@ describe('Get moderation queues rejected, pending', () => { done(); }); }); + + it('should return all the flagged comments', function(done){ + chai.request(app) + .get('/api/v1/comments/action/flag') + .end(function(err, res){ + expect(res).to.have.status(200); + expect(err).to.be.null; + expect(res.body.length).to.equal(1); + expect(res.body[0]).to.have.property('id'); + expect(res.body[0].id).to.equal('abc'); + done(); + }); + }); }); describe('Post /comments', () => { @@ -196,10 +211,12 @@ describe('Get /:comment_id', () => { const actions = [{ action_type: 'flag', - item_id: 'abc' + item_id: 'abc', + item_type: 'comment' }, { action_type: 'like', - item_id: 'hij' + item_id: 'hij', + item_type: 'comment' }]; beforeEach(() => { From c8c82fd03b21bbcd4f44b5d331eea2bef850d3c8 Mon Sep 17 00:00:00 2001 From: gaba Date: Mon, 7 Nov 2016 18:10:17 -0800 Subject: [PATCH 05/27] Move all DB functions into models. Clean up tests. --- models/action.js | 28 +++++++++++++++- models/comment.js | 52 ++++++++++++++++++++++++++++++ routes/api/comments/index.js | 27 +++++++++------- tests/routes/api/comments/index.js | 22 ++++++------- 4 files changed, 103 insertions(+), 26 deletions(-) diff --git a/models/action.js b/models/action.js index 27c63747a..1d75c483c 100644 --- a/models/action.js +++ b/models/action.js @@ -28,7 +28,7 @@ ActionSchema.statics.findById = function(id) { }; /** - * Finds users in an array of ids. + * Finds actions in an array of ids. * @param {String} ids array of user identifiers (uuid) */ ActionSchema.statics.findByItemIdArray = function(item_ids) { @@ -37,6 +37,32 @@ ActionSchema.statics.findByItemIdArray = function(item_ids) { }); }; +/** + * Finds all comments for a specific action. + * @param {String} action_type type of action + * @param {String} item_type type of item the action is on +*/ +ActionSchema.statics.findByType = function(action_type, item_type) { + return Action.find({ + 'action_type': action_type, + 'item_type': item_type + }); +}; + +/** + * Finds all comments ids for a specific action. + * @param {String} action_type type of action + * @param {String} item_type type of item the action is on +*/ +ActionSchema.statics.findCommentsIdByActionType = function(action_type, item_type) { + return Action.find({ + 'action_type': action_type, + 'item_type': item_type + }, + 'item_id' + ); +}; + const Action = mongoose.model('Action', ActionSchema); module.exports = Action; diff --git a/models/comment.js b/models/comment.js index 6ddc3b0ee..3aad5d978 100644 --- a/models/comment.js +++ b/models/comment.js @@ -31,6 +31,23 @@ const CommentSchema = new Schema({ } }); +//============================================================================== +// New Statics +//============================================================================== + +/** + * Create a comment. + * @param {String} body content of comment +*/ +CommentSchema.statics.new = function(body, author_id, asset_id, parent_id, status, username) { + let comment = new Comment({body, author_id, asset_id, parent_id, status, username}); + return comment.save(); +}; + +//============================================================================== +// Find Statics +//============================================================================== + /** * Finds a comment by the id. * @param {String} id identifier of comment (uuid) @@ -47,6 +64,28 @@ CommentSchema.statics.findByAssetId = function(asset_id) { return Comment.find({asset_id}); }; +/** + * Find comments by an action that was performed on them. + * @param {String} action_type the type of action that was performed on the comment +*/ +CommentSchema.statics.findByActionType = function(action_type) { + return Action.findCommentsIdByActionType(action_type, 'comment').then((actions) => { + return Comment.find({'id': {'$in': actions.map(function(a){return a.item_id;})}}); + }); +}; + +/** + * Find comments by their status. + * @param {String} status the status to search for +*/ +CommentSchema.statics.findByStatus = function(status) { + return Comment.find({'status': status}); +}; + +//============================================================================== +// Update Statics +//============================================================================== + /** * Change the status of a comment. * @param {String} id identifier of the comment (uuid) @@ -72,6 +111,19 @@ CommentSchema.statics.addAction = function(id, user_id, action_type) { return action.save(); }; +//============================================================================== +// Remove Statics +//============================================================================== + +/** + * Change the status of a comment. + * @param {String} id identifier of the comment (uuid) + * @param {String} status the new status of the comment +*/ +CommentSchema.statics.removeById = function(id) { + return Comment.remove({'id': id}); +}; + const Comment = mongoose.model('Comment', CommentSchema); module.exports = Comment; diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index e1f3ab9c9..b3e2bdee7 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -1,6 +1,5 @@ const express = require('express'); const Comment = require('../../../models/comment'); -const Action = require('../../../models/action'); const router = express.Router(); @@ -29,17 +28,15 @@ router.get('/:comment_id', (req, res, next) => { //============================================================================== router.get('/action/:action_type', (req, res, next) => { - Action.find({'action_type': req.params.action_type, 'item_type': 'comment'}).then((actions) => { - Comment.find({'id': {'$in': actions.map(function(a){return a.item_id;})}}).exec(function(err, comments){ - res.status(200).json(comments); - }); + Comment.findByActionType(req.params.action_type).then((comments) => { + res.status(200).json(comments); }).catch(error => { next(error); }); }); router.get('/status/rejected', (req, res, next) => { - Comment.find({'status': 'rejected'}).then((comments) => { + Comment.findByStatus('rejected').then((comments) => { res.status(200).json(comments); }).catch(error => { next(error); @@ -47,7 +44,7 @@ router.get('/status/rejected', (req, res, next) => { }); router.get('/status/pending', (req, res, next) => { - Comment.find({'status': ''}).then((comments) => { + Comment.findByStatus('').then((comments) => { res.status(200).json(comments); }).catch(error => { next(error); @@ -60,12 +57,18 @@ router.get('/status/pending', (req, res, next) => { router.post('/', (req, res, next) => { const {body, author_id, asset_id, parent_id, status, username} = req.body; - let comment = new Comment({body, author_id, asset_id, parent_id, status, username}); - comment.save().then(({id}) => { - res.status(200).send({'id': id}); + Comment.new(body, author_id, asset_id, parent_id, status, username).then((comment) => { + res.status(200).send({'id': comment.id}); }).catch(error => { next(error); }); + + // let comment = new Comment({body, author_id, asset_id, parent_id, status, username}); + // comment.save().then(({id}) => { + // res.status(200).send({'id': id}); + // }).catch(error => { + // next(error); + // }); }); router.post('/:comment_id', (req, res, next) => { @@ -104,8 +107,8 @@ router.post('/:comment_id/actions', (req, res, next) => { //============================================================================== router.delete('/:comment_id', (req, res, next) => { - Comment.remove(req.params.comment_id).then(() => { - res.status(201).send('OK. Deleted'); + Comment.removeById(req.params.comment_id).then(() => { + res.status(201).send('OK. Removed'); }).catch(error => { next(error); }); diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index 9b43a97c4..eaf32adee 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -297,7 +297,7 @@ describe('Put /:comment_id', () => { }); }); -describe('Delete /:comment_id', () => { +describe('Remove /:comment_id', () => { const comments = [{ id: 'abc', @@ -343,9 +343,10 @@ describe('Delete /:comment_id', () => { chai.request(app) .delete('/api/v1/comments/abc') .end(function(err, res){ + expect(err).to.be.null; expect(res).to.have.status(201); - Comment.findById({'id': 'abc'}).then((comment) => { - expect(comment).to.be.null; + Comment.findById('abc').then((comment) => { + expect(comment).to.be.empty; }); done(); }); @@ -405,8 +406,7 @@ describe('Post /:comment_id/status', () => { expect(err).to.be.null; expect(res).to.have.status(200); expect(res).to.have.body; - expect(res.body).to.have.property('status'); - expect(res.body.status).to.equal('accepted'); + expect(res.body).to.have.property('status', 'accepted'); done(); }); }); @@ -465,14 +465,10 @@ describe('Post /:comment_id/actions', () => { expect(err).to.be.null; expect(res).to.have.status(200); expect(res).to.have.body; - expect(res.body).to.have.property('item_type'); - expect(res.body.item_type).to.equal('comment'); - expect(res.body).to.have.property('action_type'); - expect(res.body.action_type).to.equal('flag'); - expect(res.body).to.have.property('item_id'); - expect(res.body.item_id).to.equal('abc'); - expect(res.body).to.have.property('user_id'); - expect(res.body.user_id).to.equal('456'); + expect(res.body).to.have.property('item_type', 'comment'); + expect(res.body).to.have.property('action_type', 'flag'); + expect(res.body).to.have.property('item_id', 'abc'); + expect(res.body).to.have.property('user_id', '456'); done(); }); }); From 588a8de489869b08ad3c198539363a444db2d231 Mon Sep 17 00:00:00 2001 From: gaba Date: Mon, 7 Nov 2016 18:16:04 -0800 Subject: [PATCH 06/27] MOve two lines into one. --- tests/routes/api/settings/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/routes/api/settings/index.js b/tests/routes/api/settings/index.js index 8c2cd221e..985e0fe1c 100644 --- a/tests/routes/api/settings/index.js +++ b/tests/routes/api/settings/index.js @@ -24,8 +24,7 @@ describe('GET /settings', () => { expect(err).to.be.null; expect(res).to.have.status(200); expect(res).to.be.json; - expect(res.body).to.have.property('moderation'); - expect(res.body.moderation).to.equal('pre'); + expect(res.body).to.have.property('moderation', 'pre'); done(err); }); }); @@ -55,8 +54,7 @@ describe('update settings', () => { expect(err).to.be.null; expect(res).to.have.status(200); expect(res).to.be.json; - expect(res.body).to.have.property('moderation'); - expect(res.body.moderation).to.equal('post'); + expect(res.body).to.have.property('moderation', 'post'); }); }); }); From ed509ad36bb3c3e6eeabe55acd05a58dc0b75478 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 09:10:01 -0700 Subject: [PATCH 07/27] build from root. routes in coral-admin menu work --- client/coral-admin/index.ejs | 2 +- client/coral-admin/postcss.config.js | 7 ++ client/coral-admin/public/index.html | 2 +- client/coral-admin/src/components/App.js | 20 ++-- .../coral-admin/src/components/CommentList.js | 2 +- client/coral-admin/src/components/Header.js | 8 +- .../src/components/ModerationKeysModal.js | 6 +- client/coral-admin/src/components/Page.js | 12 +++ .../src/containers/CommentStream.js | 25 ++--- .../coral-admin/src/containers/Configure.js | 55 +++++------ .../src/containers/ModerationQueue.js | 92 ++++++++++--------- client/coral-admin/src/index.js | 2 +- client/coral-admin/webpack.config.dev.js | 5 +- package.json | 2 +- 14 files changed, 129 insertions(+), 111 deletions(-) create mode 100644 client/coral-admin/postcss.config.js create mode 100644 client/coral-admin/src/components/Page.js diff --git a/client/coral-admin/index.ejs b/client/coral-admin/index.ejs index 45c971ffe..9b5fe84bf 100644 --- a/client/coral-admin/index.ejs +++ b/client/coral-admin/index.ejs @@ -17,6 +17,6 @@
- + diff --git a/client/coral-admin/postcss.config.js b/client/coral-admin/postcss.config.js new file mode 100644 index 000000000..d5267160a --- /dev/null +++ b/client/coral-admin/postcss.config.js @@ -0,0 +1,7 @@ +module.exports = { + plugins: [ + require('postcss-smart-import')({ /* ...options */ }), + require('precss')({ /* ...options */ }), + require('autoprefixer')({ /* ...options */ }) + ] +} diff --git a/client/coral-admin/public/index.html b/client/coral-admin/public/index.html index e792fcd2c..ef1adffec 100644 --- a/client/coral-admin/public/index.html +++ b/client/coral-admin/public/index.html @@ -17,6 +17,6 @@
- + diff --git a/client/coral-admin/src/components/App.js b/client/coral-admin/src/components/App.js index 2c77fe900..4b7c01e84 100644 --- a/client/coral-admin/src/components/App.js +++ b/client/coral-admin/src/components/App.js @@ -1,11 +1,9 @@ import React from 'react' import { Provider } from 'react-redux' -import { Layout } from 'react-mdl' import 'material-design-lite' import { Router, Route, browserHistory } from 'react-router' import ModerationQueue from 'containers/ModerationQueue' -import Header from 'components/Header' import store from 'services/store' import CommentStream from 'containers/CommentStream' import EmbedLink from 'components/EmbedLink' @@ -16,18 +14,12 @@ export default class App extends React.Component { render (props) { return ( - -
-
- - - - - - -
-
-
+ + + + + +
) } diff --git a/client/coral-admin/src/components/CommentList.js b/client/coral-admin/src/components/CommentList.js index f56a1349f..02367911f 100644 --- a/client/coral-admin/src/components/CommentList.js +++ b/client/coral-admin/src/components/CommentList.js @@ -120,7 +120,7 @@ export default class CommentList extends React.Component { {commentIds.map((commentId, index) => ( { if (el && commentId === active) { this._active = el } }} - key={index} + key={index + 'comment'} index={index} onClickAction={this.onClickAction} actions={this.props.actions} diff --git a/client/coral-admin/src/components/Header.js b/client/coral-admin/src/components/Header.js index ed8bfc9bd..0e52686d8 100644 --- a/client/coral-admin/src/components/Header.js +++ b/client/coral-admin/src/components/Header.js @@ -9,14 +9,14 @@ export default (props) => (
- Moderate - Configure + Moderate + Configure
- Moderate - Configure + Moderate + Configure {props.children} diff --git a/client/coral-admin/src/components/ModerationKeysModal.js b/client/coral-admin/src/components/ModerationKeysModal.js index c28534417..efe235df7 100644 --- a/client/coral-admin/src/components/ModerationKeysModal.js +++ b/client/coral-admin/src/components/ModerationKeysModal.js @@ -28,8 +28,8 @@ export default ({ open, onClose }) => (

{lang.t('modqueue.shortcuts')}

- {shortcuts.map(shortcut => ( - + {shortcuts.map((shortcut, i) => ( +
@@ -37,7 +37,7 @@ export default ({ open, onClose }) => ( {Object.keys(shortcut.shortcuts).map(key => ( - + diff --git a/client/coral-admin/src/components/Page.js b/client/coral-admin/src/components/Page.js new file mode 100644 index 000000000..733cec677 --- /dev/null +++ b/client/coral-admin/src/components/Page.js @@ -0,0 +1,12 @@ +import React from 'react' +import {Layout} from 'react-mdl' +import 'material-design-lite' +import Header from 'components/Header' + +export default (props) => ( + +
+ {props.children} +
+
+) diff --git a/client/coral-admin/src/containers/CommentStream.js b/client/coral-admin/src/containers/CommentStream.js index 33963f422..4f0a03698 100644 --- a/client/coral-admin/src/containers/CommentStream.js +++ b/client/coral-admin/src/containers/CommentStream.js @@ -6,6 +6,7 @@ import { connect } from 'react-redux' import { createComment, flagComment } from 'actions/comments' import CommentList from 'components/CommentList' import CommentBox from 'components/CommentBox' +import Page from 'components/Page' /** * Renders a comment stream using a CommentList component @@ -43,17 +44,19 @@ class CommentStream extends React.Component { // Render the comment box along with the CommentList render ({ comments }, { snackbar, snackbarMsg }) { return ( -
- - - {snackbarMsg} -
+ +
+ + + {snackbarMsg} +
+
) } } diff --git a/client/coral-admin/src/containers/Configure.js b/client/coral-admin/src/containers/Configure.js index 02862cb8b..4a36e56e7 100644 --- a/client/coral-admin/src/containers/Configure.js +++ b/client/coral-admin/src/containers/Configure.js @@ -10,6 +10,7 @@ import { Button, Icon } from 'react-mdl' +import Page from 'components/Page' import styles from './Configure.css' class Configure extends React.Component { @@ -59,33 +60,35 @@ class Configure extends React.Component { : 'Embed Comment Stream' return ( -
-
- - - Comment Settings - - - Embed Comment Stream - - - + +
+
+ + + Comment Settings + + + Embed Comment Stream + + + +
+
+

{pageTitle}

+ { + this.state.activeSection === 'comments' + ? this.getCommentSettings() + : this.getEmbed() + } +
-
-

{pageTitle}

- { - this.state.activeSection === 'comments' - ? this.getCommentSettings() - : this.getEmbed() - } -
-
+ ) } } diff --git a/client/coral-admin/src/containers/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue.js index f80aac2e2..061786543 100644 --- a/client/coral-admin/src/containers/ModerationQueue.js +++ b/client/coral-admin/src/containers/ModerationQueue.js @@ -2,6 +2,7 @@ import React from 'react' import { connect } from 'react-redux' import ModerationKeysModal from 'components/ModerationKeysModal' +import Page from 'components/Page' import CommentList from 'components/CommentList' import { updateStatus } from 'actions/comments' import styles from './ModerationQueue.css' @@ -59,53 +60,56 @@ class ModerationQueue extends React.Component { render () { const { comments } = this.props const { activeTab, singleView, modalOpen } = this.state + console.log('moderation queue', styles) return ( -
-
- this.onTabClick('pending')} - className={`mdl-tabs__tab is-active ${styles.tab}`}>{lang.t('modqueue.pending')} - this.onTabClick('rejected')} - className={`mdl-tabs__tab ${styles.tab}`}>{lang.t('modqueue.rejected')} - this.onTabClick('flagged')} - className={`mdl-tabs__tab ${styles.tab}`}>{lang.t('modqueue.flagged')} + +
+ +
+ !comments.get('byId').get(id).get('status'))} + comments={comments.get('byId')} + onClickAction={(action, id) => this.onCommentAction(action, id)} + actions={['reject', 'approve']} + loading={comments.loading} /> +
+
+ comments.get('byId').get(id).get('status') === 'rejected')} + comments={comments.get('byId')} + onClickAction={(action, id) => this.onCommentAction(action, id)} + actions={['approve']} + loading={comments.loading} /> +
+
+ { + const data = comments.get('byId').get(id) + return !data.get('status') && data.get('flagged') === true + })} + comments={comments.get('byId')} + onClickAction={(action, id) => this.onCommentAction(action, id)} + actions={['reject', 'approve']} + loading={comments.loading} /> +
+ this.setState({ modalOpen: false })} />
-
- !comments.get('byId').get(id).get('status'))} - comments={comments.get('byId')} - onClickAction={(action, id) => this.onCommentAction(action, id)} - actions={['reject', 'approve']} - loading={comments.loading} /> -
-
- comments.get('byId').get(id).get('status') === 'rejected')} - comments={comments.get('byId')} - onClickAction={(action, id) => this.onCommentAction(action, id)} - actions={['approve']} - loading={comments.loading} /> -
-
- { - const data = comments.get('byId').get(id) - return !data.get('status') && data.get('flagged') === true - })} - comments={comments.get('byId')} - onClickAction={(action, id) => this.onCommentAction(action, id)} - actions={['reject', 'approve']} - loading={comments.loading} /> -
- this.setState({ modalOpen: false })} /> -
+ ) } } diff --git a/client/coral-admin/src/index.js b/client/coral-admin/src/index.js index 509473891..d15367dd0 100644 --- a/client/coral-admin/src/index.js +++ b/client/coral-admin/src/index.js @@ -1,7 +1,7 @@ import React from 'react' import ReactDOM from 'react-dom' -import App from 'components/App' +import App from './components/App' // Render the application into the DOM ReactDOM.render(, document.querySelector('#root')) diff --git a/client/coral-admin/webpack.config.dev.js b/client/coral-admin/webpack.config.dev.js index e8b0c86f0..bd5913b5a 100644 --- a/client/coral-admin/webpack.config.dev.js +++ b/client/coral-admin/webpack.config.dev.js @@ -1,7 +1,6 @@ const path = require('path') const fs = require('fs') -const webpack = require('webpack') const autoprefixer = require('autoprefixer') const precss = require('precss') const config = require('./config.json') @@ -13,8 +12,6 @@ let templateString = fs.readFileSync(path.join(__dirname, 'index.ejs')).toString templateString = templateString.replace('<%= basePath %>', config.basePath) fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) -console.log(templateString) - module.exports = { entry: { 'bundle': path.join(__dirname, 'src', 'index') @@ -27,7 +24,7 @@ module.exports = { loaders: [ { test: /.js$/, loader: 'babel', include: path.join(__dirname, 'src'), exclude: /node_modules/ }, { test: /\.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, - { test: /\.css$/, loaders: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader'] } + { test: /.css$/, loaders: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader'] } ] }, plugins: [ autoprefixer, precss ], diff --git a/package.json b/package.json index 2b6abf556..0c7aab592 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "app.js", "scripts": { "start": "./bin/www", - "build": "./node_modules/webpack/bin/webpack.js --config ./client/coral-embed-stream/webpack.config.js && ./node_modules/webpack/bin/webpack.js --config ./client/coral-admin/webpack.config.js", + "build": "./node_modules/webpack/bin/webpack.js --config ./client/coral-embed-stream/webpack.config.js && cd client/coral-admin && npm run build", "lint": "eslint .", "pretest": "npm install", "test": "mocha tests --recursive", From b10ae913abb4d768a5167468159ab488eed65807 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 10:07:41 -0700 Subject: [PATCH 08/27] fix a race condition in the tests --- tests/routes/api/settings/index.js | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tests/routes/api/settings/index.js b/tests/routes/api/settings/index.js index 8c2cd221e..eebab69c9 100644 --- a/tests/routes/api/settings/index.js +++ b/tests/routes/api/settings/index.js @@ -38,25 +38,30 @@ describe('update settings', () => { return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); }); - it('should respond to a PUT with new settings', () => { + it('should respond ok to a PUT', () => { chai.request(app) .put('/api/v1/settings') .send({moderation: 'post'}, (err, res) => { expect(err).to.be.null; expect(res).to.have.status(204); - done(err); + + if (err) { + return done(err); + } + + // confirm have updated settings + chai.request(app) + .get('/api/v1/settings') + .end((err, res) => { + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res).to.be.json; + expect(res.body).to.have.property('moderation'); + expect(res.body.moderation).to.equal('post'); + + done(err); + }); }); }); - it('should have updates settings', () => { - chai.request(app) - .get('/api/v1/settings') - .end((err, res) => { - expect(err).to.be.null; - expect(res).to.have.status(200); - expect(res).to.be.json; - expect(res.body).to.have.property('moderation'); - expect(res.body.moderation).to.equal('post'); - }); - }); }); From 411e6e48f3471ceb0a5b7c1b01184a45ec3240f7 Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 8 Nov 2016 12:28:09 -0500 Subject: [PATCH 09/27] Removing unused copy from build process. --- client/coral-admin/webpack.config.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/coral-admin/webpack.config.js b/client/coral-admin/webpack.config.js index 2c81bf4fc..8c224bcdb 100644 --- a/client/coral-admin/webpack.config.js +++ b/client/coral-admin/webpack.config.js @@ -23,10 +23,6 @@ module.exports = Object.assign({}, devConfig, { ] }, plugins: [ - new Copy([{ - from: path.join(__dirname, '..', 'coral-embed-stream', 'dist'), - to: './embed/comment-stream' - }]), autoprefixer, precss ] }) From 095f6a319eaf41396b62bea7d396c0fa897b55a1 Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 8 Nov 2016 10:38:49 -0700 Subject: [PATCH 10/27] remove the 2 requests in settings tests. add Promises --- tests/routes/api/settings/index.js | 38 +++++++++++------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/routes/api/settings/index.js b/tests/routes/api/settings/index.js index eebab69c9..f6d07c03e 100644 --- a/tests/routes/api/settings/index.js +++ b/tests/routes/api/settings/index.js @@ -34,34 +34,24 @@ describe('GET /settings', () => { // update the settings. describe('update settings', () => { - before(() => { - return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); - }); - it('should respond ok to a PUT', () => { - chai.request(app) - .put('/api/v1/settings') - .send({moderation: 'post'}, (err, res) => { - expect(err).to.be.null; - expect(res).to.have.status(204); + return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}) + .then(() => { + return chai.request(app) + .put('/api/v1/settings') + .send({moderation: 'post'}) + .then(res => { + expect(res).to.have.status(204); - if (err) { - return done(err); - } + return Setting.getSettings(); - // confirm have updated settings - chai.request(app) - .get('/api/v1/settings') - .end((err, res) => { - expect(err).to.be.null; - expect(res).to.have.status(200); - expect(res).to.be.json; - expect(res.body).to.have.property('moderation'); - expect(res.body.moderation).to.equal('post'); - - done(err); + }).then(settings => { + // confirm updated settings in db + expect(settings).to.have.property('moderation'); + expect(settings.moderation).to.equal('post'); + }).catch(err => { + throw err; }); }); }); - }); From 80754ee57b471092a840ccb2722f6a992b0b013f Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 8 Nov 2016 12:55:32 -0500 Subject: [PATCH 11/27] Updating build scripts for coral-admin --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c7aab592..2ee7de0ab 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "pretest": "npm install", "test": "mocha tests --recursive", "test-watch": "mocha tests --recursive -w", - "embed-start": "./node_modules/webpack/bin/webpack.js --config ./client/coral-embed-stream/webpack.config.dev.js && ./bin/www" + "embed-start": "npm run build && ./bin/www" }, "config": { "pre-git": { From ee33b8445b08b0dcb946761fbc95b2e63d15a82b Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 8 Nov 2016 12:56:22 -0500 Subject: [PATCH 12/27] Adding embed script to appropriate screen in settings. --- .../coral-admin/src/containers/Configure.js | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/containers/Configure.js b/client/coral-admin/src/containers/Configure.js index 4a36e56e7..f90e8c747 100644 --- a/client/coral-admin/src/containers/Configure.js +++ b/client/coral-admin/src/containers/Configure.js @@ -12,6 +12,8 @@ import { } from 'react-mdl' import Page from 'components/Page' import styles from './Configure.css' +import I18n from 'coral-framework/i18n/i18n' +import translations from '../translations' class Configure extends React.Component { constructor (props) { @@ -40,12 +42,28 @@ class Configure extends React.Component { } + copyToClipBoard (event) { + const copyTextarea = document.querySelector('.' + styles.embedInput) + copyTextarea.select() + + try { + document.execCommand('copy') + } catch (err) { + console.error('Unable to copy') + } + } + getEmbed () { + const embedText = + `
` + return

Copy and paste code below into your CMS to embed your comment box in your articles

- - + +
} @@ -94,3 +112,5 @@ class Configure extends React.Component { } export default connect(x => x)(Configure) + +const lang = new I18n(translations) From 7e720464812cc4268cabc0679bd8cfd0ac281d21 Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 8 Nov 2016 12:57:16 -0500 Subject: [PATCH 13/27] Adding npm install to build process for coral-admin so build works. --- client/coral-admin/config.sample.json | 3 --- client/coral-admin/package.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 client/coral-admin/config.sample.json diff --git a/client/coral-admin/config.sample.json b/client/coral-admin/config.sample.json deleted file mode 100644 index 55d39db05..000000000 --- a/client/coral-admin/config.sample.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "basePath": "client/coral-admin" -} diff --git a/client/coral-admin/package.json b/client/coral-admin/package.json index 048359526..f7217952e 100644 --- a/client/coral-admin/package.json +++ b/client/coral-admin/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "build": "./node_modules/.bin/webpack --config webpack.config.js", + "build": "npm install && ./node_modules/.bin/webpack --config webpack.config.js", "start": "./node_modules/.bin/webpack-dev-server --config webpack.config.dev.js --inline --hot --content-base public --port 3142" }, "keywords": [], From 242e64198ab4e705314a4dd770f2a7b3590a737a Mon Sep 17 00:00:00 2001 From: David Erwin Date: Tue, 8 Nov 2016 13:09:09 -0500 Subject: [PATCH 14/27] Add autoprefixer to dependencies --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0c7aab592..45470f3c8 100644 --- a/package.json +++ b/package.json @@ -42,12 +42,13 @@ }, "homepage": "https://github.com/coralproject/talk#readme", "dependencies": { + "autoprefixer": "^6.5.2", "body-parser": "^1.15.2", "debug": "^2.2.0", "express": "^4.14.0", "mongoose": "^4.6.5", - "uuid": "^2.0.3", - "morgan": "^1.7.0" + "morgan": "^1.7.0", + "uuid": "^2.0.3" }, "devDependencies": { "babel-core": "6.14.0", From a15d2eade7b0af71177b3afe80c0e8c2a6ca83e9 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 11:15:08 -0700 Subject: [PATCH 15/27] add ejs templating and serve coral-admin from /admin --- app.js | 7 +++++++ client/coral-admin/webpack.config.dev.js | 10 ---------- client/coral-admin/webpack.config.js | 9 --------- package.json | 5 +++-- client/coral-admin/index.ejs => views/admin.ejs | 0 5 files changed, 10 insertions(+), 21 deletions(-) rename client/coral-admin/index.ejs => views/admin.ejs (100%) diff --git a/app.js b/app.js index 838819e35..5d91243e8 100644 --- a/app.js +++ b/app.js @@ -3,11 +3,14 @@ const bodyParser = require('body-parser'); const morgan = require('morgan'); const path = require('path'); +const adminConfig = require('./client/coral-admin/config'); const app = express(); // Middleware declarations. app.use(morgan('dev')); app.use(bodyParser.json()); +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'ejs'); // API Routes. app.use('/api/v1', require('./routes/api')); @@ -15,4 +18,8 @@ app.use('/api/v1', require('./routes/api')); // Static Routes. app.use('/client/', express.static(path.join(__dirname, 'dist'))); +app.get('/admin/*', (req, res) => { + res.render('admin', {basePath: '/client/coral-admin'}); +}); + module.exports = app; diff --git a/client/coral-admin/webpack.config.dev.js b/client/coral-admin/webpack.config.dev.js index bd5913b5a..1eba29d66 100644 --- a/client/coral-admin/webpack.config.dev.js +++ b/client/coral-admin/webpack.config.dev.js @@ -1,16 +1,6 @@ - const path = require('path') -const fs = require('fs') const autoprefixer = require('autoprefixer') const precss = require('precss') -const config = require('./config.json') - -// doing a string replace here because I spent a day trying to do it the "webpack" way -// ond nothing works. just trying to replace a string in an index.html file is -// apparently something no one has ever done in the js community. -let templateString = fs.readFileSync(path.join(__dirname, 'index.ejs')).toString() -templateString = templateString.replace('<%= basePath %>', config.basePath) -fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) module.exports = { entry: { diff --git a/client/coral-admin/webpack.config.js b/client/coral-admin/webpack.config.js index 2c81bf4fc..10768b6e5 100644 --- a/client/coral-admin/webpack.config.js +++ b/client/coral-admin/webpack.config.js @@ -1,17 +1,8 @@ const path = require('path') -const fs = require('fs') const devConfig = require('./webpack.config.dev') const autoprefixer = require('autoprefixer') const precss = require('precss') const Copy = require('copy-webpack-plugin') -const config = require('./config.json') - -// doing a string replace here because I spent a day trying to do it the "webpack" way -// ond nothing works. just trying to replace a string in an index.html file is -// apparently something no one has ever done in the js community. -let templateString = fs.readFileSync(path.join(__dirname, 'index.ejs')).toString() -templateString = templateString.replace('<%= basePath %>', config.basePath) -fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) module.exports = Object.assign({}, devConfig, { module: { diff --git a/package.json b/package.json index 0c7aab592..bbd097221 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,11 @@ "dependencies": { "body-parser": "^1.15.2", "debug": "^2.2.0", + "ejs": "^2.5.2", "express": "^4.14.0", "mongoose": "^4.6.5", - "uuid": "^2.0.3", - "morgan": "^1.7.0" + "morgan": "^1.7.0", + "uuid": "^2.0.3" }, "devDependencies": { "babel-core": "6.14.0", diff --git a/client/coral-admin/index.ejs b/views/admin.ejs similarity index 100% rename from client/coral-admin/index.ejs rename to views/admin.ejs From b6355b06db8f95c1359c980acc3324b2ffed5e02 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 11:24:46 -0700 Subject: [PATCH 16/27] remove unused var --- app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app.js b/app.js index 5d91243e8..76dba1c1a 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,6 @@ const bodyParser = require('body-parser'); const morgan = require('morgan'); const path = require('path'); -const adminConfig = require('./client/coral-admin/config'); const app = express(); // Middleware declarations. From ed01d5441813160104789bd280863cc2c700826c Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 8 Nov 2016 10:23:59 -0800 Subject: [PATCH 17/27] It fixes random test on get comment by comment_id. --- tests/routes/api/comments/index.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index eaf32adee..378860bcb 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -117,8 +117,7 @@ describe('Get moderation queues rejected, pending, flags', () => { .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - expect(res.body[0]).to.have.property('id'); - expect(res.body[0].id).to.equal('abc'); + expect(res.body[0]).to.have.property('id', 'abc'); done(); }); }); @@ -129,8 +128,7 @@ describe('Get moderation queues rejected, pending, flags', () => { .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - expect(res.body[0]).to.have.property('id'); - expect(res.body[0].id).to.equal('def'); + expect(res.body[0]).to.have.property('id', 'def'); done(); }); }); @@ -142,8 +140,7 @@ describe('Get moderation queues rejected, pending, flags', () => { expect(res).to.have.status(200); expect(err).to.be.null; expect(res.body.length).to.equal(1); - expect(res.body[0]).to.have.property('id'); - expect(res.body[0].id).to.equal('abc'); + expect(res.body[0]).to.have.property('id', 'abc'); done(); }); }); @@ -229,13 +226,12 @@ describe('Get /:comment_id', () => { it('should return the right comment for the comment_id', function(done){ chai.request(app) - .get('/api/v1/comments') - .query({'comment_id': 'abc'}) + .get('/api/v1/comments/abc') .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - expect(res.body[0]).to.have.property('body'); - expect(res.body[0].body).to.equal('comment 10'); + expect(res).to.have.property('body'); + expect(res.body).to.have.property('body', 'comment 10'); done(); }); }); @@ -290,8 +286,7 @@ describe('Put /:comment_id', () => { .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - expect(res.body).to.have.property('body'); - expect(res.body.body).to.equal('Something body.'); + expect(res.body).to.have.property('body', 'Something body.'); done(); }); }); From 6f6da144015a956e360125aa5dd034c61da2ca80 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 11:27:47 -0700 Subject: [PATCH 18/27] fix build script a bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbd097221..ee92db73f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "app.js", "scripts": { "start": "./bin/www", - "build": "./node_modules/webpack/bin/webpack.js --config ./client/coral-embed-stream/webpack.config.js && cd client/coral-admin && npm run build", + "build": "./node_modules/webpack/bin/webpack.js --config ./client/coral-embed-stream/webpack.config.js && cd client/coral-admin && npm install && npm run build", "lint": "eslint .", "pretest": "npm install", "test": "mocha tests --recursive", From 80f1f70a2a76f3662b3623df79412390b873ed20 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 12:03:49 -0700 Subject: [PATCH 19/27] hardcode routes in react app --- client/coral-admin/.gitignore | 1 - client/coral-admin/config.json | 5 +++++ client/coral-admin/src/components/App.js | 9 ++++----- client/coral-admin/src/components/Header.js | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 client/coral-admin/config.json diff --git a/client/coral-admin/.gitignore b/client/coral-admin/.gitignore index c9c7cb580..707c890e5 100644 --- a/client/coral-admin/.gitignore +++ b/client/coral-admin/.gitignore @@ -3,5 +3,4 @@ public/bundle.js public/embed/comment-stream .DS_Store npm-debug.log -config.json yarn.lock diff --git a/client/coral-admin/config.json b/client/coral-admin/config.json new file mode 100644 index 000000000..c8f318cfc --- /dev/null +++ b/client/coral-admin/config.json @@ -0,0 +1,5 @@ +{ + "basePath": "admin", + "talkHost": "http://localhost:16180", + "xeniaHost": "http://localhost:16180" +} diff --git a/client/coral-admin/src/components/App.js b/client/coral-admin/src/components/App.js index 4b7c01e84..81eea850f 100644 --- a/client/coral-admin/src/components/App.js +++ b/client/coral-admin/src/components/App.js @@ -8,17 +8,16 @@ import store from 'services/store' import CommentStream from 'containers/CommentStream' import EmbedLink from 'components/EmbedLink' import Configure from 'containers/Configure' -import config from 'services/config' export default class App extends React.Component { render (props) { return ( - - - - + + + + ) diff --git a/client/coral-admin/src/components/Header.js b/client/coral-admin/src/components/Header.js index 0e52686d8..ea268108e 100644 --- a/client/coral-admin/src/components/Header.js +++ b/client/coral-admin/src/components/Header.js @@ -9,14 +9,14 @@ export default (props) => (
- Moderate - Configure + Moderate + Configure
- Moderate - Configure + Moderate + Configure {props.children} From c7cf2785fd841a1919dbb5ec0c5171b4047f3ea5 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Mon, 7 Nov 2016 21:36:52 -0500 Subject: [PATCH 20/27] Update README --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d295ef326..f3a2d55fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # Talk [![CircleCI](https://circleci.com/gh/coralproject/talk.svg?style=svg)](https://circleci.com/gh/coralproject/talk) A commenting platform from The Coral Project. [https://coralproject.net](https://coralproject.net) +## Contributing to Talk + +### Local Dependencies +Node +Mongo + ### Getting Started `npm install` Run it once to install the dependencies. @@ -8,16 +14,21 @@ Run it once to install the dependencies. `npm start` Runs Talk. +### Running with Docker +Make sure you have Docker running first and then run `docker-compose up -d` + ### Testing `npm test` ### Lint `npm run lint` +### Helpful URLs +Bare comment stream: http://localhost:5000/client/coral-embed-stream/ +Comment stream embedded on sample article: http://localhost:5000/client/coral-embed-stream/samplearticle.html + ### Docs `swagger.yaml` -### Mantainers - ### License **Apache-2.0** From e3074892ce8e1870cc7097245e58261f27c2ed97 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Tue, 8 Nov 2016 11:56:55 -0500 Subject: [PATCH 21/27] Add moderator view URL --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f3a2d55fc..3408c9f11 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Make sure you have Docker running first and then run `docker-compose up -d` ### Helpful URLs Bare comment stream: http://localhost:5000/client/coral-embed-stream/ Comment stream embedded on sample article: http://localhost:5000/client/coral-embed-stream/samplearticle.html +Moderator view: http://localhost:5000/client/coral-admin/ ### Docs `swagger.yaml` From db66c66f3da9a84d162ce4ce9c97282273f57d77 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Tue, 8 Nov 2016 14:23:24 -0500 Subject: [PATCH 22/27] Update admin route --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3408c9f11..103910d77 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ Make sure you have Docker running first and then run `docker-compose up -d` `npm run lint` ### Helpful URLs -Bare comment stream: http://localhost:5000/client/coral-embed-stream/ +Bare comment stream: http://localhost:5000/client/coral-embed-stream Comment stream embedded on sample article: http://localhost:5000/client/coral-embed-stream/samplearticle.html -Moderator view: http://localhost:5000/client/coral-admin/ +Moderator view: http://localhost:5000/admin ### Docs `swagger.yaml` From ff42d571e6396bbb8311f1d04a69af71c8240cda Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Tue, 8 Nov 2016 14:25:53 -0500 Subject: [PATCH 23/27] Add trailing slashes to URLs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 103910d77..f4d8b31de 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ Make sure you have Docker running first and then run `docker-compose up -d` `npm run lint` ### Helpful URLs -Bare comment stream: http://localhost:5000/client/coral-embed-stream +Bare comment stream: http://localhost:5000/client/coral-embed-stream/ Comment stream embedded on sample article: http://localhost:5000/client/coral-embed-stream/samplearticle.html -Moderator view: http://localhost:5000/admin +Moderator view: http://localhost:5000/admin/ ### Docs `swagger.yaml` From c609e5b3bb5541dd5b0f9a7fa8a587372c4e5a61 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 12:35:37 -0700 Subject: [PATCH 24/27] enable css modules --- client/coral-admin/webpack.config.dev.js | 2 +- client/coral-admin/webpack.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/webpack.config.dev.js b/client/coral-admin/webpack.config.dev.js index 1eba29d66..e4d771e72 100644 --- a/client/coral-admin/webpack.config.dev.js +++ b/client/coral-admin/webpack.config.dev.js @@ -14,7 +14,7 @@ module.exports = { loaders: [ { test: /.js$/, loader: 'babel', include: path.join(__dirname, 'src'), exclude: /node_modules/ }, { test: /\.json$/, loaders: 'json', include: __dirname, exclude: /node_modules/ }, - { test: /.css$/, loaders: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader'] } + { test: /.css$/, loaders: ['style-loader', 'css-loader?modules&localIdentName=[name]__[local]___[hash:base64:5]', 'postcss-loader'] } ] }, plugins: [ autoprefixer, precss ], diff --git a/client/coral-admin/webpack.config.js b/client/coral-admin/webpack.config.js index 10768b6e5..1b6fc0962 100644 --- a/client/coral-admin/webpack.config.js +++ b/client/coral-admin/webpack.config.js @@ -10,7 +10,7 @@ module.exports = Object.assign({}, devConfig, { loaders: [ { test: /.js$/, loader: 'babel', include: [path.join(__dirname, 'src'), path.join(__dirname, '../', 'coral-framework')], exclude: /node_modules/ }, { test: /.json$/, loader: 'json', include: __dirname, exclude: /node_modules/ }, - { test: /.css$/, loaders: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader'] } + { test: /.css$/, loaders: ['style-loader', 'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]', 'postcss-loader'] } ] }, plugins: [ From 6c9e31c52d6fa7ca9a0f92bbc45dfdb2e7a8639e Mon Sep 17 00:00:00 2001 From: David Erwin Date: Tue, 8 Nov 2016 14:36:40 -0500 Subject: [PATCH 25/27] Drop trailing slash requirement on admin route --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 76dba1c1a..d4041c93a 100644 --- a/app.js +++ b/app.js @@ -17,7 +17,7 @@ app.use('/api/v1', require('./routes/api')); // Static Routes. app.use('/client/', express.static(path.join(__dirname, 'dist'))); -app.get('/admin/*', (req, res) => { +app.get('/admin*', (req, res) => { res.render('admin', {basePath: '/client/coral-admin'}); }); From 1874206dd76514534795961939a68a9c5f698e4a Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 12:38:16 -0700 Subject: [PATCH 26/27] update root package.json --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index bb62d4ca3..df096877d 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "uuid": "^2.0.3" }, "devDependencies": { + "autoprefixer": "6.5.0", "babel-core": "6.14.0", "babel-jest": "^15.0.0", "babel-loader": "6.2.5", @@ -66,6 +67,7 @@ "chai": "^3.5.0", "chai-http": "^3.0.0", "copy-webpack-plugin": "^3.0.1", + "css-loader": "0.25.0", "eslint": "^3.9.1", "exports-loader": "^0.6.3", "immutable": "^3.8.1", @@ -73,6 +75,9 @@ "json-loader": "^0.5.4", "mocha": "^3.1.2", "mocha-junit-reporter": "^1.12.1", + "postcss-loader": "0.13.0", + "postcss-modules": "0.5.2", + "precss": "1.4.0", "pre-git": "^3.10.0", "pym.js": "^1.1.1", "react": "15.3.2", @@ -81,6 +86,7 @@ "redux": "^3.6.0", "redux-thunk": "^2.1.0", "regenerator": "^0.8.46", + "style-loader": "0.13.1", "supertest": "^2.0.1", "timeago.js": "^2.0.3", "webpack": "^1.13.2", From 661b402351c6a7eff9e7549762af39bc6f28e84b Mon Sep 17 00:00:00 2001 From: David Erwin Date: Tue, 8 Nov 2016 14:53:28 -0500 Subject: [PATCH 27/27] Remove npm install from coral-admin build --- client/coral-admin/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-admin/package.json b/client/coral-admin/package.json index f7217952e..048359526 100644 --- a/client/coral-admin/package.json +++ b/client/coral-admin/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "build": "npm install && ./node_modules/.bin/webpack --config webpack.config.js", + "build": "./node_modules/.bin/webpack --config webpack.config.js", "start": "./node_modules/.bin/webpack-dev-server --config webpack.config.dev.js --inline --hot --content-base public --port 3142" }, "keywords": [],
{lang.t(shortcut.title)}
{key} {lang.t(shortcut.shortcuts[key])}