Passed
Push — develop ( 9a1b4b...96b452 )
by Xaver
03:40
created

lib/legend.js   A

Complexity

Total Complexity 8
Complexity/F 1.14

Size

Lines of Code 55
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 37
mnd 1
bc 1
fnc 7
dl 0
loc 55
rs 10
bpm 0.1428
cpm 1.1428
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A legend.js ➔ render 0 26 3
A legend.js ➔ setData 0 16 5
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