diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-09-06 12:07:22 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-09-06 12:07:22 -0400 |
| commit | 5e5cdd7e3758412851fffa56a9786ffa5d751e40 (patch) | |
| tree | 97b567ba0bfa1700a7db5b03d276bb9f4c108484 | |
| parent | abe12120374d07cf5f87192964a9d1c10741e475 (diff) | |
getting colors from keywords
| -rw-r--r-- | lib/bucky.js | 22 | ||||
| -rw-r--r-- | lib/db/index.js | 8 | ||||
| -rw-r--r-- | lib/index.js | 2 | ||||
| -rw-r--r-- | public/assets/css/bucky.css | 14 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/threadbox.js | 2 | ||||
| -rw-r--r-- | public/assets/js/util/format.js | 34 |
6 files changed, 78 insertions, 4 deletions
diff --git a/lib/bucky.js b/lib/bucky.js index ef6fbbc..9a43c0d 100644 --- a/lib/bucky.js +++ b/lib/bucky.js @@ -1,4 +1,5 @@ var db = require('./db') +var _ = require('lodash') var bucky = module.exports = { @@ -8,6 +9,7 @@ var bucky = module.exports = { db.getLatestThreads().then(function(threads){ res.threads = threads res.threads_ids = res.threads.pluck("id").sort() + res.keywords = _.uniq(res.threads.pluck("keyword")) next() }) }, @@ -33,6 +35,26 @@ var bucky = module.exports = { next() }) }, + ensureKeywordsForThreads: function (req, res, next){ + db.getKeywords(res.keywords).then(function(keywords){ + var lookup = {} + keywords.forEach(function(k){ + lookup[k.get('keyword')] = k + }) + console.log(keywords) + res.threads.forEach(function(t){ + var kw = t.get('keyword') + if (! kw) return + var k = lookup[kw] + if (! k) return + if (! t.get("color")) { + t.set("color", k.get("color")) + console.log(k.get("color")) + } + }) + next() + }) + }, ensureHootbox: function (req, res, next){ db.getCommentsForThread(1, 9).then(function(hootbox){ res.hootbox = hootbox diff --git a/lib/db/index.js b/lib/db/index.js index e7ad632..899abcc 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -67,6 +67,7 @@ db.getLatestThreads = function () { } /* FILES */ + db.getFilesForThread = function (id){ return File.query("where", "thread", "=", id).fetchAll() } @@ -78,6 +79,7 @@ db.getFileSizes = function(ids){ } /* COMMENTS */ + db.getCommentsForThread = function (id, limit, offset){ return Comment.query(function(qb){ qb.where("thread", "=", id).orderBy("id", "desc") @@ -98,6 +100,12 @@ db.getCommentCounts = function(ids){ return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') } +/* KEYWORDS */ +db.getKeywords = function (keywords){ + return Keyword.query("where", "keyword", "in", keywords).fetchAll() +} + + /* PRIVATE MESSAGES */ db.getMessage = function (id){ diff --git a/lib/index.js b/lib/index.js index ace34af..c1ded7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -87,7 +87,7 @@ site.route = function(){ bucky.ensureLatestThreads, bucky.ensureCommentCountsForThreads, bucky.ensureFileCountsForThreads, -// bucky.ensureFileSizeForThreads, + bucky.ensureKeywordsForThreads, bucky.ensureHootbox, bucky.ensureLastlog, function(req, res){ diff --git a/public/assets/css/bucky.css b/public/assets/css/bucky.css index d404fe8..7077308 100644 --- a/public/assets/css/bucky.css +++ b/public/assets/css/bucky.css @@ -142,7 +142,12 @@ hr { border-left: 1px solid #b6aeab; border-right: 1px solid #b6aeab; } .threads td:nth-child(3) { - padding-left: 10px; + padding-left: 20px; + padding-right: 10px; +} +.threads td:nth-child(4), +.threads td:nth-child(5) { + padding-right: 10px; } .threads tr:first-child td:nth-child(2) { border-top: 1px solid #b6aeab; @@ -209,3 +214,10 @@ tr:nth-child(odd) td.black { background-color: #ccc; border-bottom: 1px so tr:nth-child(odd) td.black:hover { background-color: #f8f8f8; color: #000000; border-bottom: 1px solid #aaa; } tr:nth-child(even) td.black { background-color: #eee; border-bottom: 1px solid #aaa; } tr:nth-child(even) td.black:hover { background-color: #f8f8f8; color: #000000; border-bottom: 1px solid #aaa; } + +.new { color: #000000; font-weight: bold; } +.recent { color: #001111; } +.med { color: #203838; } +.old { color: #425050; } +.older { color: #5D6464; } +.quiet { color: #787878; } diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js index 069f85d..2e7d211 100644 --- a/public/assets/js/lib/views/index/threadbox.js +++ b/public/assets/js/lib/views/index/threadbox.js @@ -33,7 +33,7 @@ var ThreadBox = View.extend({ .replace(/{{username}}/g, thread.username) .replace(/{{privacy_dot}}/g, dot) .replace(/{{title}}/g, thread.title) - .replace(/{{age}}/g, get_age(thread.lastmodified) ) + .replace(/{{age}}/g, verbose_date(thread.lastmodified) ) .replace(/{{age_class}}/g, carbon_date(thread.lastmodified) ) .replace(/{{views}}/g, views[1]) .replace(/{{comments}}/g, comments[1]) diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js index 7c773d4..90a19d2 100644 --- a/public/assets/js/util/format.js +++ b/public/assets/js/util/format.js @@ -21,8 +21,40 @@ function privacy_dot (p) { else return "·:" } +var short_months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ") +function verbose_date (date) { + var date = new Date(date * 1000) + var d = date.getDate() + var m = date.getMinutes() + var h = date.getHours() + var meridian + + if (h == 0) { + h = 12 + meridian = " am" + } + else if (h == 12) { + meridian = " pm" + } + else if (h > 12) { + h -= 12 + meridian = " pm" + } + else { + meridian = " am" + } + + if (d < 10) d = "0" + d + if (m < 10) m = "0" + m + if (h < 10) h = "0" + h + + var date = d + '-' + short_months[date.getMonth()] + '-' + date.getFullYear() + var time = h + ':' + m + meridian + + return date + " <small>" + time + "</small>" +} function carbon_date (date, no_bold) { - var span = (+new Date() - date * 1000) + var span = (+new Date() / 1000 - date) if (! no_bold && span < 86400) // modified today { color = "new" } else if (span < 604800) // modifed this week |
