|
1
|
|
|
define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper', 'utils/node'], |
|
2
|
|
|
function (SortTable, V, d3Interpolate, moment, helper, nodef) { |
|
3
|
|
|
'use strict'; |
|
4
|
|
|
V = V.default; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
function showStatImg(o, d) { |
|
8
|
|
|
var subst = {}; |
|
9
|
|
|
subst['{NODE_ID}'] = d.node_id; |
|
10
|
|
|
subst['{NODE_NAME}'] = d.hostname.replace(/[^a-z0-9\-]/ig, '_'); |
|
11
|
|
|
subst['{TIME}'] = d.lastseen.format('DDMMYYYYHmmss'); |
|
12
|
|
|
subst['{LOCALE}'] = _.locale(); |
|
13
|
|
|
return helper.showStat(V, o, subst); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
return function (config, el, router, d, linkScale, nodeDict) { |
|
17
|
|
|
function nodeLink(node) { |
|
18
|
|
|
return V.h('a', { |
|
19
|
|
|
props: { |
|
20
|
|
|
className: node.is_online ? 'online' : 'offline', |
|
21
|
|
|
href: router.generateLink({ node: node.node_id }) |
|
22
|
|
|
}, on: { |
|
23
|
|
|
click: function (e) { |
|
24
|
|
|
router.fullUrl({ node: node.node_id }, e); |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
}, node.hostname); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function nodeIdLink(nodeId) { |
|
31
|
|
|
if (nodeDict[nodeId]) { |
|
32
|
|
|
return nodeLink(nodeDict[nodeId]); |
|
33
|
|
|
} |
|
34
|
|
|
return nodeId; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
function showGateway(node) { |
|
38
|
|
|
var gatewayCols = [ |
|
39
|
|
|
V.h('span', [ |
|
40
|
|
|
nodeIdLink(node.gateway_nexthop), |
|
41
|
|
|
V.h('br'), |
|
42
|
|
|
_.t('node.nexthop') |
|
43
|
|
|
]), |
|
44
|
|
|
V.h('span', { props: { className: 'ion-arrow-right-c' } }), |
|
45
|
|
|
V.h('span', [ |
|
46
|
|
|
nodeIdLink(node.gateway), |
|
47
|
|
|
V.h('br'), |
|
48
|
|
|
'IPv4' |
|
49
|
|
|
]), |
|
50
|
|
|
V.h('span', [ |
|
51
|
|
|
nodeIdLink(node.gateway6), |
|
52
|
|
|
V.h('br'), |
|
53
|
|
|
'IPv6' |
|
54
|
|
|
]) |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
return V.h('td', { props: { className: 'gateway' } }, gatewayCols); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
function renderNeighbourRow(n) { |
|
61
|
|
|
var icons = ''; |
|
62
|
|
|
if (helper.hasLocation(n.node)) { |
|
63
|
|
|
icons = V.h('span', { props: { className: 'ion-location' } }); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return V.h('tr', [ |
|
67
|
|
|
V.h('td', icons), |
|
68
|
|
|
V.h('td', nodeLink(n.node)), |
|
69
|
|
|
V.h('td', n.node.clients), |
|
70
|
|
|
V.h('td', { style: { color: linkScale((n.link.source_tq + n.link.target_tq) / 2) } }, helper.showTq(n.link.source_tq) + ' - ' + helper.showTq(n.link.target_tq)), |
|
71
|
|
|
V.h('td', helper.showDistance(n.link)) |
|
72
|
|
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
var self = this; |
|
76
|
|
|
var header = document.createElement('h2'); |
|
77
|
|
|
var table = document.createElement('table'); |
|
78
|
|
|
var images = document.createElement('div'); |
|
79
|
|
|
var neighbours = document.createElement('h3'); |
|
80
|
|
|
var headings = [{ |
|
81
|
|
|
name: '' |
|
82
|
|
|
}, { |
|
83
|
|
|
name: 'node.nodes', |
|
84
|
|
|
sort: function (a, b) { |
|
85
|
|
|
return a.node.hostname.localeCompare(b.node.hostname); |
|
86
|
|
|
}, |
|
87
|
|
|
reverse: false |
|
88
|
|
|
}, { |
|
89
|
|
|
name: 'node.clients', |
|
90
|
|
|
class: 'ion-people', |
|
91
|
|
|
sort: function (a, b) { |
|
92
|
|
|
return a.node.clients - b.node.clients; |
|
93
|
|
|
}, |
|
94
|
|
|
reverse: true |
|
95
|
|
|
}, { |
|
96
|
|
|
name: 'node.tq', |
|
97
|
|
|
class: 'ion-connection-bars', |
|
98
|
|
|
sort: function (a, b) { |
|
99
|
|
|
return a.link.source_tq - b.link.source_tq; |
|
100
|
|
|
}, |
|
101
|
|
|
reverse: true |
|
102
|
|
|
}, { |
|
103
|
|
|
name: 'node.distance', |
|
104
|
|
|
class: 'ion-arrow-resize', |
|
105
|
|
|
sort: function (a, b) { |
|
106
|
|
|
return (a.link.distance === undefined ? -1 : a.link.distance) - |
|
107
|
|
|
(b.link.distance === undefined ? -1 : b.link.distance); |
|
108
|
|
|
}, |
|
109
|
|
|
reverse: true |
|
110
|
|
|
}]; |
|
111
|
|
|
var tableNeighbour = new SortTable(headings, 1, renderNeighbourRow); |
|
112
|
|
|
|
|
113
|
|
|
el.appendChild(header); |
|
114
|
|
|
el.appendChild(table); |
|
115
|
|
|
el.appendChild(neighbours); |
|
116
|
|
|
el.appendChild(tableNeighbour.el); |
|
117
|
|
|
el.appendChild(images); |
|
118
|
|
|
|
|
119
|
|
|
self.render = function render() { |
|
120
|
|
|
V.patch(header, V.h('h2', d.hostname)); |
|
121
|
|
|
|
|
122
|
|
|
var children = []; |
|
123
|
|
|
|
|
124
|
|
|
config.nodeAttr.forEach(function (row) { |
|
125
|
|
|
var field; |
|
126
|
|
|
if (d[row[1]] !== undefined) { |
|
127
|
|
|
field = d[row[1]]; |
|
128
|
|
|
} else if (nodef['show' + row[1]] !== undefined) { |
|
129
|
|
|
field = nodef['show' + row[1]](V, d); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
if (field) { |
|
133
|
|
|
if (typeof field !== 'object') { |
|
134
|
|
|
field = V.h('td', field); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
children.push(V.h('tr', [ |
|
138
|
|
|
V.h('th', _.t(row[0])), |
|
139
|
|
|
field |
|
140
|
|
|
])); |
|
141
|
|
|
} |
|
142
|
|
|
}); |
|
143
|
|
|
|
|
144
|
|
|
children.push(helper.attributeEntry(V, 'node.site', nodef.showSite(V, d, config))); |
|
145
|
|
|
children.push(helper.attributeEntry(V, 'node.gateway', showGateway(d))); |
|
146
|
|
|
|
|
147
|
|
|
var elNew = V.h('table', children); |
|
148
|
|
|
table = V.patch(table, elNew); |
|
149
|
|
|
table.elm.classList.add('attributes'); |
|
150
|
|
|
|
|
151
|
|
|
V.patch(neighbours, V.h('h3', _.t('node.link', d.neighbours.length) + ' (' + d.neighbours.length + ')')); |
|
152
|
|
|
if (d.neighbours.length > 0) { |
|
153
|
|
|
tableNeighbour.setData(d.neighbours); |
|
154
|
|
|
tableNeighbour.el.elm.classList.add('node-links'); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
if (config.nodeInfos) { |
|
158
|
|
|
var img = []; |
|
159
|
|
|
config.nodeInfos.forEach(function (nodeInfo) { |
|
160
|
|
|
img.push(V.h('h4', nodeInfo.name)); |
|
161
|
|
|
img.push(showStatImg(nodeInfo, d)); |
|
162
|
|
|
}); |
|
163
|
|
|
images = V.patch(images, V.h('div', img)); |
|
164
|
|
|
} |
|
165
|
|
|
}; |
|
166
|
|
|
|
|
167
|
|
|
self.setData = function setData(data) { |
|
168
|
|
|
if (data.nodeDict[d.node_id]) { |
|
169
|
|
|
d = data.nodeDict[d.node_id]; |
|
170
|
|
|
} |
|
171
|
|
|
self.render(); |
|
172
|
|
|
}; |
|
173
|
|
|
return self; |
|
174
|
|
|
}; |
|
175
|
|
|
}); |
|
176
|
|
|
|