Completed
Push — develop ( e1b69c...c28840 )
by Xaver
01:12
created

simplenodelist.js ➔ ... ➔ V.h(ꞌaꞌ).on.click   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 1
1
define(['moment', 'snabbdom', 'helper'], function (moment, V, helper) {
2
  'use strict';
3
  V = V.default;
4
5
  return function (nodes, field, router, 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 time = moment(d[field]).from(data.now);
38
        var td0Content = [];
39
        var td1Content = [];
40
41
        var aClass = ['hostname', d.flags.online ? 'online' : 'offline'];
42
43
        td1Content.push(V.h('a', {
44
          props: {
45
            className: aClass.join(' '),
46
            href: router.generateLink({ node: d.nodeinfo.node_id })
47
          }, on: {
48
            click: function (e) {
49
              router.fullUrl({ node: d.nodeinfo.node_id }, e);
50
            }
51
          }
52
        }, d.nodeinfo.hostname));
53
54
        if (helper.hasLocation(d)) {
55
          td0Content.push(V.h('span', { props: { className: 'icon ion-location' } }));
56
        }
57
58
        var td0 = V.h('td', td0Content);
59
        var td1 = V.h('td', td1Content);
60
        var td2 = V.h('td', time);
61
62
        return V.h('tr', [td0, td1, td2]);
63
      });
64
65
      var tbodyNew = V.h('tbody', items);
66
      tbody = V.patch(tbody, tbodyNew);
67
    };
68
69
    return self;
70
  };
71
});
72