Completed
Pull Request — develop (#224)
by Xaver
36s
created

link.js ➔ ... ➔ data.links.filter   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(['helper', 'snabbdom'], function (helper, V) {
2
  'use strict';
3
  V = V.default;
4
5
  function showStatImg(o, d, time) {
6
    var subst = {
7
      '{SOURCE_ID}': d.source.node_id,
8
      '{SOURCE_NAME}': d.source.hostname.replace(/[^a-z0-9\-]/ig, '_'),
9
      '{TARGET_ID}': d.target.node_id,
10
      '{TARGET_NAME}': d.target.hostname.replace(/[^a-z0-9\-]/ig, '_'),
11
      '{TIME}': time,
12
      '{LOCALE}': _.locale()
13
    };
14
    return helper.showStat(V, o, subst);
15
  }
16
17
  return function (el, d, linkScale) {
18
    var self = this;
19
    var header = document.createElement('div');
20
    var table = document.createElement('table');
21
    var images = document.createElement('div');
22
    el.appendChild(header);
23
    el.appendChild(table);
24
    el.appendChild(images);
25
26
    self.render = function render() {
27
      var children = [];
28
      var headers = [];
29
      headers.push(V.h('h2', [
30
        V.h('a', {
31
          props: { href: router.generateLink({ node: d[0].source.node_id }) }
32
        }, d[0].source.hostname),
33
        V.h('span', ' - '),
34
        V.h('a', {
35
          props: { href: router.generateLink({ node: d[0].target.node_id }) }
36
        }, d[0].target.hostname)
37
      ]));
38
39
      header = V.patch(header, V.h('div', headers));
40
41
      helper.attributeEntry(V, children, 'node.hardware', (d[0].source.model ? d[0].source.model + ' – ' : '') +
42
        (d[0].target.model ? d[0].target.model : ''));
43
      helper.attributeEntry(V, children, 'node.distance', helper.showDistance(d[0]));
44
45
      d.forEach(function (node) {
46
        children.push(V.h('tr', { props: { className: 'header' } }, [
47
          V.h('th', _.t('node.connectionType')),
48
          V.h('th', node.type)
49
        ]));
50
        helper.attributeEntry(V, children, 'node.tq', V.h('span',
51
          {
52
            style:
53
              {
54
                color: linkScale((node.source_tq + node.target_tq) / 2)
55
              }
56
          }, helper.showTq(node.source_tq) + ' - ' + helper.showTq(node.target_tq))
57
        );
58
      });
59
60
      var elNew = V.h('table', children);
61
      table = V.patch(table, elNew);
62
      table.elm.classList.add('attributes');
63
64
      if (config.linkInfos) {
65
        var time = d.target.lastseen.format('DDMMYYYYHmmss');
66
        var img = [];
67
        config.linkInfos.forEach(function (linkInfo) {
68
          img.push(V.h('h4', linkInfo.name));
69
          img.push(showStatImg(linkInfo, d, time));
70
        });
71
        images = V.patch(images, V.h('div', img));
72
      }
73
    };
74
75
    self.setData = function setData(data) {
76
      d = data.links.filter(function (a) {
77
        return a.id === d[0].id;
78
      });
79
      self.render();
80
    };
81
    return self;
82
  };
83
});
84