Skip to content

Commit

Permalink
new page for related questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj Singh committed Dec 8, 2016
1 parent 0eb157e commit 755009a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 39 deletions.
2 changes: 2 additions & 0 deletions stackoverflow-status/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var cloudant = Cloudant({account:cloudant_username, password: cloudant_password}
// console.log('CLOUDANT:');console.log(cloudant);

var index = require('./routes/index');
var related = require('./routes/related');

var app = express();

Expand All @@ -48,6 +49,7 @@ app.use(function(req,res,next){
});

app.use('/', index);
app.use('/related', related);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
3 changes: 2 additions & 1 deletion stackoverflow-status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"express": "~4.14.0",
"jade": "~1.11.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
"serve-favicon": "~2.3.0",
"request": "^2.79.0"
}
}
27 changes: 27 additions & 0 deletions stackoverflow-status/routes/related.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var express = require('express');
var router = express.Router();
var request = require('request');

/* GET home page. */
router.get('/', function(req, res, next) {
var relurl = "https://api.stackexchange.com/2.2/similar?";
relurl += "order=desc&sort=relevance&site=stackoverflow";
relurl += "&title=" + encodeURIComponent(req.query.title);
if (req.query.tags) relurl += "&tags=" + req.query.tags;
// relurl = "http://localhost:3000/test.json";
console.log("relurl: "+relurl);

request({url:relurl, json:true, gzip:true}, function (error, response, body) {
if (!error && response.statusCode == 200) {
// pass data to view
console.log("GOT GOOD BODY:");
console.log(body);
res.render('related', { relatedqs: body, title: req.query.title });
} else {
res.send("Couldn't get Stackoverflow related questions:\n"+error);
}
})

});

module.exports = router;
75 changes: 38 additions & 37 deletions stackoverflow-status/views/index.jade
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
extends layout

block content
div.container
div.row
div.col.s12
h1 Stackoverflow Status
div.row
div.col.s12
h5.subhead Questions without an accepted answer, tagged any of:

h5.subhead Questions without an accepted answer, tagged any of:
- var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
- var searchwords = search.split(',').map(Function.prototype.call, String.prototype.trim);
p
each w in searchwords
a.so-tag.waves-effect.waves-light.btn.blue(onclick='javascript:toggleTagVisibility(this)')= w
hr

- var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
- var searchwords = search.split(',').map(Function.prototype.call, String.prototype.trim);
p
each w in searchwords
a.so-tag.waves-effect.waves-light.btn.blue(onclick='javascript:toggleTagVisibility(this)')= w
hr
div.row.so-questions
each q in questions
- qdate = new Date(q.value.creation_date * 1000)
- qprettydate = qdate.getDate() + ' ' + monthNames[qdate.getMonth()] + ' ' + qdate.getFullYear();

div.row.so-questions
each q in questions
- qdate = new Date(q.value.creation_date * 1000)
- qprettydate = qdate.getDate() + ' ' + monthNames[qdate.getMonth()] + ' ' + qdate.getFullYear();
- relurl = "/related?title=" + q.value.title + "&tags="
each tag in q.value.tags
- relurl += tag + ";"

div.col.s12.m6.l4.questioncol.notdisplayed
div.card.sticky-action.small.question.z-depth-4
div.card-content
i.material-icons.right.activator(role="button")= "more_vert"
h5.activator.questiontitle
:verbatim !{q.value.title}
p.grey-text.date= qprettydate
hr.blue-text
div.tags
each tag in q.value.tags
span.tag.chip.small.blue= tag.toString()
div.card-action
a.pink-text(href=q.value.link, target="_blank" title="View on SO")
i.material-icons.small= "open_in_browser"
span.answercount.badge.right.white-text.pink(title="answers")= q.value.answer_count
div.card-reveal
span.card-title.grey-text= "Details"
i.material-icons.right(role="button")= "close"
div.grey-text
:verbatim !{q.value.body}


div.col.s12.m6.l4.questioncol.notdisplayed
div.card.sticky-action.small.question.z-depth-4
div.card-content
i.material-icons.right.activator(role="button")= "more_vert"
h5.activator.questiontitle
:verbatim !{q.value.title}
p.grey-text.date= qprettydate
hr.blue-text
div.tags
each tag in q.value.tags
span.tag.chip.small.blue= tag.toString()
div.card-action
a.pink-text(href=q.value.link, target="_blank" title="View on SO")
i.material-icons.small= "open_in_browser"
a.pink-text(href=relurl, title="Related questions")
i.material-icons.small= "question_answer"
span.answercount.badge.right.white-text.pink(title="answers")= q.value.answer_count
div.card-reveal
span.card-title.grey-text= "Details"
i.material-icons.right(role="button")= "close"
div.grey-text
:verbatim !{q.value.body}
10 changes: 9 additions & 1 deletion stackoverflow-status/views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ html
link(rel='stylesheet', href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css')
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
div.container
div.row
div.col.s12
div.right= "content from "
a(href="http://stackoverflow.com/" target="_blank")= "StackOverflow"
h1 Stackoverflow Status

block content

script(src='https://code.jquery.com/jquery-2.1.1.min.js')
script(src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js')
script(src='js/filter.js')
Expand Down
26 changes: 26 additions & 0 deletions stackoverflow-status/views/related.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends layout

block content
div.row
div.col.s12
div= "Questions related to:"
h5.subhead= title

hr

div.row.so-related
each q in relatedqs.items
div.col.s12.m6.l4.relcol
div.card.small.z-depth-4.relq
div.card-content
h5.questiontitle
a(href=q.link, target="_blank" title="View on SO")
:verbatim !{q.title}
div.tags
each tag in q.tags
span.tag.chip.small.grey= tag.toString()
div.card-action
a.pink-text(href=q.link, target="_blank" title="View on SO")
i.material-icons.small= "open_in_browser"
span.answercount.badge.right.white-text.pink(title="answers")= q.answer_count

0 comments on commit 755009a

Please sign in to comment.