Skip to content

Commit d491fae

Browse files
committed
Update web interface
Former-commit-id: cb853be Former-commit-id: e570a6a
1 parent a43857f commit d491fae

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

public/TestData.htm

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
5+
<title>TestData</title>
6+
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
7+
<link rel="icon" href="favicon.ico" type="image/x-icon">
8+
<script src="js/jquery-1.8.2.min.js"></script>
9+
<script src="js/default.js"></script>
10+
</head>
11+
<body>
12+
<h2>HAPI Server for TestData datasets</h2>
13+
<p>
14+
This server servers software-generated parameters that can be used to test a HAPI client (see <a href="https://github.com/hapi-server/">the HAPI project page</a> for a list of existing clients).
15+
</p>
16+
<p>
17+
The parameters include most types that are supported by the HAPI specification along with variations that are expected to be found in real datasets (non-uniform cadence, fill values, empty time intervals).
18+
</p>
19+
<p>
20+
Note that if the time interval <code>1970-01-01T00:00:10.000</code> to <code>1970-01-01T00:00:20.000</code> is requested for any parameter, the body of the response for a HAPI CSV or HAPI Binary request (with no header) is empty, e.g. <a href="hapi/data?id=dataset1&parameters=scalar&time.min=1970-01-01T00:00:10.000Z&time.max=1970-01-01T00:00:20.000">this request</a>.
21+
</p>
22+
<p>
23+
This server supports the <a href="https://github.com/hapi-server/data-specification">HAPI 2.0 API</a> specification for delivery of time series data.
24+
</p>
25+
<p>
26+
The server responds to GET requests to the following <a href="https://github.com/hapi-server/data-specification/tree/v1.1.0#endpoints">HAPI endpoints</a>:
27+
</p>
28+
<ul>
29+
<li>
30+
<a href="./hapi/capabilities"><code>capabilities</code></a> - list the API version and output options
31+
</li>
32+
<li>
33+
<a href="./hapi/catalog"><code>catalog</code></a> - list the datasets that are available (<span id="Ndatasets"></span> total)
34+
</li>
35+
<li>
36+
<code>info</code> - list information about parameters in a dataset, e.g,:
37+
<ul id="info">
38+
</ul>
39+
</li>
40+
<li>
41+
<code>data</code> - stream data for parameters in a dataset. Note that this server supports the non-HAPI input of <code>attach=false</code>, which tells the server to not send data as an attachment; typically a browser will display the data in a window instead of prompting a download (e.g., <a href="hapi/data?id=dataset1&parameters=scalar&time.min=1970-01-01T00:00:00.000Z&time.max=1970-01-01T00:00:10.000&attach=false">this request</a>). <span id="dataexamples">Examples for first dataset:</span>
42+
<ul id="data">
43+
</ul>
44+
</li>
45+
</ul>
46+
<p>
47+
48+
</p>
49+
<br/>
50+
<div id="showvalidation" style="cursor:pointer;color:blue;text-decoration:underline;">Run Validation Tests</div>
51+
<br/>
52+
<a id="verifierurl" style="display:none;"></a>
53+
<div id="validationresults" style="display:none;">
54+
<iframe id="iframe" style="width:100%;height:1000px;border:1px solid black"/>
55+
</div>
56+
</body>
57+
<html>

public/js/default.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
if (typeof(elem) == 'undefined') {
2+
VERIFIER = "http://hapi-server.org/verify";
3+
console.log('VERIFIER variable is not defined. Using ' + VERIFIER);
4+
}
5+
var src = VERIFIER+"?url="+window.location;
6+
7+
if (window.location.hostname == 'localhost' && !VERIFIER.match('localhost')) {
8+
$(document).ready(function () {
9+
link = "<a href='https://github.com/hapi-server/server-nodejs/blob/master/README.md#Installation'>the documentation</a>"
10+
$("#verifierurl").html("If HAPI server is run on localhost, verifier must be run on localhost. See " + link + " for instructions on starting a localhost verifier server.");
11+
12+
$("#showvalidation").click(function () {
13+
$("#verifierurl").show();
14+
})
15+
$.ajax("./hapi/catalog").done(info);
16+
})
17+
} else {
18+
// When DOM is ready, set links.
19+
$(document).ready(function () {
20+
validation();
21+
$.ajax("./hapi/catalog").done(info);
22+
})
23+
}
24+
25+
function validation() {
26+
$("#showvalidation").attr("title",src);
27+
$("#verifierurl").html(src);
28+
$("#verifierurl").attr("href",src);
29+
$("#showvalidation").click(function () {
30+
$("#verifierurl").show();
31+
$("#validationresults").show();
32+
$('#iframe').attr("src",src);
33+
})
34+
}
35+
36+
function info(json) {
37+
// Process output of /hapi/catalog
38+
// Place sample /hapi/info request links
39+
$("#Ndatasets").text(json["catalog"].length);
40+
var N = Math.min(5,json["catalog"].length);
41+
for (var i = 0;i < N;i++) {
42+
var url = "./hapi/info?id="+json["catalog"][i]["id"];
43+
var link = $("<a>")
44+
.attr("href", url)
45+
.attr("title", url)
46+
.text(url);
47+
$("#info").append("<li>");
48+
$($("#info li")[i]).append(link);
49+
}
50+
51+
data(json["catalog"][0]["id"]);
52+
}
53+
54+
function data(id) {
55+
// Get /hapi/info response for first dataset
56+
var url = "./hapi/info?id=" + id;
57+
58+
$.ajax(url).done(process);
59+
60+
function process(json, status) {
61+
if (json["sampleStartDate"] && json["sampleStopDate"]) {
62+
var start = json["sampleStartDate"];
63+
var stop = json["sampleStopDate"];
64+
} else {
65+
// Add one day
66+
// TODO: If json["cadence"], use it to determine
67+
// reasonable sampleStopDate
68+
var start = new Date(json["startDate"]);
69+
var stop = new Date(start.setDate(start.getDate() + 1)).toISOString()
70+
start = json["startDate"];
71+
}
72+
for (var i = 1; i < json.parameters.length; i++) {
73+
var url = "./hapi/data?id=" + id + "&parameters="
74+
+ json["parameters"][i]["name"]
75+
+ "&time.min=" + start + "&time.max=" + stop;
76+
var link = $("<a>")
77+
.attr("href", url+"&attach=false")
78+
.attr("title", url)
79+
.text(url);
80+
$("#data").append("<li>")
81+
$("#data li").last().append(link);
82+
}
83+
}
84+
}

public/js/jquery-1.8.2.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

verify.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/hapi-server-verifier/verify.js

0 commit comments

Comments
 (0)