From d3a31c89081f7d2d268c53fef64c502407ef42bb Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 4 Apr 2020 21:44:26 +0200 Subject: user list --- public/assets/js/lib/views/users/users.js | 55 ++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'public/assets/js/lib/views/users/users.js') diff --git a/public/assets/js/lib/views/users/users.js b/public/assets/js/lib/views/users/users.js index cbb0fde..a45123d 100644 --- a/public/assets/js/lib/views/users/users.js +++ b/public/assets/js/lib/views/users/users.js @@ -1,6 +1,6 @@ var UsersView = View.extend({ - el: "#users_list", + el: "#user_list", events: { }, @@ -8,8 +8,15 @@ var UsersView = View.extend({ action: "/api/users", initialize: function(opt){ + opt = opt || {} + this.showAll = !!opt.all this.template = this.$(".template").html() this.form = new NewKeywordForm ({ parent: this }) + if (!this.showAll) { + $('.all_link').attr('href', '/users/all').html('Show all users') + } else { + $('.all_link').attr('href', '/users').html('Show active users') + } }, load: function(){ @@ -22,6 +29,8 @@ var UsersView = View.extend({ // data.threadGroups.forEach(kw => { // keywordThreads[kw.keyword] = kw // }) + var showAll = this.showAll + var userStats = data.userStats data.users // .map(a => [parseInt((keywordThreads[a.keyword] || {})['sum(`viewed`)']) || 0, a]) // .sort((b,a) => cmp(a[0], b[0])) @@ -34,31 +43,45 @@ var UsersView = View.extend({ // var threadCount = threadCountNum ? hush_threads(threadCountNum) : ['',''] // "id", "username", "realname", "firstseen", "lastseen", // "location", "website", "avatar", - var create_datetime = verbose_date(keyword.createdate) - var age = get_age(thread.lastmodified) - var id = thread.id + get_revision(thread) + console.log(user) + var stats = userStats[user.username] || {} + console.log(stats) + if (!showAll && !stats.threads && !stats.files && !stats.comments) { + return + } + var threadCount = stats.threads ? hush_threads(stats.threads) : ['',''] + var fileCount = stats.files ? hush_null(stats.files, 'f') : ['',''] + var commentCount = stats.comments ? hush_null(stats.comments, 'c') : ['',''] + var firstseen_datetime = verbose_date(user.firstseen) + var lastseen = get_age(user.lastseen) var t = this.template - .replace(/{{keyword}}/g, sanitizeHTML(keyword.keyword)) - .replace(/{{id}}/g, id) - .replace(/{{username}}/g, keyword.username) - .replace(/{{title}}/g, thread.title) - .replace(/{{create_date}}/g, create_datetime[0]) - .replace(/{{create_time}}/g, create_datetime[1]) - .replace(/{{date_class}}/g, carbon_date(thread.lastmodified) ) - .replace(/{{views}}/g, views[1]) + .replace(/{{username}}/g, sanitizeHTML(user.username)) + .replace(/{{id}}/g, user.id) + .replace(/{{realname}}/g, sanitizeHTML(user.realname)) + .replace(/{{firstseen_date}}/g, firstseen_datetime[0]) + .replace(/{{firstseen_time}}/g, firstseen_datetime[1]) + .replace(/{{firstseen_date_class}}/g, carbon_date(user.firstseen) ) + .replace(/{{lastseen}}/g, lastseen ) + .replace(/{{lastseen_date_class}}/g, carbon_date(lastseen) ) .replace(/{{threadcount}}/, threadCount[1]) .replace(/{{threadcount_class}}/, threadCount[0]) + .replace(/{{filecount}}/, fileCount[1]) + .replace(/{{filecount_class}}/, fileCount[0]) + .replace(/{{commentcount}}/, commentCount[1]) + .replace(/{{commentcount_class}}/, commentCount[0]) // .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) + // .replace(/{{color}}/g, thread.color || "blue" ) + var $t = $(t) + if (!user.firstseen) { + $t.find('.date').html('') + } + this.$el.append($t) }) $("body").removeClass('loading') }, -- cgit v1.2.3-70-g09d2