summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/users/users.js
blob: 41137ffdb54b103c20b370eb2f48b948014f8a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var UsersView = View.extend({

  el: "#user_list",

  events: {
  },

  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(){
    $.get(this.action, this.populate.bind(this))
  },

  populate: function(data){
    console.log(data)
    // var keywordThreads = {}
    // 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]))
    // .map(a => a[1])
    .map(user => {
      // var user = users[user.username.toLowerCase()] || return
      // var viewed = thread['sum(`viewed`)']
      // var views = viewed ? hush_views(viewed) : ['','']
      // var threadCountNum = thread['count(*)']
      // var threadCount = threadCountNum ? hush_threads(threadCountNum) : ['','']
      // "id", "username", "realname", "firstseen", "lastseen",
      // "location", "website", "avatar",
      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 avatar = user.avatar || ("https://s3.amazonaws.com/i.asdf.us/bucky/profile/" + username + ".jpg")
      var t = this.template
        .replace(/{{username}}/g, sanitizeHTML(user.username))
        .replace(/{{id}}/g, user.id)
        .replace(/{{avatar}}/g, user.avatar)
        .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(/{{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" )
      var $t = $(t)
      if (!user.firstseen) {
        $t.find('.date').html('')
      }
      // if (!user.avatar) {
      //   $t.find('.avatar').addClass('hidden')
      // }
      this.$el.append($t)
    })
    $("body").removeClass('loading')
  },

})