forked from hapi-server/server-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle.htm
145 lines (135 loc) · 5.17 KB
/
single.htm
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>__CATALOG__</title>
<link rel="icon" href="//hapi-server.org/favicon.ico" type="image/x-icon">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
VERIFIER = "__VERIFIER__";
PLOTSERVER = "__PLOTSERVER__";
if (window.location.hostname === "localhost") {
VERIFIER = "http://localhost:9999";
PLOTSERVER = "http://localhost:5000";
}
</script>
</head>
<body>
<h2>HAPI Server for __CATALOG__ datasets</h2>
<p>
This server supports the <a href="https://github.com/hapi-server/data-specification">HAPI __VERSION__ API</a> specification for streaming of time series data.
</p>
<p>
The server responds to <code>GET</code> requests to the following <a href="https://github.com/hapi-server/data-specification/tree/v1.1.0#endpoints">HAPI endpoints</a>:
</p>
<ul>
<li>
<a href="hapi/capabilities"><code>capabilities</code></a> - list the API version and output options
</li>
<li>
<a href="hapi/catalog"><code>catalog</code></a> - list the datasets that are available (<span id="Ndatasets"></span> total)
</li>
<li>
<code>info</code> - list information about parameters in a dataset, e.g,
<ul id="info">
</ul>
</li>
<li>
<code>data</code> - stream data for parameters in a dataset. <span id="dataexamples">Examples for first dataset:</span>
<ul id="data">
</ul>
</li>
</ul>
<a id="viviz" href="">Plots</a>
<p>
Server contact: __SERVERCONTACT__; Data contact __DATACONTACT__
</p>
<p id="verifierp">
<a id="verifier" href="">Run validation tests</a>
</p>
<script>
let ROOT = "";
let VERSION = '__VERSION__';
let datasetKey = "id";
if (parseInt(VERSION.substring(0)) >= 3) {
datasetKey = "dataset";
}
$(document).ready(function () {
if (location.href.endsWith("/")) {
// This page should be served from a URL that ends in "hapi".
// If this page is also served from a URL ending with "hapi/",
// we need to fix the links. (The server should 301
// redirect "hapi/" to "hapi" so this fix is not needed.)
ROOT = "../"
$("[href]").each(function(idx,el) {
let href = el.href.replace();
$(el).attr('href',ROOT+el.href);
})
}
let vargs = "?url=" + window.location.href;
$("#verifier").attr("href",VERIFIER + vargs);
let pargs = "?server=" + window.location.href + "&format=gallery";
$("#viviz").attr("href",PLOTSERVER + pargs);
if (!window.location.hostname == 'localhost') {
$('#verifierp')
.append('Remove validation link on production sites.');
} else {
let note = " <span style='background-color:yellow'>If HAPI server URL domain name is localhost, plot server must be run on localhost for this link to work. See <code>hapi-server -h</code>.</span>"
if ($("#viviz").attr("href").match('localhost')) {
$('#viviz').after(note);
}
if ($("#verifier").attr("href").match('localhost')) {
$('#verifier')
.after(note.replace("plot server","verifier server"));
}
}
$.ajax(ROOT+"hapi/catalog").done(info);
})
function info(json) {
// Process output of /hapi/catalog
// Place sample /hapi/info request links
$("#Ndatasets").text(json["catalog"].length);
var N = Math.min(5,json["catalog"].length);
for (var i = 0;i < N;i++) {
var url = ROOT+"hapi/info?"+datasetKey+"="+json["catalog"][i]["id"];
var link = $("<a>")
.attr("href", url)
.attr("title", url)
.text(url);
$("#info").append("<li>");
$($("#info li")[i]).append(link);
}
data(json["catalog"][0]["id"]);
}
function data(id) {
// Get /hapi/info response for first dataset
var url = ROOT+"hapi/info?"+datasetKey+"=" + id;
$.ajax(url).done(process);
function process(json, status) {
if (json["sampleStartDate"] && json["sampleStopDate"]) {
var start = json["sampleStartDate"];
var stop = json["sampleStopDate"];
} else {
// Add one day
// TODO: If json["cadence"], use it to determine
// reasonable sampleStopDate
var start = new Date(json["startDate"]);
var stop = new Date(start.setDate(start.getDate() + 1)).toISOString()
start = json["startDate"];
}
for (var i = 1; i < json.parameters.length; i++) {
var url = ROOT+"hapi/data?"+datasetKey+"=" + id + "¶meters="
+ json["parameters"][i]["name"]
+ "&time.min=" + start + "&time.max=" + stop;
var link = $("<a>")
.attr("href", url)
.attr("title", url)
.text(url);
$("#data").append("<li>")
$("#data li").last().append(link);
}
}
}
</script>
</body>
</html>