From a3ab32f339614cae5b9e020e3dff216ff546215a Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Sat, 23 May 2015 00:53:41 -0700 Subject: [PATCH] improve get help and add find a pair --- app.js | 1 + controllers/resources.js | 24 +++++++++++++++++++++--- package.json | 1 + public/js/main.js | 26 ++++++++++++++++++++------ views/coursewares/showHTML.jade | 5 ++++- 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index e84b796a26..843aaa367f 100755 --- a/app.js +++ b/app.js @@ -228,6 +228,7 @@ app.get('/nonprofit-project-instructions', function(req, res) { app.post('/get-help', resourcesController.getHelp); +app.post('/get-pair', resourcesController.getPair); app.get('/chat', resourcesController.chat); diff --git a/controllers/resources.js b/controllers/resources.js index 20a99a2080..c3d71ac6bd 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -592,10 +592,28 @@ module.exports = { var challenge = req.body.payload.challenge; slack.send({ - text: "User " + userName + " needs help with challenge " + - "" + challenge + "!\n```\n" + code + "\n```", + text: "*" + userName + "* wants help with " + challenge + "\n```\n" + + code + "\n```\n Hey, *" + userName + "*, if no one helps you right " + + "away, try typing out your problem in detail to me. Like this: " + + "http://en.wikipedia.org/wiki/Rubber_duck_debugging", channel: '#help', - username: userName + username: "Debuggy the Rubber Duck", + icon_emoji: ":hatched_chick:" + }); + return res.sendStatus(200); + + }, + + getPair: function(req, res, next) { + var userName = req.user.profile.username; + var challenge = req.body.payload.challenge; + console.log('test'); + + slack.send({ + text: "Anyone want to pair with *" + userName + "* on " + challenge + "? (In the meantime, keep coding, *" + userName + "*)", + channel: '#letspair', + username: "Perry the Matchmaker", + icon_emoji: ":dancers:" }); return res.sendStatus(200); diff --git a/package.json b/package.json index 72dae9262c..1b5f3b319c 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "mongoose": "~4.0.1", "mongoose-long": "0.0.2", "morgan": "~1.5.0", + "node-slack": "0.0.7", "nodemailer": "~1.3.0", "passport": "~0.2.1", "passport-facebook": "~1.0.3", diff --git a/public/js/main.js b/public/js/main.js index 901182006a..9f2392fc00 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -16,26 +16,40 @@ $(document).ready(function() { setCSRFToken($('meta[name="csrf-token"]').attr('content')); - $('#i-need-help').on('click', function() { + $('#i-want-help').on('click', function() { var editorValue = editor.getValue(); - var currentLocation = window.location.href - console.log('clicked!'); + var currentLocation = window.location.href; $.post( '/get-help', { payload: { code: editorValue, + challenge: currentLocation, + } + }, + function(res) { + if (res) { + window.open('https://freecode.slack.com/messages/help/', '_blank') + } + } + ); + }); + + $('#i-want-to-pair').on('click', function() { + var currentLocation = window.location.href; + $.post( + '/get-pair', + { + payload: { challenge: currentLocation } }, function(res) { - console.log(res); if (res) { - window.location.href = 'https://freecode.slack.com/messages/help/' + window.open('https://freecode.slack.com/messages/letspair/', '_blank') } } ); - }); $('.checklist-element').each(function() { diff --git a/views/coursewares/showHTML.jade b/views/coursewares/showHTML.jade index 6f1d23338b..05dd0cbaa9 100644 --- a/views/coursewares/showHTML.jade +++ b/views/coursewares/showHTML.jade @@ -19,7 +19,6 @@ block content script(src='/js/lib/codemirror/mode/css/css.js') script(src='/js/lib/codemirror/mode/htmlmixed/htmlmixed.js') .row.courseware-height - .btn.btn-warning#i-need-help I need help! .col-xs-12.col-sm-12.col-md-3.col-lg-3 .well .row @@ -44,6 +43,10 @@ block content | Go to my next challenge br | (ctrl + enter) + .button-spacer + a.btn.btn-warning.btn-big.btn-block#i-want-help Get help + .button-spacer + a.btn.btn-success.btn-big.btn-block#i-want-to-pair Find a Pair script. var userLoggedIn = true; - else