-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.html
227 lines (200 loc) · 7.44 KB
/
client.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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Snowflake API Client</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
</div>
<div class="col-8">
</div>
<div class="col">
</div>
</div>
<div class="row">
<div class="col">
</div>
<div class="col-8">
<h2>Snowflake WebSocket API - Sample Client</h2>
</div>
<div class="col">
</div>
</div>
<div class="row">
<div class="col">
</div>
<div class="col-8">
<div class="form-group">
<input type="text" class="form-control" id="inputURL" placeholder="Enter API URL">
<small id="urlHelp" class="form-text text-muted">e.g. wss://xxxyyzz.execute-api.us-east-1.amazonaws.com/dev</small>
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputViewName" placeholder="View Name">
</div>
<button id="submitBtn" class="btn btn-primary">Run View</button>
</div>
<div class="col">
</div>
</div>
<div class="row">
<div class="col-12">
</div>
</div>
<div class="row">
<div class="col">
</div>
<div class="col-8">
<div class="progress">
<div id="barProgress" class="progress-bar" role="progressbar" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100" style="width: 10%"></div>
</div>
</div>
<div class="col">
</div>
</div>
<div class="row">
<div class="col-12">
</div>
</div>
<div class="row">
<div class="col-2">
</div>
<div class="col-8">
<div class="form-group">
<label for="exampleFormControlTextarea1">Response</label>
<textarea class="form-control" id="textResponse" rows="10"></textarea>
</div>
</div>
<div class="col-2">
</div>
</div>
<div class="row">
<div class="col-2">
</div>
<div class="col-2">
<small id="timer" class="form-text text-muted">
00:00.000
</small>
</div>
<div class="col-6">
<nav id="navPagination" aria-label="Page navigation example">
<ul class="pagination float-right">
<li id="btnPaginateStart" class="page-item"><a class="page-link" href="#">First</a></li>
<li id="btnPaginateNext100" class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
</nav>
</div>
<div class="col-2">
</div>
</div>
<div class="row">
<div class="col-12">
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"></script>
<script src="datamaps.all.hires.min.js"></script>
<script>
var query_id, offset, int;
var apiSocket;
function startTimer(){
var start = new Date;
int = setInterval(function() {
//$('#timer').text((new Date - start) + " ms");
var time = new Date().getTime();
var dif = time-start;
ms= dif%1000;
s = Math.floor(dif/1000)%60;
m = Math.floor(dif/1000/60)%60;
$('#timer').text( m+':'+s+'.'+ms);
}, 1);
}
function stopTimer(){
clearInterval(int);
}
$( document ).ready(function() {
offset = 0;
$("#navPagination").hide();
$("#barProgress").hide();
});
$("#submitBtn").click(function(){
startTimer();
offset = 0;
console.log('url: ' + $('#inputURL').val())
apiSocket = new WebSocket($('#inputURL').val());
$("#barProgress").show();
$('#barProgress').css('width', '10%').attr('aria-valuenow', "10");
apiSocket.onopen = function (event) {
console.log('connected!');
var msg = {
action: "run_view",
view_name: $('#inputViewName').val(),
};
console.log('sending: ' + JSON.stringify(msg));
apiSocket.send(JSON.stringify(msg));
$('#barProgress').css('width', '20%').attr('aria-valuenow', "20");
};
apiSocket.onmessage = function (event) {
$("#textResponse").text = "";
$("#textResponse").val(event.data);
//simple check to see if we have recieved a valid response
if (event.data.length > 100) {
stopTimer();
$('#barProgress').css('width', '100%').attr('aria-valuenow', "100");
response = JSON.parse(event.data);
query_id = response.query_id;
console.log('query_id: ' + query_id);
$("#navPagination").show();
} else {
$('#barProgress').css('width', '40%').attr('aria-valuenow', "40");
}
}
apiSocket.onerror = function (err) {
console.log('error: ' + err);
}
$("#btnPaginateStart").click(function(){
$('#barProgress').css('width', '30%').attr('aria-valuenow', "30");
offset = 0;
var msg = {
action: "fetch_results",
query_id: query_id,
offset: offset.toString()
};
console.log('msg: ' + JSON.stringify(msg));
apiSocket.send(JSON.stringify(msg));
$("#textResponse").val('Sent: ' + JSON.stringify(msg));
startTimer();
});
$("#btnPaginateNext100").click(function(){
$('#barProgress').css('width', '30%').attr('aria-valuenow', "30");
offset = offset + 100;
var msg = {
action: "fetch_results",
query_id: query_id,
offset: offset.toString()
};
console.log('msg: ' + JSON.stringify(msg));
apiSocket.send(JSON.stringify(msg));
$("#textResponse").val('Sent: ' + JSON.stringify(msg));
startTimer();
});
});
</script>
</body>
</html>