-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.html
240 lines (177 loc) · 6.34 KB
/
template.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html>
<head>
<title>AODN Service Status</title>
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link rel="shortcut icon" href="/img/favicon.png" type="image/x-icon" />
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="../../assets/js/html5shiv.js"></script>
<script src="../../assets/js/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
var millisPerSecond = 1000;
var millisPerMinute = 60 * millisPerSecond;
var lastUpdated = new Date(##LAST_UPDATED_MILLIS##);
var pageLoad = new Date();
function minutesSince(date) {
var now = new Date();
var difference = now.getTime() - date.getTime();
return difference / millisPerMinute;
}
function displayMinutesSince(date) {
var num = Math.floor(minutesSince(date));
var minuteString = (num < 1) ? "< 1" : num;
minuteString += " minute";
minuteString += (num > 1) ? "s" : ""
return minuteString;
}
function onLoad() {
if (dataIsStale())
displayStaleDataMessage();
displayServiceStatus();
updateFields();
}
function updateFields() {
$('.since_load_replacement').html(displayMinutesSince(pageLoad));
$('.since_update_replacement').html(displayMinutesSince(lastUpdated));
if (pageIsTooOld())
$('#modal').modal(); // Show popup
setTimeout(function() {updateFields()}, 20 * millisPerSecond);
}
function dataIsStale() {
return minutesSince(lastUpdated) >= 10;
}
function pageIsTooOld() {
return minutesSince(pageLoad) >= 7;
}
function displayStaleDataMessage() {
insertStatusPageInfo('<strong>Information out of date</strong><br>The information feed for this page was last updated <span class="since_update_replacement"></span> ago and is considered out of date. It has not been displayed.');
}
function displayServiceStatus() {
var info = serviceStatusInfo();
var output = '';
$.each(info, function(idx, serviceGroup) {
output += formatServiceGroup(serviceGroup);
});
insertServiceInfo(output);
}
function serviceStatusInfo() {
var serviceGroupInfo = ##SERVICE_STATUS_JSON##;
if (dataIsStale())
markAllServicesAsUnknown(serviceGroupInfo);
return serviceGroupInfo;
}
function markAllServicesAsUnknown(groups) {
$.each(groups, function(idx, group) {
group.status = null;
$.each(group.services, function(idx, service) {
service.notice = null;
service.okMessage = null;
service.warningMessage = null;
service.errorMessage = null;
service.inactiveMessage = 'Unknown';
});
});
}
function formatServiceGroup(group) {
var cssClass;
if (group.status == "ok") {
cssClass = 'panel-success';
}
else if (group.status == "warning") {
cssClass = 'panel-warning';
}
else if (group.status == "error") {
cssClass = 'panel-danger';
}
else {
cssClass = 'panel-default';
}
var markup = '' +
'<div class="panel ' + cssClass + '">' +
' <div class="panel-heading">' +
' <h3 class="panel-title">' + group.name + '</h3>' +
' </div>' +
' <ul class="list-group">';
$.each(group.services, function(idx, service) {
markup += formatServiceData(service);
});
markup += '' +
' </ul>' +
'</div>';
return markup;
}
function formatServiceData(service) {
var labelStyle;
var labelText;
if (service.okMessage) {
labelStyle = 'label-success';
labelText = '<i class="glyphicon glyphicon-ok"></i> ' + service.okMessage;
}
else if (service.warningMessage) {
labelStyle = 'label-warning';
labelText = '<i class="glyphicon glyphicon-exclamation-sign"></i> ' + service.warningMessage;
}
else if (service.errorMessage) {
labelStyle = 'label-danger';
labelText = '<i class="glyphicon glyphicon-fire"></i> ' + service.errorMessage;
}
else {
labelStyle = 'label-default';
labelText = '<i class="glyphicon glyphicon-question-sign"></i> ' + 'Unknown';
}
var markup = '<li class="list-group-item">';
markup += '<span style="font-size: 105%;" class="label ' + labelStyle + ' pull-right">' + labelText + '</span>';
if (service.notice)
markup += '<span style="font-size: 105%; margin-right: 2px;" class="label label-info pull-right"><i class="glyphicon glyphicon-wrench"></i> ' + service.notice + '</span>';
markup += '<h4 class="list-group-item-heading">' + service.name + '</h4>';
markup += '<p class="list-group-item-text">' + service.description + '</p>';
markup += '</li>';
return markup;
}
function insertStatusPageInfo(message) {
$('#this_page_status').html('<div class="alert alert-danger">' + message + '</div>')
}
function insertServiceInfo(info) {
$('#service_info').html(info);
}
</script>
</head>
<body onload="onLoad()">
<div class="container">
<div class="starter-template">
<h1>AODN Service Status</h1>
<p><i class="glyphicon glyphicon-time"></i> Last update <span class="since_update_replacement"></span> ago</p>
<div id="this_page_status"></div>
<div id="service_info"></div>
</div>
</div>
<div class="modal fade" id="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Refresh page</h4>
</div>
<div class="modal-body">
<p>It has been <span class="since_load_replacement"></span> since this page was loaded. You should refresh this page to see the lastest available service information.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-lg btn-block" onclick="location.reload(true);"><span class="glyphicon glyphicon-refresh"></span> Refresh now</button>
</div>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="//code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>