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

link.js ➔ ... ➔ d.forEach   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 10
rs 9.4285
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
29
      header = V.patch(header, V.h('div', 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
      helper.attributeEntry(V, children, 'node.hardware', (d[0].source.model ? d[0].source.model + ' – ' : '') +
40
        (d[0].target.model ? d[0].target.model : ''));
41
      helper.attributeEntry(V, children, 'node.distance', helper.showDistance(d[0]));
42
43
      d.forEach(function (link) {
44
        children.push(V.h('tr', { props: { className: 'header' } }, [
45
          V.h('th', _.t('node.connectionType')),
46
          V.h('th', link.type)
47
        ]));
48
        helper.attributeEntry(V, children, 'node.tq', V.h('span',
49
          { style: { color: linkScale((link.source_tq + link.target_tq) / 2) } },
50
          helper.showTq(link.source_tq) + ' - ' + helper.showTq(link.target_tq))
51
        );
52
      });
53
54
      var elNew = V.h('table', children);
55
      table = V.patch(table, elNew);
56
      table.elm.classList.add('attributes');
57
58
      if (config.linkInfos) {
59
        var time = d.target.lastseen.format('DDMMYYYYHmmss');
60
        var img = [];
61
        config.linkInfos.forEach(function (linkInfo) {
62
          img.push(V.h('h4', linkInfo.name));
63
          img.push(showStatImg(linkInfo, d, time));
64
        });
65
        images = V.patch(images, V.h('div', img));
66
      }
67
    };
68
69
    self.setData = function setData(data) {
70
      d = data.links.filter(function (a) {
71
        return a.id === d[0].id;
72
      });
73
      self.render();
74
    };
75
    return self;
76
  };
77
});
78