Completed
Push — develop ( 7c8456...1887a3 )
by Xaver
32s
created

link.js ➔ ... ➔ render   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
nc 8
dl 0
loc 41
rs 8.5806
nop 0

1 Function

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