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

lib/simplenodelist.js   A

Complexity

Total Complexity 10
Complexity/F 1.67

Size

Lines of Code 66
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 43
mnd 4
bc 4
fnc 6
dl 0
loc 66
rs 10
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B simplenodelist.js ➔ setData 0 49 7
A simplenodelist.js ➔ render 0 3 3
1
define(['moment', 'snabbdom', 'helper'], function (moment, V, helper) {
2
  'use strict';
3
  V = V.default;
4
5
  return function (nodes, field, title) {
6
    var self = this;
7
    var el;
8
    var tbody;
9
10
    self.render = function render(d) {
11
      el = d;
12
    };
13
14
    self.setData = function setData(data) {
15
      var list = data.nodes[nodes];
16
17
      if (list.length === 0) {
18
        tbody = null;
19
        return;
20
      }
21
22
      if (!tbody) {
23
        var h2 = document.createElement('h2');
24
        h2.textContent = title;
25
        el.appendChild(h2);
26
27
        var table = document.createElement('table');
28
        table.classList.add('node-list');
29
        el.appendChild(table);
30
31
        tbody = document.createElement('tbody');
32
        tbody.last = V.h('tbody');
33
        table.appendChild(tbody);
34
      }
35
36
      var items = list.map(function (d) {
37
        var td0Content = '';
38
        if (helper.hasLocation(d)) {
39
          td0Content = V.h('span', { props: { className: 'icon ion-location', title: _.t('location.location') } });
40
        }
41
42
        var td1Content = V.h('a', {
43
          props: {
44
            className: ['hostname', d.is_online ? 'online' : 'offline'].join(' '),
45
            href: router.generateLink({ node: d.node_id })
46
          }, on: {
47
            click: function (e) {
48
              router.fullUrl({ node: d.node_id }, e);
49
            }
50
          }
51
        }, d.hostname);
52
53
        return V.h('tr', [
54
          V.h('td', td0Content),
55
          V.h('td', td1Content),
56
          V.h('td', moment(d[field]).from(data.now))
57
        ]);
58
      });
59
60
      var tbodyNew = V.h('tbody', items);
61
      tbody = V.patch(tbody, tbodyNew);
62
    };
63
64
    return self;
65
  };
66
});
67