summaryrefslogtreecommitdiff
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
parent7ad469291c015b33a2d20587db26b9621ed82d00 (diff)
keywords list
-rw-r--r--bucky/app/bucky.js10
-rw-r--r--bucky/app/router.js13
-rw-r--r--bucky/db/index.js3
-rw-r--r--public/assets/css/bucky.css7
-rw-r--r--public/assets/js/lib/router.js10
-rw-r--r--public/assets/js/lib/views/details/details.js (renamed from public/assets/js/lib/views/details/index.js)0
-rw-r--r--public/assets/js/lib/views/keywords/keywords.js72
-rw-r--r--public/assets/js/util/format.js15
-rw-r--r--views/pages/keywords.ejs68
-rw-r--r--views/partials/header.ejs2
-rw-r--r--views/partials/scripts.ejs4
11 files changed, 189 insertions, 15 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()
}
diff --git a/public/assets/css/bucky.css b/public/assets/css/bucky.css
index e915ded..9d2b36e 100644
--- a/public/assets/css/bucky.css
+++ b/public/assets/css/bucky.css
@@ -82,10 +82,14 @@ h1 {
margin-top: 2px;
margin-bottom: 4px;
}
+a.headline:link,
+a.headline:visited { color: #111; text-decoration: none; }
+a.headline h1 { text-decoration: none; }
+.desktop a.headline:hover { color: #654; text-decoration: none; }
a:link { color: #2050ca; text-decoration: underline; }
a:visited { color: #1030aa; text-decoration: none; }
a:active { color: #a0a0c7; text-decoration: underline; }
-a:hover { color: #2040f0; text-decoration: underline; }
+.desktop a:hover { color: #2040f0; text-decoration: underline; }
hr {
border-color: #000;
}
@@ -615,7 +619,6 @@ pre br {
#files .total td a {
display: inline;
}
-
#gallery {
width: 100%;
}
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js
index da5149a..9ac6336 100644
--- a/public/assets/js/lib/router.js
+++ b/public/assets/js/lib/router.js
@@ -13,6 +13,8 @@ var SiteRouter = Router.extend({
"/details/:id/settings": 'threadSettings',
"/post": 'post',
"/post/:keyword": 'post',
+ "/comment/:id/edit": 'editComment',
+ "/keywords": 'keywords',
"/search": 'search',
"/mail": 'mailbox',
"/mail/:mailbox": 'mailbox',
@@ -20,7 +22,6 @@ var SiteRouter = Router.extend({
"/mail/compose/:username": 'compose',
"/mail/read/:id": 'message',
"/mail/reply/:id": 'compose',
- "/comment/:id/edit": 'editComment',
"/profile": 'profile',
"/profile/:username": 'profile',
"/profile/:username/edit": 'editProfile',
@@ -62,7 +63,12 @@ var SiteRouter = Router.extend({
app.view = new EditCommentForm ()
app.view.load(id)
},
-
+
+ keywords: function(){
+ app.view = new KeywordsView ()
+ app.view.load()
+ },
+
mailbox: function(box){
app.view = new MailboxView ()
app.view.load(box)
diff --git a/public/assets/js/lib/views/details/index.js b/public/assets/js/lib/views/details/details.js
index 1b67b92..1b67b92 100644
--- a/public/assets/js/lib/views/details/index.js
+++ b/public/assets/js/lib/views/details/details.js
diff --git a/public/assets/js/lib/views/keywords/keywords.js b/public/assets/js/lib/views/keywords/keywords.js
new file mode 100644
index 0000000..acb76f1
--- /dev/null
+++ b/public/assets/js/lib/views/keywords/keywords.js
@@ -0,0 +1,72 @@
+var KeywordsView = View.extend({
+
+ el: "#keyword_list",
+
+ events: {
+ },
+
+ action: "/api/keywords/statistics",
+
+ initialize: function(opt){
+ this.template = this.$(".template").html()
+ console.log(this.$(".template"))
+ },
+
+ load: function(){
+ $.get(this.action, this.populate.bind(this))
+ },
+
+ populate: function(data){
+ console.log(data)
+ var keywordThreads = {}
+ data.threadGroups.forEach(kw => {
+ keywordThreads[kw.keyword] = kw
+ })
+ data.keywords
+ .map(a => [parseInt((keywordThreads[a.keyword] || {})['sum(`viewed`)']) || 0, a])
+ .sort((b,a) => cmp(a[0], b[0]))
+ .map(a => a[1])
+ .forEach(keyword => {
+ var thread = keywordThreads[keyword.keyword.toLowerCase()] || {
+ title: '',
+ }
+ // {
+ // keyword: "warez",
+ // sum(`viewed`): "498",
+ // id: 701,
+ // title: "EMS SYNTHI PLUG FOR MAC",
+ // lastmodified: 1192401724
+ // },
+ console.log(keyword, thread)
+ var viewed = thread['sum(`viewed`)']
+ var views = viewed ? hush_views(viewed) : ['','']
+ var dot = privacy_dot(thread.privacy)
+ var datetime = verbose_date(keyword.createdate)
+ var age = get_age(thread.lastmodified)
+ var id = thread.id + get_revision(thread)
+ var t = this.template
+ .replace(/{{keyword}}/g, sanitize(keyword.keyword))
+ .replace(/{{id}}/g, id)
+ .replace(/{{username}}/g, keyword.username)
+ .replace(/{{privacy_dot}}/g, dot)
+ .replace(/{{title}}/g, thread.title)
+ .replace(/{{date}}/g, datetime[0])
+ .replace(/{{time}}/g, datetime[1])
+ .replace(/{{date_class}}/g, carbon_date(thread.lastmodified) )
+ .replace(/{{views}}/g, views[1])
+// .replace(/{{comments}}/g, comments[1])
+// .replace(/{{files}}/g, files[1])
+// .replace(/{{size}}/g, size[1] )
+ .replace(/{{views_class}}/g, views[0])
+// .replace(/{{comments_class}}/g, comments[0])
+// .replace(/{{files_class}}/g, files[0])
+// .replace(/{{show_files}}/g, thread.file_count == 0 ? "hidden" : "")
+// .replace(/{{size_class}}/g, size[0] )
+ .replace(/{{color}}/g, thread.color || "blue" )
+
+ this.$el.append(t)
+ })
+ $("body").removeClass('loading')
+ },
+
+}) \ No newline at end of file
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
index e58928e..5002899 100644
--- a/public/assets/js/util/format.js
+++ b/public/assets/js/util/format.js
@@ -8,10 +8,11 @@ document.body.classList.add(is_desktop ? 'desktop' : 'mobile');
function csrf() {
return $("[name=_csrf]").attr("value")
}
-function commatize (n) {
+function commatize (n, radix) {
+ radix = radix || 1024
var nums = [], i, counter = 0, r = Math.floor
- if (n > 1024) {
- n /= 1024
+ if (n > radix) {
+ n /= radix
nums.unshift(r((n * 10) % 10))
nums.unshift(".")
}
@@ -82,7 +83,7 @@ function carbon_date (date, no_bold) {
}
function hush_views (n, bias, no_bold) {
- var txt = commatize(n)
+ var txt = commatize(n, 1000)
bias = bias || 1
n = n || 0
if (n < 30) { return["quiet", n + "&nbsp;v."] }
@@ -90,11 +91,11 @@ function hush_views (n, bias, no_bold) {
else if (n < 500) { return ["quiet", txt + "&nbsp;v."] }
else if (n < 1000) { return ["old", txt + "&nbsp;v."] }
else if (n < 5000) { return ["med", txt + "&nbsp;kv."] }
- else if (nobold || n < 10000) { return ["recent", txt + "&nbsp;kv."] }
+ else if (no_bold || n < 10000) { return ["recent", txt + "&nbsp;kv."] }
else { return ["new", txt + "&nbsp;kv."] }
}
-function hush_size (n, bias, nobold) {
+function hush_size (n, bias, no_bold) {
var txt = commatize(Math.floor(n / 1024))
bias = 1 || bias
n = n || 0
@@ -113,7 +114,7 @@ function hush_size (n, bias, nobold) {
else if (n < (80000000/bias)) {
return ["med", txt + "&nbsp;mb."]
}
- else if (nobold || n < (170000000/bias)) {
+ else if (no_bold || n < (170000000/bias)) {
return ["recent", txt + "&nbsp;mb."]
}
else {
diff --git a/views/pages/keywords.ejs b/views/pages/keywords.ejs
new file mode 100644
index 0000000..d844e39
--- /dev/null
+++ b/views/pages/keywords.ejs
@@ -0,0 +1,68 @@
+<% include ../partials/header %>
+
+<div class="subtitle"></div>
+
+<div id="content">
+ <div id="keyword_list">
+ <script type="text/html" class="template">
+ <div class="keyword_row">
+ <div class="keyword"><a href="/index/{{keyword}}">{{keyword}}</a></div>
+ <div class='dot'>
+ &middot;
+ </div>
+ <div class="date {{date_class}}">
+ {{date}} <small>{{time}}</small>
+ </div>
+ <div class="views {{views_class}}">
+ {{views}}
+ </div>
+ <div class="{{color}} title">
+ <a href="/details/{{id}}">{{title}}</a>
+ </div>
+ </div>
+ </script>
+ </div>
+</div>
+
+<% include ../partials/footer %>
+
+<style>
+.keyword_row {
+ display: flex;
+ flex-direction: row;
+ margin-top: 10px;
+}
+.keyword_row div {
+ display: flex;
+}
+.keyword_row .dot {
+ margin-right: 5px;
+}
+.keyword_row .keyword a {
+ font-size: 12px;
+ font-weight: bold;
+ display: block;
+ min-width: 100px;
+ text-align: right;
+ margin-right: 5px;
+ margin-top: -3px;
+}
+.keyword_row .date {
+ min-width: 130px;
+}
+.keyword_row .date small {
+ font-size: 9px;
+ margin-left: 3px;
+}
+.keyword_row .views {
+ min-width: 30px;
+ text-align: center;
+}
+.keyword_row .title a {
+ display: block;
+ padding: 5px;
+ margin-top: -4px;
+
+}
+
+</style> \ No newline at end of file
diff --git a/views/partials/header.ejs b/views/partials/header.ejs
index c810114..664e236 100644
--- a/views/partials/header.ejs
+++ b/views/partials/header.ejs
@@ -10,7 +10,7 @@
<body class="loading">
<header>
- <h1><%= title %></h1>
+ <a href="/" class="headline"><h1><%= title %></h1></a>
<% include ../partials/searchform %>
</header>
<content> \ No newline at end of file
diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs
index 83845ee..54ecf8f 100644
--- a/views/partials/scripts.ejs
+++ b/views/partials/scripts.ejs
@@ -28,10 +28,12 @@
<script src="/assets/js/lib/views/search/results.js"></script>
+<script src="/assets/js/lib/views/keywords/keywords.js"></script>
+
<script src="/assets/js/lib/views/profile/profile.js"></script>
<script src="/assets/js/lib/views/profile/profile_edit.js"></script>
-<script src="/assets/js/lib/views/details/index.js"></script>
+<script src="/assets/js/lib/views/details/details.js"></script>
<script src="/assets/js/lib/views/details/settings.js"></script>
<script src="/assets/js/lib/views/details/comments.js"></script>
<script src="/assets/js/lib/views/details/commentform.js"></script>