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