-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
212 lines (193 loc) · 8.58 KB
/
index.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
<html>
<head>
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function changeFormat() {
var appId = $('#selectSpec').val();
var format = $('#selectFormat').val();
$('#spec').attr('action', 'print/' + appId + "/buildreport." + format);
}
function openCapabilities() {
var url = $('#capabilities').attr('url');
window.open(url, '_capabilities')
}
function openOldApiCapabilities() {
var url = $('#old-api-capabilities').attr('url');
url = url + "app=" + $('#selectSpec').val();
window.open(url, '_info')
}
function copyRequestToTextArea() {
var att = $('#selectExample').val();
$('#specText').val(requestExamples[att]);
validateJSON();
}
function updateApp() {
var appId = $('#selectSpec').val();
$.ajax({
type: 'GET',
url: 'print/' + appId + '/capabilities.json',
success: function (data) {
var i = 0;
var formatSelect = $('#selectFormat');
formatSelect.empty();
var select = data.formats[0];
for(i = 0; i < data.formats.length; i++) {
if (data.formats[i] === 'pdf') {
select = data.formats[i];
}
formatSelect.append(new Option(data.formats[i], data.formats[i]));
}
formatSelect.val(select);
$('#spec').attr('action', 'print/' + appId + "/buildreport." + select);
var caps = $('#capabilities');
caps.attr("url", 'print/' + appId + '/capabilities.json?pretty=true');
}
});
$.ajax({
type: 'GET',
url: 'print/' + appId + '/exampleRequest.json',
dataType: 'json',
success: function (data) {
var setExample = true;
requestExamples = data;
var exampleSelect = $('#selectExample');
exampleSelect.empty();
for (var att in data) {
if (data.hasOwnProperty(att)) {
exampleSelect.append(new Option(att, att));
if (setExample) {
$('#specText').val(data[att]);
validateJSON();
setExample = false;
}
}
}
}
});
}
function disableUI(disabled) {
$('#specText').attr('disabled', disabled);
$('#selectSpec').attr('disabled', disabled);
$('#selectFormat').attr('disabled', disabled);
$('#CreateAndGetPrint').attr('disabled', disabled);
$('#PostAndPollPrint').attr('disabled', disabled);
}
function validateJSON() {
$('#messages').text("");
var data = $('#specText').val();
try {
$.parseJSON(data);
$('#validation').text("");
$('#CreateAndGetPrint').attr('disabled', false);
$('#PostAndPollPrint').attr('disabled', false);
} catch (e) {
$('#validation').text("JSON in text area is invalid, It must be fixed before posting request");
$('#CreateAndGetPrint').attr('disabled', true);
$('#PostAndPollPrint').attr('disabled', true);
}
}
function post() {
var data = encodeURIComponent($('#specText').val());
var appId = $('#selectSpec').val();
var format = $('#selectFormat').val();
disableUI(true);
var startTime = new Date().getTime();
$('#messages').text('Waiting for report...');
$.ajax({
type: 'POST',
url: 'print/' + appId + '/report.' + format,
data: data,
success: function (data) {
downloadWhenReady(startTime, $.parseJSON(data));
},
error: function (data) {
$('#messages').text('Error creating report: ' + data.statusText);
disableUI(false);
},
dataType: 'application/json'
});
}
function updateWaitingMsg(startTime, data) {
var elapsed = Math.floor((new Date().getTime() - startTime) / 100);
var time = '';
if (elapsed > 5) {
time = (elapsed / 10) +" sec";
}
$('#messages').text('Waiting for report '+ time + ": " + data.ref );
}
function downloadWhenReady(startTime, data) {
if ((new Date().getTime() - startTime) > 30000) {
$('#messages').text('Gave up waiting after 30 seconds')
disableUI(false);
} else {
updateWaitingMsg(startTime, data);
setTimeout(function () {
$.getJSON(data.statusURL, function (statusData) {
if (!statusData.done) {
downloadWhenReady(startTime, data);
} else {
window.location = statusData.downloadURL;
$('#messages').text('Downloading: '+data.ref);
disableUI(false);
}
}, function error(data) {$('#messages').text('Error occurred requesting status');});
}, 500);
}
}
function init() {
$.ajax({
type: 'GET',
url: 'print/apps.json',
success: function (data) {
var specSelect = $('#selectSpec');
var i = 0;
for (i = 0; i < data.length; i++) {
specSelect.append(new Option(data[i], data[i]));
}
specSelect.val(data[0]);
updateApp();
}
});
}
</script>
</head>
<body onload="init()">
<h1>Test Print</h1>
<h2><span id="messages"></span></h2>
<h3><span id="validation" style="color:red"></span></h3>
<form id="spec" action="print/buildreport.pdf" method="post">
<textarea id="specText" name="spec" style="width: 100%" rows="30" oninput="validateJSON()">
</textarea>
<p>
<table>
<tr><td><label for="selectSpec">Kies voorbeeld (KAD=Kadaster):</label></td><td><select id="selectSpec" onchange="updateApp()"></select></td></tr>
<tr><td><label for="selectExample">Sample Request Data:</label></td><td><select id="selectExample" onchange="copyRequestToTextArea()"></select></td></tr>
<tr><td><label for="selectFormat">Output Formaat:</label></td><td><select id="selectFormat" onchange="changeFormat()"></select></td></tr>
</table>
</p>
<p>
<button id="CreateAndGetPrint" type="submit">Create And Get Print</button>
<button id="PostAndPollPrint" type="button" onclick="javascript:post()">Post and Poll Print</button>
<button id="capabilities"
type="button"
url="print/capabilities.json?pretty=true"
onclick="openCapabilities()">Capabilities</button>
</p>
<p>
<button id="old-api-capabilities"
type="button"
url="print/dep/info.json?"
onclick="openOldApiCapabilities()">Old API Info (Capabilities)</button>
</p>
</form>
<button id="list-fonts" type="button" onclick="window.open('print/fonts', '_fonts')">List available fonts</button>
<h2>Performance and Health Metrics:</h2>
<p>
<button id="metrics" type="button" onclick="window.open('metrics/metrics?pretty=true', '_metrics')">Metrics</button>
<button id="healthcheck" type="button" onclick="window.open('metrics/healthcheck', '_metrics')">Health Check</button>
<button id="ping" type="button" onclick="window.open('metrics/ping', '_metrics')">Ping</button>
<button id="threads" type="button" onclick="window.open('metrics/threads', '_metrics')">Threads</button>
</p>
</body>
</html>