Completed
Pull Request — develop (#125)
by Xaver
01:05
created

linklist.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(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) {
2
  'use strict';
3
4
  function linkName(d) {
5
    return (d.source.node ? d.source.node.nodeinfo.hostname : d.source.id) + ' – ' + d.target.node.nodeinfo.hostname;
6
  }
7
8
  var headings = [{
9
    name: 'node.nodes',
10
    sort: function (a, b) {
11
      return linkName(a).localeCompare(linkName(b));
12
    },
13
    reverse: false
14
  }, {
15
    name: 'node.tq',
16
    class: 'ion-connection-bars',
17
    sort: function (a, b) {
18
      return a.tq - b.tq;
19
    },
20
    reverse: true
21
  }, {
22
    name: 'node.distance',
23
    class: 'ion-arrow-resize',
24
    sort: function (a, b) {
25
      return (a.distance === undefined ? -1 : a.distance) -
26
        (b.distance === undefined ? -1 : b.distance);
27
    },
28
    reverse: true
29
  }];
30
31
  return function (linkScale, router) {
32
    var table = new SortTable(headings, 2, renderRow);
33
    V = V.default;
34
35
    function renderRow(d) {
36
      var td1Content = [V.h('a', {
37
        props: {
38
          href: router.generateLink({ link: d.id })
39
        }, on: {
40
          click: function (e) {
41
            router.fullUrl({ link: d.id }, e);
42
          }
43
        }
44
      }, linkName(d))];
45
46
      var td1 = V.h('td', td1Content);
47
      var td2 = V.h('td', {  style: { color: linkScale(1 / d.tq) } }, helper.showTq(d));
48
      var td3 = V.h('td', helper.showDistance(d));
49
50
      return V.h('tr', [td1, td2, td3]);
51
    }
52
53
    this.render = function render(d) {
54
      var h2 = document.createElement('h2');
55
      h2.textContent = _.t('node.links');
56
      d.appendChild(h2);
57
      table.el.elm.classList.add('link-list');
58
      d.appendChild(table.el.elm);
59
    };
60
61
    this.setData = function setData(d) {
62
      table.setData(d.graph.links);
63
    };
64
  };
65
});
66