summaryrefslogtreecommitdiffstats
path: root/index.html
blob: 41d938dce502ec8f74a173114ab4a1d61c2f0e2e (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8 />
    <title>Hostinfo: Overview</title>

    <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css" />
    <style>
      a {
        cursor: pointer;
        color: #F00;
        font-weight: bold;
      }

      a:hover {
        color: rgb(168, 0, 0);
      }

      h1 {
        text-align: center;
      }

      #hosts li {
        list-style-type: none;
        text-align: center;
        margin: 10px;
      }

      #hosts li a {
        line-height: 100px;
        display: block;
      }

      #hosts li a:hover {
        background-color: #CCC;
        color: #000;
        text-decoration: none;
      }

      td.centering, p.centering {
        text-align: center;
      }
    </style>

    <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/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(data.addresses, 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>