summaryrefslogtreecommitdiffstats
path: root/index.html
blob: a80ca973469c70d009eaf244e683a97b753593fb (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8 />
    <title>Hostinfo: Overview</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap-responsive.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="css/custom.css" />

    <script src="js/js-yaml.min.js"></script>
    <script src="js/jquery-2.0.0.min.js"></script>
    <script src="js/jquery.history.js"></script>
    <script src="js/jquery.mustache.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/mustache.js"></script>
    <script src="js/underscore.min.js"></script>
    <script type="text/javascript">

      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();
        }
      });
    </script>
  </head>
  <body>
    <div class="container">
      <div class="row">

        <div class="span12" id="content">
        </div>
      </div>
    </div>

  </body>
</html>