summaryrefslogtreecommitdiff
path: root/bucky
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-15 06:52:54 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-15 06:52:54 +0100
commita1b33089877660ba33331d76281e68790f35ae44 (patch)
tree168692d34f8af123ef2bab505a3cdbe4d1d57229 /bucky
parent7ad469291c015b33a2d20587db26b9621ed82d00 (diff)
keywords list
Diffstat (limited to 'bucky')
-rw-r--r--bucky/app/bucky.js10
-rw-r--r--bucky/app/router.js13
-rw-r--r--bucky/db/index.js3
3 files changed, 24 insertions, 2 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 25de991..20bb2e5 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -151,7 +151,7 @@ var bucky = module.exports = {
if (keyword) {
keyword.set("threads", keyword.get("threads").toString())
keyword.set("ops", keyword.get("ops").toString())
- keyword.set("display", keyword.get("display").toString())
+ keyword.set("display", (keyword.get("display") || '').toString())
}
next()
})
@@ -196,7 +196,6 @@ var bucky = module.exports = {
if (! settings) {
return res.sendStatus(500)
}
-console.log(privacy)
res.thread.set('title', title)
res.thread.set('keyword', keyword)
res.thread.set('color', util.sanitize(req.body.color || 'blue'))
@@ -280,6 +279,12 @@ console.log(privacy)
next()
})
},
+ ensureThreadGroups: function (res, res, next){
+ db.getThreadGroups().then(function(threadGroups){
+ res.threadGroups = threadGroups
+ next()
+ })
+ },
ensureThreadsForKeyword: function (req, res, next){
var keyword = req.params.keyword
if (! keyword) {
@@ -415,6 +420,7 @@ console.log(privacy)
})
},
+
/* PROFILE / USER */
ensureUser: function (req, res, next){
diff --git a/bucky/app/router.js b/bucky/app/router.js
index e24253a..7df8fd2 100644
--- a/bucky/app/router.js
+++ b/bucky/app/router.js
@@ -29,6 +29,9 @@ module.exports = function(app){
hoot_text: fortune("hoots"),
})
})
+ app.get("/keywords", middleware.ensureAuthenticated, function(req, res){
+ res.render("pages/keywords", {})
+ })
app.get("/details/:id", middleware.ensureAuthenticated, function(req, res){
res.render("pages/details", {})
})
@@ -251,6 +254,16 @@ module.exports = function(app){
keywords: res.keywords,
})
})
+ app.get("/api/keywords/statistics",
+ middleware.ensureAuthenticated,
+ bucky.ensureKeywords,
+ bucky.ensureThreadGroups,
+ function(req, res){
+ res.json({
+ keywords: res.keywords,
+ threadGroups: res.threadGroups,
+ })
+ })
app.get("/api/keyword/:keyword",
middleware.ensureAuthenticated,
bucky.ensureKeyword,
diff --git a/bucky/db/index.js b/bucky/db/index.js
index f92ba2f..74ff788 100644
--- a/bucky/db/index.js
+++ b/bucky/db/index.js
@@ -220,6 +220,9 @@ db.getKeywords = function (keywords){
db.getKeyword = function (keyword) {
return Keyword.query("where", "keyword", "=", keyword).fetch()
}
+db.getThreadGroups = function (keyword) {
+ return knex.column('keyword').sum('viewed').as('viewed').column('id').column('title').column('lastmodified').column('privacy').select().from('threads').groupBy('keyword')
+}
db.createKeyword = function(data){
return new db.Keyword(data).save()
}