diff options
Diffstat (limited to 'public/assets/js/lib/views/index')
| -rw-r--r-- | public/assets/js/lib/views/index/index.js | 2 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/lastlog.js | 3 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/threadbox.js | 38 |
3 files changed, 32 insertions, 11 deletions
diff --git a/public/assets/js/lib/views/index/index.js b/public/assets/js/lib/views/index/index.js index d66ea1c..171133b 100644 --- a/public/assets/js/lib/views/index/index.js +++ b/public/assets/js/lib/views/index/index.js @@ -8,7 +8,7 @@ var IndexView = View.extend({ initialize: function(opt){ // opt.parent = parent this.hootbox = new HootBox ({ parent: this }) - this.threadbox = new ThreadBox ({ parent: this, latest: true }) + this.threadbox = new ThreadBox ({ parent: this, latest: true, welcome: true, }) this.lastlog = new LastLog ({ parent: this }) this.load() }, diff --git a/public/assets/js/lib/views/index/lastlog.js b/public/assets/js/lib/views/index/lastlog.js index 2f7b224..0fed101 100644 --- a/public/assets/js/lib/views/index/lastlog.js +++ b/public/assets/js/lib/views/index/lastlog.js @@ -18,11 +18,12 @@ var LastLog = View.extend({ }, load: function(lastlog){ - var s = lastlog.map(this.parse.bind(this)).join(', ') + var s = lastlog.map(this.parse.bind(this)).filter(s => s).join(', ') this.$el.html(s) }, parse: function(user){ + if (Date.now()/1000 - user.lastseen > 86400 * 14 *10000) return '' var t = this.template .replace(/{{username}}/g, user.username) .replace(/{{age}}/g, get_age(user.lastseen) ) diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js index 8d8cb02..6efce22 100644 --- a/public/assets/js/lib/views/index/threadbox.js +++ b/public/assets/js/lib/views/index/threadbox.js @@ -8,28 +8,34 @@ var ThreadBox = View.extend({ this.__super__.initialize.call(this) this.template = this.$(".template").html() this.keywordTemplate = this.$(".keywordTemplate").html() + this.welcomeTemplate = this.$(".welcomeTemplate").html() }, load: function(data){ + if (this.options.welcome) { + this.appendWelcome() + } if (data.keyword) { this.appendKeyword(data.keyword) - data.threads.forEach(this.appendThread.bind(this)) - } - else if (this.options.latest) { - data.threads.sort( (a,b) => { - return b.lastmodified - a.lastmodified - }).slice(0, 50).forEach(this.appendThread.bind(this)) + this.appendThreads(data.threads) } else { + if (this.options.latest) { + var latest = data.threads.sort( (a,b) => { + return b.lastmodified - a.lastmodified + }).slice(0, 15) + this.appendThreads(latest) + data.threads = data.threads.filter((thread) => thread && !! thread.keyword) + } var keywords = {} data.threads.forEach((thread) => { - var keyword = thread.keyword || '__unsorted' + var keyword = thread.keyword || 'unsorted' keywords[keyword] = keywords[keyword] || [] keywords[keyword].push(thread) }) Object.keys(keywords).sort().forEach((keyword) => { this.appendKeyword({ keyword }) - keywords[keyword].forEach(this.appendThread.bind(this)) + this.appendThreads(keywords[keyword]) }) } }, @@ -62,7 +68,7 @@ var ThreadBox = View.extend({ .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 || "ivory" ) + .replace(/{{color}}/g, thread.color || "blue" ) return t }, @@ -76,9 +82,18 @@ var ThreadBox = View.extend({ var $row = $( this.parse(thread) ) this.$el.prepend($row) }, + + appendThreads: function(threads){ + threads[0].first = true + threads[threads.length-1].last = true + threads.forEach(this.appendThread.bind(this)) + }, appendThread: function(thread){ + thread.appended = true var $row = $( this.parse(thread) ) + if (thread.first) $row.addClass('first') + if (thread.last) $row.addClass('last') this.$el.append($row) }, @@ -86,4 +101,9 @@ var ThreadBox = View.extend({ var $row = $( this.parseKeyword(keyword) ) this.$el.append($row) }, + + appendWelcome: function(){ + this.$el.append(this.welcomeTemplate) + }, + }) |
