1
|
|
|
define(['helper'], function (helper) { |
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
return function (language) { |
5
|
|
|
var self = this; |
6
|
|
|
var stats = document.createTextNode(''); |
7
|
|
|
var timestamp = document.createTextNode(''); |
8
|
|
|
|
9
|
|
|
self.setData = function setData(d) { |
10
|
|
|
var totalNodes = Object.keys(d.nodeDict).length; |
11
|
|
|
var totalOnlineNodes = d.nodes.online.length; |
12
|
|
|
var totalClients = helper.sum(d.nodes.online.map(function (n) { |
13
|
|
|
return n.clients; |
14
|
|
|
})); |
15
|
|
|
var totalGateways = helper.sum(d.nodes.online.filter(function (n) { |
16
|
|
|
return n.is_gateway; |
17
|
|
|
}).map(helper.one)); |
18
|
|
|
|
19
|
|
|
stats.textContent = _.t('sidebar.nodes', { total: totalNodes, online: totalOnlineNodes }) + ' ' + |
20
|
|
|
_.t('sidebar.clients', { smart_count: totalClients }) + ' ' + |
21
|
|
|
_.t('sidebar.gateway', { smart_count: totalGateways }); |
22
|
|
|
|
23
|
|
|
timestamp.textContent = _.t('sidebar.lastUpdate') + ' ' + d.timestamp.fromNow(); |
24
|
|
|
}; |
25
|
|
|
|
26
|
|
|
self.render = function render(el) { |
27
|
|
|
var h1 = document.createElement('h1'); |
28
|
|
|
h1.textContent = config.siteName; |
29
|
|
|
el.appendChild(h1); |
30
|
|
|
|
31
|
|
|
language.languageSelect(el); |
32
|
|
|
|
33
|
|
|
var p = document.createElement('p'); |
34
|
|
|
p.classList.add('legend'); |
35
|
|
|
|
36
|
|
|
p.appendChild(stats); |
37
|
|
|
p.appendChild(document.createElement('br')); |
38
|
|
|
p.appendChild(timestamp); |
39
|
|
|
|
40
|
|
|
if (config.linkList) { |
41
|
|
|
p.appendChild(document.createElement('br')); |
42
|
|
|
config.linkList.forEach(function (link) { |
43
|
|
|
var a = document.createElement('a'); |
44
|
|
|
a.innerText = link.title; |
45
|
|
|
a.href = link.href; |
46
|
|
|
p.appendChild(a); |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
el.appendChild(p); |
51
|
|
|
}; |
52
|
|
|
|
53
|
|
|
return self; |
54
|
|
|
}; |
55
|
|
|
}); |
56
|
|
|
|