1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
var strip = function(data) { return data.split('.')[0] };
render = {
'index' : function() {
jQuery.get('data/metadata/hosts', function(raw) {
var data = jsyaml.load(raw),
hosts = [];
for(var i=0; i < data.hosts.length; i++) {
var entry = data.hosts[i];
hosts.push({
'name' : strip(entry),
'uri' : entry
});
}
$.Mustache.load('./templates/index.html').done(function () {
$('#content').mustache('hosts', {'hosts':hosts}, {method: 'html'});
$("#hosts a").click("hover", function(event){
var uri = $(this).attr('data-uri');
render.host(uri);
History.pushState({host: uri}, 'Hostinfo: ' + uri, 'index.html?'+uri);
return false;
});
});
});
},
'host' : function(uri) {
jQuery.get('data/'+uri, function(raw) {
var data = jsyaml.load(raw);
data.name = strip(data.hostname);
data.interfaces = _.map(
_.groupBy(
_.filter(data.addresses, function(x) {
return typeof x.vserver == 'undefined';
}),
function(x) {
return x.interface;
}),
function(obj, key) {
obj.device = key;
return obj;
});
$.Mustache.load('./templates/host.html').done(function () {
$('#content').mustache('hostinfo', data, {method: 'html'});
$("#index").click("hover", function(event){
render.index();
History.pushState({host: undefined}, 'Hostinfo: Overview', 'index.html');
return false;
});
});
});
}
};
$(document).ready(function() {
var History = window.History;
if (History.enabled) {
History.Adapter.bind(window,'statechange',function(){
var State = History.getState();
if (State.data.host) {
render.host(State.data.host);
}
else {
render.index();
}
});
}
var host = window.location.search.split('?')[1] || undefined;
if (host) {
render.host(host);
document.title = 'Hostinfo: ' + host;
History.replaceState({host: host}, 'Hostinfo: ' + host, 'index.html?' + host);
}
else {
render.index();
}
});
|