@hpcc-js/other 2.17.1 → 2.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +43 -43
- package/README.md +41 -41
- package/dist/index.es6.js +5 -5
- package/dist/index.es6.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +5 -5
- package/src/Audio.ts +83 -83
- package/src/AutoCompleteText.css +21 -21
- package/src/AutoCompleteText.ts +124 -124
- package/src/CalendarHeatMap.css +26 -26
- package/src/CalendarHeatMap.ts +243 -243
- package/src/Comms.ts +1085 -1085
- package/src/ESP.ts +451 -451
- package/src/HPCCBadge.ts +220 -220
- package/src/HeatMap.ts +135 -135
- package/src/Html.css +5 -5
- package/src/Html.ts +44 -44
- package/src/IconList.css +3 -3
- package/src/IconList.ts +86 -86
- package/src/Legend.css +85 -85
- package/src/Legend.ts +220 -220
- package/src/MorphText.css +11 -11
- package/src/MorphText.ts +102 -102
- package/src/NestedTable.ts +51 -51
- package/src/Opportunity.css +80 -80
- package/src/Opportunity.ts +488 -488
- package/src/Paginator.css +120 -120
- package/src/Paginator.ts +164 -164
- package/src/Persist.ts +151 -151
- package/src/PropertyEditor.css +130 -130
- package/src/PropertyEditor.ts +750 -750
- package/src/RadioCheckbox.css +6 -6
- package/src/RadioCheckbox.ts +123 -123
- package/src/Select.css +7 -7
- package/src/Select.ts +120 -120
- package/src/Table.css +92 -92
- package/src/Table.ts +1050 -1050
- package/src/ThemeEditor.css +195 -195
- package/src/ThemeEditor.ts +744 -744
- package/src/__package__.ts +3 -3
- package/src/index.ts +23 -23
- package/types/__package__.d.ts +2 -2
- package/types-3.4/__package__.d.ts +2 -2
package/src/Comms.ts
CHANGED
|
@@ -1,1085 +1,1085 @@
|
|
|
1
|
-
import { Utility } from "@hpcc-js/common";
|
|
2
|
-
|
|
3
|
-
const TIMEOUT_DEFAULT = 60;
|
|
4
|
-
function espValFix(val) {
|
|
5
|
-
if (val === undefined || val === null) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
if (!val.trim) {
|
|
9
|
-
if (val.Row) {
|
|
10
|
-
return espRowFix(val.Row);
|
|
11
|
-
}
|
|
12
|
-
return val;
|
|
13
|
-
}
|
|
14
|
-
const retVal = val.trim();
|
|
15
|
-
if (retVal !== "" && !isNaN(retVal)) {
|
|
16
|
-
if (retVal.length <= 1 || retVal[0] !== "0" || retVal[1] === ".") {
|
|
17
|
-
return Number(retVal);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return retVal;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function espRowFix(row) {
|
|
24
|
-
for (const key in row) {
|
|
25
|
-
row[key] = espValFix(row[key]);
|
|
26
|
-
}
|
|
27
|
-
return row;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class ESPUrl {
|
|
31
|
-
protected _protocol = "http:";
|
|
32
|
-
protected _hostname = "localhost";
|
|
33
|
-
protected _url;
|
|
34
|
-
protected _port;
|
|
35
|
-
protected _search;
|
|
36
|
-
protected _pathname;
|
|
37
|
-
protected _params;
|
|
38
|
-
protected _hash;
|
|
39
|
-
protected _host;
|
|
40
|
-
|
|
41
|
-
constructor() {
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
url(_: string): this;
|
|
45
|
-
url(): string;
|
|
46
|
-
url(_?): string | this {
|
|
47
|
-
if (!arguments.length) return this._url;
|
|
48
|
-
this._url = _;
|
|
49
|
-
const parser = document.createElement("a");
|
|
50
|
-
parser.href = this._url;
|
|
51
|
-
// eslint-disable-next-line no-self-assign
|
|
52
|
-
parser.href = parser.href; // This fixes an IE9/IE10 DOM value issue
|
|
53
|
-
|
|
54
|
-
const params = {};
|
|
55
|
-
if (parser.search.length) {
|
|
56
|
-
let tmp: any = parser.search;
|
|
57
|
-
if (tmp[0] === "?") {
|
|
58
|
-
tmp = tmp.substring(1);
|
|
59
|
-
}
|
|
60
|
-
tmp = tmp.split("&");
|
|
61
|
-
tmp.map(function (item) {
|
|
62
|
-
const tmpItem = item.split("=");
|
|
63
|
-
params[decodeURIComponent(tmpItem[0])] = decodeURIComponent(tmpItem[1]);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
this._protocol = parser.protocol;
|
|
67
|
-
this._hostname = parser.hostname;
|
|
68
|
-
this._port = parser.port;
|
|
69
|
-
this._pathname = parser.pathname;
|
|
70
|
-
while (this._pathname.length && this._pathname[0] === "/") {
|
|
71
|
-
this._pathname = this._pathname.substring(1);
|
|
72
|
-
}
|
|
73
|
-
this._search = parser.search;
|
|
74
|
-
this._params = params;
|
|
75
|
-
this._hash = parser.hash;
|
|
76
|
-
this._host = parser.host;
|
|
77
|
-
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
protocol(_: string): this;
|
|
82
|
-
protocol(): string;
|
|
83
|
-
protocol(_?: string): string | this {
|
|
84
|
-
if (!arguments.length) return this._protocol;
|
|
85
|
-
this._protocol = _;
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
hostname(_: string): this;
|
|
90
|
-
hostname(): string;
|
|
91
|
-
hostname(_?: string): string | this {
|
|
92
|
-
if (!arguments.length) return this._hostname;
|
|
93
|
-
this._hostname = _;
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
port(_: string): this;
|
|
98
|
-
port(): string;
|
|
99
|
-
port(_?: string) {
|
|
100
|
-
if (!arguments.length) return this._port;
|
|
101
|
-
this._port = _;
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
search(_: string): this;
|
|
106
|
-
search(): string;
|
|
107
|
-
search(_?: string) {
|
|
108
|
-
if (!arguments.length) return this._search;
|
|
109
|
-
this._search = _;
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
pathname(_: string): this;
|
|
114
|
-
pathname(): string;
|
|
115
|
-
pathname(_?: string) {
|
|
116
|
-
if (!arguments.length) return this._pathname;
|
|
117
|
-
this._pathname = _;
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
hash(_: string): this;
|
|
122
|
-
hash(): string;
|
|
123
|
-
hash(_?: string) {
|
|
124
|
-
if (!arguments.length) return this._hash;
|
|
125
|
-
this._hash = _;
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
host(_: string): this;
|
|
130
|
-
host(): string;
|
|
131
|
-
host(_?: string) {
|
|
132
|
-
if (!arguments.length) return this._host;
|
|
133
|
-
this._host = _;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
params(_: string): this;
|
|
138
|
-
params(): string;
|
|
139
|
-
params(_?: string) {
|
|
140
|
-
if (!arguments.length) return this._params;
|
|
141
|
-
this._params = _;
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
param(key: string) {
|
|
146
|
-
return this._params[key];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
isWsWorkunits() {
|
|
150
|
-
return this._pathname.toLowerCase().indexOf("wsworkunits") >= 0 || this._params["Wuid"];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
isWorkunitResult() {
|
|
154
|
-
return this.isWsWorkunits() && (this._params["Sequence"] || this._params["ResultName"]);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
isWsEcl() {
|
|
158
|
-
return this._pathname.toLowerCase().indexOf("wsecl") >= 0 || (this._params["QuerySetId"] && this._params["Id"]);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
isWsWorkunits_GetStats() {
|
|
162
|
-
return this._pathname.toLowerCase().indexOf("wsworkunits/wugetstats") >= 0 && this._params["WUID"];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
getUrl(overrides) {
|
|
166
|
-
overrides = overrides || {};
|
|
167
|
-
return (overrides.protocol !== undefined ? overrides.protocol : this._protocol) + "//" +
|
|
168
|
-
(overrides.hostname !== undefined ? overrides.hostname : this._hostname) + ":" +
|
|
169
|
-
(overrides.port !== undefined ? overrides.port : this._port) + "/" +
|
|
170
|
-
(overrides.pathname !== undefined ? overrides.pathname : this._pathname);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function ESPMappings(mappings) {
|
|
175
|
-
this._mappings = mappings;
|
|
176
|
-
this._reverseMappings = {};
|
|
177
|
-
for (const resultName in this._mappings) {
|
|
178
|
-
this._reverseMappings[resultName] = {};
|
|
179
|
-
for (const key in this._mappings[resultName]) {
|
|
180
|
-
this._reverseMappings[resultName][this._mappings[resultName][key]] = key;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
ESPMappings.prototype.contains = function (resultName, origField) {
|
|
186
|
-
return Utility.exists(resultName + "." + origField, this._mappings);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
ESPMappings.prototype.mapResult = function (response, resultName) {
|
|
190
|
-
const mapping = this._mappings[resultName];
|
|
191
|
-
if (mapping) {
|
|
192
|
-
response[resultName] = response[resultName].map(function (item) {
|
|
193
|
-
let row = [];
|
|
194
|
-
if (mapping.x && mapping.x instanceof Array) {
|
|
195
|
-
// LINE Mapping ---
|
|
196
|
-
row = [];
|
|
197
|
-
for (let i = 0; i < mapping.x.length; ++i) {
|
|
198
|
-
row.push(item[mapping.y[i]]);
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
// Regular Mapping ---
|
|
202
|
-
for (const key in mapping) {
|
|
203
|
-
if (mapping[key] === "label") {
|
|
204
|
-
row[0] = item[key];
|
|
205
|
-
} else if (mapping[key] === "weight") {
|
|
206
|
-
row[1] = item[key];
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return row;
|
|
211
|
-
}, this);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
ESPMappings.prototype.mapResponse = function (response) {
|
|
216
|
-
for (const key in response) {
|
|
217
|
-
this.mapResult(response, key);
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const serialize = function (obj) {
|
|
222
|
-
const str = [];
|
|
223
|
-
for (const key in obj) {
|
|
224
|
-
if (obj.hasOwnProperty(key)) {
|
|
225
|
-
const val = obj[key];
|
|
226
|
-
if (val !== undefined && val !== null) {
|
|
227
|
-
str.push(encodeURIComponent(key) + "=" + encodeURIComponent(val));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return str.join("&");
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
let jsonp = function (url, request, timeout) {
|
|
235
|
-
return new Promise(function (resolve, reject) {
|
|
236
|
-
let respondedTimeout = timeout * 1000;
|
|
237
|
-
const respondedTick = 5000;
|
|
238
|
-
const callbackName = "jsonp_callback_" + Math.round(Math.random() * 999999);
|
|
239
|
-
window[callbackName] = function (response) {
|
|
240
|
-
respondedTimeout = 0;
|
|
241
|
-
doCallback();
|
|
242
|
-
resolve(response);
|
|
243
|
-
};
|
|
244
|
-
const script = document.createElement("script");
|
|
245
|
-
script.src = url + (url.indexOf("?") >= 0 ? "&" : "?") + "jsonp=" + callbackName + "&" + serialize(request);
|
|
246
|
-
document.body.appendChild(script);
|
|
247
|
-
const progress = setInterval(function () {
|
|
248
|
-
if (respondedTimeout <= 0) {
|
|
249
|
-
clearInterval(progress);
|
|
250
|
-
} else {
|
|
251
|
-
respondedTimeout -= respondedTick;
|
|
252
|
-
if (respondedTimeout <= 0) {
|
|
253
|
-
clearInterval(progress);
|
|
254
|
-
doCallback();
|
|
255
|
-
reject(Error("Request timeout: " + script.src));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}, respondedTick);
|
|
259
|
-
|
|
260
|
-
function doCallback() {
|
|
261
|
-
delete window[callbackName];
|
|
262
|
-
document.body.removeChild(script);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
export class Comms extends ESPUrl {
|
|
268
|
-
protected _proxyMappings;
|
|
269
|
-
protected _mappings;
|
|
270
|
-
protected _timeout;
|
|
271
|
-
protected _hipieResults;
|
|
272
|
-
protected _hipieResultsLength;
|
|
273
|
-
|
|
274
|
-
constructor() {
|
|
275
|
-
super();
|
|
276
|
-
this._proxyMappings = {};
|
|
277
|
-
this._mappings = new ESPMappings({});
|
|
278
|
-
this._timeout = TIMEOUT_DEFAULT;
|
|
279
|
-
this._hipieResults = {};
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
hipieResults(_) {
|
|
283
|
-
if (!arguments.length) return this._hipieResults;
|
|
284
|
-
this._hipieResultsLength = 0;
|
|
285
|
-
this._hipieResults = {};
|
|
286
|
-
const context = this;
|
|
287
|
-
_.forEach(function (item) {
|
|
288
|
-
context._hipieResultsLength++;
|
|
289
|
-
context._hipieResults[item.id] = item;
|
|
290
|
-
});
|
|
291
|
-
return this;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
jsonp(url, request) {
|
|
295
|
-
for (const key in this._proxyMappings) {
|
|
296
|
-
const newUrlParts = url.split(key);
|
|
297
|
-
const newUrl = newUrlParts[0];
|
|
298
|
-
if (newUrlParts.length > 1) {
|
|
299
|
-
const espUrl = new ESPUrl()
|
|
300
|
-
.url(url)
|
|
301
|
-
;
|
|
302
|
-
url = newUrl + this._proxyMappings[key];
|
|
303
|
-
request.IP = espUrl.hostname();
|
|
304
|
-
request.PORT = espUrl.port();
|
|
305
|
-
if (newUrlParts.length > 0) {
|
|
306
|
-
request.PATH = newUrlParts[1];
|
|
307
|
-
}
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return jsonp(url, request, this.timeout());
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
ajax(method, url, request?) {
|
|
315
|
-
return new Promise(function (resolve, reject) {
|
|
316
|
-
let uri = url;
|
|
317
|
-
if (method === "GET" && request) {
|
|
318
|
-
uri += "?" + serialize(request);
|
|
319
|
-
}
|
|
320
|
-
const xhr: any = new XMLHttpRequest();
|
|
321
|
-
xhr.onload = function (e) {
|
|
322
|
-
if (this.status >= 200 && this.status < 300) {
|
|
323
|
-
resolve(JSON.parse(this.response));
|
|
324
|
-
} else {
|
|
325
|
-
reject(Error(this.statusText));
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
xhr.onerror = function () {
|
|
329
|
-
reject(Error(this.statusText));
|
|
330
|
-
};
|
|
331
|
-
xhr.open(method, uri);
|
|
332
|
-
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
333
|
-
if (method === "GET") {
|
|
334
|
-
xhr.send();
|
|
335
|
-
} else {
|
|
336
|
-
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
337
|
-
xhr.send(serialize(request));
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
get(url, request?) {
|
|
343
|
-
return this.ajax("GET", url, request);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
post(url, request) {
|
|
347
|
-
return this.ajax("POST", url, request);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
mappings(_?) {
|
|
351
|
-
if (!arguments.length) return this._mappings;
|
|
352
|
-
this._mappings = new ESPMappings(_);
|
|
353
|
-
return this;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
proxyMappings(_?) {
|
|
357
|
-
if (!arguments.length) return this._proxyMappings;
|
|
358
|
-
this._proxyMappings = _;
|
|
359
|
-
return this;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
timeout(_?) {
|
|
363
|
-
if (!arguments.length) return this._timeout;
|
|
364
|
-
this._timeout = _ || TIMEOUT_DEFAULT;
|
|
365
|
-
return this;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
export class Basic extends Comms {
|
|
370
|
-
|
|
371
|
-
protected _cacheCalls;
|
|
372
|
-
|
|
373
|
-
constructor() {
|
|
374
|
-
super();
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
cacheCalls(_?) {
|
|
378
|
-
if (!arguments.length) return this._cacheCalls;
|
|
379
|
-
this._cacheCalls = _;
|
|
380
|
-
return this;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
call(request, callback) {
|
|
384
|
-
const url = this._url + (this._url.indexOf("?") >= 0 ? "&" : "?") + serialize(request);
|
|
385
|
-
if (this._cacheCalls) {
|
|
386
|
-
const context = this;
|
|
387
|
-
return new Promise(function (resolve, reject) {
|
|
388
|
-
const response = JSON.parse(localStorage.getItem("hpcc.viz." + url));
|
|
389
|
-
if (!response) {
|
|
390
|
-
throw Error("not cached");
|
|
391
|
-
}
|
|
392
|
-
if (callback) {
|
|
393
|
-
console.error("Deprecated: callback, use promise (Basic.prototype.call)");
|
|
394
|
-
callback(response);
|
|
395
|
-
}
|
|
396
|
-
resolve(response);
|
|
397
|
-
}).catch(function (response) {
|
|
398
|
-
return context.get(url).then(function (response2) {
|
|
399
|
-
localStorage.setItem("hpcc.viz." + url, JSON.stringify(response2));
|
|
400
|
-
if (callback) {
|
|
401
|
-
console.error("Deprecated: callback, use promise (Basic.prototype.call)");
|
|
402
|
-
callback(response2);
|
|
403
|
-
}
|
|
404
|
-
return response2;
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
} else {
|
|
408
|
-
localStorage.removeItem("hpcc.viz." + url);
|
|
409
|
-
return this.get(url).then(function (response) {
|
|
410
|
-
if (callback) {
|
|
411
|
-
console.error("Deprecated: callback, use promise (Basic.prototype.call)");
|
|
412
|
-
callback(response);
|
|
413
|
-
}
|
|
414
|
-
return response;
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function locateRoxieResponse(response): object {
|
|
421
|
-
// v5 and v6 compatible ---
|
|
422
|
-
for (const key in response) {
|
|
423
|
-
if (response[key].Row && response[key].Row instanceof Array) {
|
|
424
|
-
return response;
|
|
425
|
-
}
|
|
426
|
-
let retVal;
|
|
427
|
-
if (typeof (response[key]) !== "string") {
|
|
428
|
-
retVal = locateRoxieResponse(response[key]);
|
|
429
|
-
}
|
|
430
|
-
if (retVal) {
|
|
431
|
-
return retVal;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return null;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
function locateRoxieException(response) {
|
|
438
|
-
for (const key in response) {
|
|
439
|
-
if (response[key].Exception && response[key].Exception instanceof Array) {
|
|
440
|
-
return response[key];
|
|
441
|
-
}
|
|
442
|
-
const retVal = locateRoxieException(response[key]);
|
|
443
|
-
if (retVal) {
|
|
444
|
-
return retVal;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
return null;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
export class WsECL extends Comms {
|
|
451
|
-
|
|
452
|
-
protected _target;
|
|
453
|
-
protected _query;
|
|
454
|
-
|
|
455
|
-
constructor() {
|
|
456
|
-
super();
|
|
457
|
-
|
|
458
|
-
this._port = "8002";
|
|
459
|
-
this._target = "";
|
|
460
|
-
this._query = "";
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
url(_?) {
|
|
464
|
-
const retVal = super.url.apply(this, arguments);
|
|
465
|
-
if (arguments.length) {
|
|
466
|
-
// http://localhost:8010/esp/files/stub.htm?QuerySetId=roxie&Id=stock.3&Widget=QuerySetDetailsWidget
|
|
467
|
-
this._port = this._port === "8010" ? "8002" : this._port; // Need a better way ---
|
|
468
|
-
for (const key in this._params) {
|
|
469
|
-
switch (key) {
|
|
470
|
-
case "QuerySetId":
|
|
471
|
-
this.target(this._params[key]);
|
|
472
|
-
break;
|
|
473
|
-
case "Id":
|
|
474
|
-
this.query(this._params[key]);
|
|
475
|
-
break;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
let pathParts;
|
|
480
|
-
let queryParts;
|
|
481
|
-
if (!this._target || !this._query) {
|
|
482
|
-
// http://localhost:8002/WsEcl/forms/default/query/roxie/wecare
|
|
483
|
-
pathParts = this._pathname.split("/query/");
|
|
484
|
-
if (pathParts.length >= 2) {
|
|
485
|
-
queryParts = pathParts[1].split("/");
|
|
486
|
-
if (queryParts.length >= 2) {
|
|
487
|
-
this.target(queryParts[0]);
|
|
488
|
-
this.query(queryParts[1]);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
return retVal;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
target(_?) {
|
|
497
|
-
if (!arguments.length) return this._target;
|
|
498
|
-
this._target = _;
|
|
499
|
-
return this;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
query(_?) {
|
|
503
|
-
if (!arguments.length) return this._query;
|
|
504
|
-
this._query = _;
|
|
505
|
-
return this;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
constructUrl() {
|
|
509
|
-
return Comms.prototype.getUrl.call(this, {
|
|
510
|
-
pathname: "WsEcl/submit/query/" + this._target + "/" + this._query + "/json"
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
call(target, request, callback) {
|
|
515
|
-
target = target || {};
|
|
516
|
-
target.target = target.target || this._target;
|
|
517
|
-
target.query = target.query || this._query;
|
|
518
|
-
const context = this;
|
|
519
|
-
const url = this.getUrl({
|
|
520
|
-
pathname: "WsEcl/submit/query/" + target.target + "/" + target.query + "/json"
|
|
521
|
-
});
|
|
522
|
-
return this.jsonp(url, request).then(function (response: any) {
|
|
523
|
-
let _response = locateRoxieResponse(response);
|
|
524
|
-
if (!_response) {
|
|
525
|
-
_response = locateRoxieException(response);
|
|
526
|
-
}
|
|
527
|
-
response = _response;
|
|
528
|
-
|
|
529
|
-
// Check for exceptions
|
|
530
|
-
if (response.Exception) {
|
|
531
|
-
throw Error(response.Exception.reduce(function (previousValue, exception, index, array) {
|
|
532
|
-
if (previousValue.length) {
|
|
533
|
-
previousValue += "\n";
|
|
534
|
-
}
|
|
535
|
-
return previousValue + exception.Source + " " + exception.Code + ": " + exception.Message;
|
|
536
|
-
}, ""));
|
|
537
|
-
}
|
|
538
|
-
// Remove "response.result.Row"
|
|
539
|
-
for (const key in response) {
|
|
540
|
-
if (response[key].Row) {
|
|
541
|
-
response[key] = response[key].Row.map(espRowFix);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
context._mappings.mapResponse(response);
|
|
545
|
-
if (callback) {
|
|
546
|
-
console.error("Deprecated: callback, use promise (WsECL.prototype.call)");
|
|
547
|
-
callback(response);
|
|
548
|
-
}
|
|
549
|
-
return response;
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
send(request, callback) {
|
|
554
|
-
return this.call({ target: this._target, query: this._query }, request, callback);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
export class WsWorkunits extends Comms {
|
|
559
|
-
|
|
560
|
-
protected _wuid = "";
|
|
561
|
-
protected _jobname = "";
|
|
562
|
-
protected _sequence = null;
|
|
563
|
-
protected _resultName = null;
|
|
564
|
-
|
|
565
|
-
protected _fetchResultNamesPromise = null;
|
|
566
|
-
protected _fetchResultPromise = {};
|
|
567
|
-
protected _resultNameCache = {};
|
|
568
|
-
protected _resultNameCacheCount = 0;
|
|
569
|
-
protected _total;
|
|
570
|
-
|
|
571
|
-
constructor() {
|
|
572
|
-
super();
|
|
573
|
-
this._port = "8010";
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
url(_?) {
|
|
577
|
-
const retVal = Comms.prototype.url.apply(this, arguments);
|
|
578
|
-
if (arguments.length) {
|
|
579
|
-
// http://localhost:8010/WsWorkunit/WuResult?Wuid=xxx&ResultName=yyy
|
|
580
|
-
for (const key in this._params) {
|
|
581
|
-
switch (key) {
|
|
582
|
-
case "Wuid":
|
|
583
|
-
this.wuid(this._params[key]);
|
|
584
|
-
break;
|
|
585
|
-
case "ResultName":
|
|
586
|
-
this.resultName(this._params[key]);
|
|
587
|
-
break;
|
|
588
|
-
case "Sequence":
|
|
589
|
-
this.sequence(this._params[key]);
|
|
590
|
-
break;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
if (!this._wuid) {
|
|
594
|
-
// http://localhost:8010/WsWorkunits/res/W20140922-213329/c:/temp/index.html
|
|
595
|
-
const urlParts = this._url.split("/res/");
|
|
596
|
-
if (urlParts.length >= 2) {
|
|
597
|
-
const urlParts2 = urlParts[1].split("/");
|
|
598
|
-
this.wuid(urlParts2[0]);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return retVal;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
wuid(_?) {
|
|
606
|
-
if (!arguments.length) return this._wuid;
|
|
607
|
-
this._wuid = _;
|
|
608
|
-
return this;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
jobname(_?) {
|
|
612
|
-
if (!arguments.length) return this._jobname;
|
|
613
|
-
this._jobname = _;
|
|
614
|
-
return this;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
sequence(_?) {
|
|
618
|
-
if (!arguments.length) return this._sequence;
|
|
619
|
-
this._sequence = _;
|
|
620
|
-
return this;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
resultName(_?) {
|
|
624
|
-
if (!arguments.length) return this._resultName;
|
|
625
|
-
this._resultName = _;
|
|
626
|
-
return this;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
appendParam(label, value, params) {
|
|
630
|
-
if (value) {
|
|
631
|
-
if (params) {
|
|
632
|
-
params += "&";
|
|
633
|
-
}
|
|
634
|
-
return params + label + "=" + value;
|
|
635
|
-
}
|
|
636
|
-
return params;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
constructUrl() {
|
|
640
|
-
const url = Comms.prototype.getUrl.call(this, {
|
|
641
|
-
pathname: "WsWorkunits/res/" + this._wuid + "/"
|
|
642
|
-
});
|
|
643
|
-
let params = "";
|
|
644
|
-
params = this.appendParam("ResultName", this._resultName, params);
|
|
645
|
-
return url + (params ? "?" + params : "");
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
_fetchResult(target, callback, skipMapping) {
|
|
649
|
-
target = target || {};
|
|
650
|
-
if (!this._fetchResultPromise[target.resultname]) {
|
|
651
|
-
target._start = target._start || 0;
|
|
652
|
-
target._count = target._count || -1;
|
|
653
|
-
const url = this.getUrl({
|
|
654
|
-
pathname: "WsWorkunits/WUResult.json"
|
|
655
|
-
});
|
|
656
|
-
const request = {
|
|
657
|
-
Wuid: target.wuid,
|
|
658
|
-
ResultName: target.resultname,
|
|
659
|
-
SuppressXmlSchema: true,
|
|
660
|
-
Start: target._start,
|
|
661
|
-
Count: target._count
|
|
662
|
-
};
|
|
663
|
-
this._resultNameCache[target.resultname] = {};
|
|
664
|
-
const context = this;
|
|
665
|
-
this._fetchResultPromise[target.resultname] = this.jsonp(url, request).then(function (response: any) {
|
|
666
|
-
// Remove "xxxResponse.Result"
|
|
667
|
-
for (const key in response) {
|
|
668
|
-
if (!response[key].Result) {
|
|
669
|
-
throw new Error("No result found.");
|
|
670
|
-
}
|
|
671
|
-
context._total = response[key].Total;
|
|
672
|
-
response = response[key].Result;
|
|
673
|
-
for (const responseKey in response) {
|
|
674
|
-
response = response[responseKey].Row.map(espRowFix);
|
|
675
|
-
break;
|
|
676
|
-
}
|
|
677
|
-
break;
|
|
678
|
-
}
|
|
679
|
-
context._resultNameCache[target.resultname] = response;
|
|
680
|
-
if (!skipMapping) {
|
|
681
|
-
context._mappings.mapResult(context._resultNameCache, target.resultname);
|
|
682
|
-
}
|
|
683
|
-
if (callback) {
|
|
684
|
-
console.error("Deprecated: callback, use promise (WsWorkunits.prototype._fetchResult)");
|
|
685
|
-
callback(context._resultNameCache[target.resultname]);
|
|
686
|
-
}
|
|
687
|
-
return context._resultNameCache[target.resultname];
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
return this._fetchResultPromise[target.resultname];
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
fetchResult(target, callback, skipMapping) {
|
|
694
|
-
if (target.wuid) {
|
|
695
|
-
return this._fetchResult(target, callback, skipMapping);
|
|
696
|
-
} else if (target.jobname) {
|
|
697
|
-
const context = this;
|
|
698
|
-
return this.WUQuery(target, function (response) {
|
|
699
|
-
target.wuid = response[0].Wuid;
|
|
700
|
-
return context._fetchResult(target, callback, skipMapping);
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
WUQuery(_request, callback) {
|
|
706
|
-
const url = this.getUrl({
|
|
707
|
-
pathname: "WsWorkunits/WUQuery.json"
|
|
708
|
-
});
|
|
709
|
-
const request = {
|
|
710
|
-
Jobname: _request.jobname,
|
|
711
|
-
Count: 1
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
this._resultNameCache = {};
|
|
715
|
-
this._resultNameCacheCount = 0;
|
|
716
|
-
return this.jsonp(url, request).then(function (response: any) {
|
|
717
|
-
if (!Utility.exists("WUQueryResponse.Workunits.ECLWorkunit", response)) {
|
|
718
|
-
throw Error("No workunit found.");
|
|
719
|
-
}
|
|
720
|
-
response = response.WUQueryResponse.Workunits.ECLWorkunit;
|
|
721
|
-
if (callback) {
|
|
722
|
-
console.error("Deprecated: callback, use promise (WsWorkunits.prototype.WUQuery)");
|
|
723
|
-
callback(response);
|
|
724
|
-
}
|
|
725
|
-
return response;
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
fetchResultNames(callback?) {
|
|
730
|
-
if (!this._fetchResultNamesPromise) {
|
|
731
|
-
const url = this.getUrl({
|
|
732
|
-
pathname: "WsWorkunits/WUInfo.json"
|
|
733
|
-
});
|
|
734
|
-
const request = {
|
|
735
|
-
Wuid: this._wuid,
|
|
736
|
-
TruncateEclTo64k: true,
|
|
737
|
-
IncludeExceptions: false,
|
|
738
|
-
IncludeGraphs: false,
|
|
739
|
-
IncludeSourceFiles: false,
|
|
740
|
-
IncludeResults: true,
|
|
741
|
-
IncludeResultsViewNames: false,
|
|
742
|
-
IncludeVariables: false,
|
|
743
|
-
IncludeTimers: false,
|
|
744
|
-
IncludeResourceURLs: false,
|
|
745
|
-
IncludeDebugValues: false,
|
|
746
|
-
IncludeApplicationValues: false,
|
|
747
|
-
IncludeWorkflows: false,
|
|
748
|
-
IncludeXmlSchemas: false,
|
|
749
|
-
SuppressResultSchemas: true
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
this._resultNameCache = {};
|
|
753
|
-
this._resultNameCacheCount = 0;
|
|
754
|
-
const context = this;
|
|
755
|
-
this._fetchResultNamesPromise = this.jsonp(url, request).then(function (response: any) {
|
|
756
|
-
if (Utility.exists("WUInfoResponse.Workunit.Archived", response) && response.WUInfoResponse.Workunit.Archived) {
|
|
757
|
-
console.warn("WU is archived: " + url + " " + JSON.stringify(request));
|
|
758
|
-
}
|
|
759
|
-
if (Utility.exists("WUInfoResponse.Workunit.Results.ECLResult", response)) {
|
|
760
|
-
response.WUInfoResponse.Workunit.Results.ECLResult.map(function (item) {
|
|
761
|
-
context._resultNameCache[item.Name] = [];
|
|
762
|
-
++context._resultNameCacheCount;
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
if (callback) {
|
|
766
|
-
console.error("Deprecated: callback, use promise (WsWorkunits.prototype.fetchResultNames)");
|
|
767
|
-
callback(context._resultNameCache);
|
|
768
|
-
}
|
|
769
|
-
return context._resultNameCache;
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
return this._fetchResultNamesPromise;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
fetchResults(callback, skipMapping) {
|
|
776
|
-
const context = this;
|
|
777
|
-
return this.fetchResultNames().then(function (response) {
|
|
778
|
-
const fetchArray = [];
|
|
779
|
-
for (const key in context._resultNameCache) {
|
|
780
|
-
fetchArray.push(context.fetchResult({ wuid: context._wuid, resultname: key }, null, skipMapping));
|
|
781
|
-
}
|
|
782
|
-
return Promise.all(fetchArray).then(function (responseArray) {
|
|
783
|
-
if (callback) {
|
|
784
|
-
console.error("Deprecated: callback, use promise (WsWorkunits.prototype.fetchResults)");
|
|
785
|
-
callback(context._resultNameCache);
|
|
786
|
-
}
|
|
787
|
-
return context._resultNameCache;
|
|
788
|
-
});
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
postFilter(request, response) {
|
|
793
|
-
const retVal = {};
|
|
794
|
-
for (const key in response) {
|
|
795
|
-
retVal[key] = response[key].filter(function (row, idx) {
|
|
796
|
-
for (const request_key in request) {
|
|
797
|
-
if (row[request_key] !== undefined && request[request_key] !== undefined && row[request_key] != request[request_key]) {
|
|
798
|
-
return false;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
return true;
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
this._mappings.mapResponse(retVal);
|
|
805
|
-
return retVal;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
send(request, callback) {
|
|
809
|
-
const context = this;
|
|
810
|
-
if (!this._resultNameCacheCount) {
|
|
811
|
-
this.fetchResults(function (response) {
|
|
812
|
-
callback(context.postFilter(request, response));
|
|
813
|
-
}, true);
|
|
814
|
-
} else {
|
|
815
|
-
callback(context.postFilter(request, this._resultNameCache));
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
function WsWorkunits_GetStats() {
|
|
821
|
-
Comms.call(this);
|
|
822
|
-
|
|
823
|
-
this._port = "8010";
|
|
824
|
-
this._wuid = null;
|
|
825
|
-
}
|
|
826
|
-
WsWorkunits_GetStats.prototype = Object.create(Comms.prototype);
|
|
827
|
-
|
|
828
|
-
WsWorkunits_GetStats.prototype.url = function (_) {
|
|
829
|
-
const retVal = Comms.prototype.url.apply(this, arguments);
|
|
830
|
-
if (arguments.length) {
|
|
831
|
-
// http://localhost:8010/WsWorkunits/WUGetStats?WUID="xxx"
|
|
832
|
-
for (const key in this._params) {
|
|
833
|
-
switch (key) {
|
|
834
|
-
case "WUID":
|
|
835
|
-
this.wuid(this._params[key]);
|
|
836
|
-
break;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
return retVal;
|
|
841
|
-
};
|
|
842
|
-
|
|
843
|
-
WsWorkunits_GetStats.prototype.wuid = function (_) {
|
|
844
|
-
if (!arguments.length) return this._wuid;
|
|
845
|
-
this._wuid = _;
|
|
846
|
-
return this;
|
|
847
|
-
};
|
|
848
|
-
|
|
849
|
-
WsWorkunits_GetStats.prototype.constructUrl = function () {
|
|
850
|
-
return Comms.prototype.getUrl.call(this, {
|
|
851
|
-
pathname: "WsWorkunits/WUGetStats?WUID=" + this._wuid
|
|
852
|
-
});
|
|
853
|
-
};
|
|
854
|
-
|
|
855
|
-
WsWorkunits_GetStats.prototype.send = function (request, callback) {
|
|
856
|
-
const url = this.getUrl({
|
|
857
|
-
pathname: "WsWorkunits/WUGetStats.json?WUID=" + this._wuid
|
|
858
|
-
});
|
|
859
|
-
return this.jsonp(url, request).then(function (response) {
|
|
860
|
-
if (Utility.exists("WUGetStatsResponse.Statistics.WUStatisticItem", response)) {
|
|
861
|
-
if (callback) {
|
|
862
|
-
console.error("Deprecated: callback, use promise (WsWorkunits_GetStats.prototype.send)");
|
|
863
|
-
callback(response.WUGetStatsResponse.Statistics.WUStatisticItem);
|
|
864
|
-
}
|
|
865
|
-
return response.WUGetStatsResponse.Statistics.WUStatisticItem;
|
|
866
|
-
} else {
|
|
867
|
-
if (callback) {
|
|
868
|
-
console.error("Deprecated: callback, use promise (WsWorkunits_GetStats.prototype.send)");
|
|
869
|
-
callback([]);
|
|
870
|
-
}
|
|
871
|
-
return [];
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
};
|
|
875
|
-
|
|
876
|
-
// HIPIERoxie ---
|
|
877
|
-
function HIPIERoxie() {
|
|
878
|
-
Comms.call(this);
|
|
879
|
-
}
|
|
880
|
-
HIPIERoxie.prototype = Object.create(Comms.prototype);
|
|
881
|
-
|
|
882
|
-
HIPIERoxie.prototype.fetchResults = function (request, callback) {
|
|
883
|
-
const url = this.getUrl({});
|
|
884
|
-
this._resultNameCache = {};
|
|
885
|
-
this._resultNameCacheCount = 0;
|
|
886
|
-
const context = this;
|
|
887
|
-
return this.jsonp(url, request).then(function (response) {
|
|
888
|
-
let _response = locateRoxieResponse(response);
|
|
889
|
-
if (!_response) {
|
|
890
|
-
_response = locateRoxieException(response);
|
|
891
|
-
}
|
|
892
|
-
response = _response;
|
|
893
|
-
|
|
894
|
-
// Check for exceptions
|
|
895
|
-
if (response.Exception) {
|
|
896
|
-
throw Error(response.Exception.reduce(function (previousValue, exception, index, array) {
|
|
897
|
-
if (previousValue.length) {
|
|
898
|
-
previousValue += "\n";
|
|
899
|
-
}
|
|
900
|
-
return previousValue + exception.Source + " " + exception.Code + ": " + exception.Message;
|
|
901
|
-
}, ""));
|
|
902
|
-
}
|
|
903
|
-
// Remove "response.result.Row"
|
|
904
|
-
for (const key in response) {
|
|
905
|
-
if (response[key].Row) {
|
|
906
|
-
context._resultNameCache[key] = response[key].Row.map(espRowFix);
|
|
907
|
-
++context._resultNameCacheCount;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
if (callback) {
|
|
911
|
-
console.error("Deprecated: callback, use promise (HIPIERoxie.prototype.fetchResults)");
|
|
912
|
-
callback(context._resultNameCache);
|
|
913
|
-
}
|
|
914
|
-
return context._resultNameCache;
|
|
915
|
-
});
|
|
916
|
-
};
|
|
917
|
-
|
|
918
|
-
HIPIERoxie.prototype.fetchResult = function (name, callback) {
|
|
919
|
-
const context = this;
|
|
920
|
-
return new Promise(function (resolve, reject) {
|
|
921
|
-
if (callback) {
|
|
922
|
-
console.error("Deprecated: callback, use promise (HIPIERoxie.prototype.fetchResult)");
|
|
923
|
-
callback(context._resultNameCache[name]);
|
|
924
|
-
}
|
|
925
|
-
resolve(context._resultNameCache[name]);
|
|
926
|
-
});
|
|
927
|
-
};
|
|
928
|
-
|
|
929
|
-
HIPIERoxie.prototype.call = function (request, callback) {
|
|
930
|
-
const context = this;
|
|
931
|
-
return this.fetchResults(request, callback).then(function (response) {
|
|
932
|
-
const retVal = {};
|
|
933
|
-
for (const hipieKey in context._hipieResults) {
|
|
934
|
-
const item = context._hipieResults[hipieKey];
|
|
935
|
-
retVal[item.id] = response[item.from];
|
|
936
|
-
}
|
|
937
|
-
return retVal;
|
|
938
|
-
});
|
|
939
|
-
};
|
|
940
|
-
|
|
941
|
-
// HIPIEWorkunit ---
|
|
942
|
-
function HIPIEWorkunit() {
|
|
943
|
-
WsWorkunits.call(this);
|
|
944
|
-
}
|
|
945
|
-
HIPIEWorkunit.prototype = Object.create(WsWorkunits.prototype);
|
|
946
|
-
|
|
947
|
-
HIPIEWorkunit.prototype.fetchResults = function (callback) {
|
|
948
|
-
const context = this;
|
|
949
|
-
return WsWorkunits.prototype.fetchResultNames.call(this).then(function (response) {
|
|
950
|
-
const fetchArray = [];
|
|
951
|
-
for (const key in context._hipieResults) {
|
|
952
|
-
const item = context._hipieResults[key];
|
|
953
|
-
fetchArray.push(context.fetchResult(item.from));
|
|
954
|
-
}
|
|
955
|
-
return Promise.all(fetchArray).then(function (response2) {
|
|
956
|
-
if (callback) {
|
|
957
|
-
console.error("Deprecated: callback, use promise (HIPIEWorkunit.prototype.fetchResults)");
|
|
958
|
-
callback(context._resultNameCache);
|
|
959
|
-
}
|
|
960
|
-
return context._resultNameCache;
|
|
961
|
-
});
|
|
962
|
-
});
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
HIPIEWorkunit.prototype.fetchResult = function (name, callback) {
|
|
966
|
-
return WsWorkunits.prototype.fetchResult.call(this, { wuid: this._wuid, resultname: name }).then(function (response) {
|
|
967
|
-
if (callback) {
|
|
968
|
-
console.error("Deprecated: callback, use promise (HIPIEWorkunit.prototype.fetchResult)");
|
|
969
|
-
callback(response);
|
|
970
|
-
}
|
|
971
|
-
return response;
|
|
972
|
-
});
|
|
973
|
-
};
|
|
974
|
-
|
|
975
|
-
HIPIEWorkunit.prototype.call = function (request, callback) {
|
|
976
|
-
const context = this;
|
|
977
|
-
if (request.refresh || !this._resultNameCache || !this._resultNameCacheCount) {
|
|
978
|
-
return this.fetchResults(callback).then(function (response) {
|
|
979
|
-
return filterResults(request);
|
|
980
|
-
});
|
|
981
|
-
} else {
|
|
982
|
-
return new Promise(function (resolve, reject) {
|
|
983
|
-
resolve(filterResults(request));
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
function filterResults(request2) {
|
|
988
|
-
const changedFilter = {};
|
|
989
|
-
for (const key in request2) {
|
|
990
|
-
if (request2[key + "_changed"] !== undefined) {
|
|
991
|
-
changedFilter[key] = {
|
|
992
|
-
value: request2[key]
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
const retVal = {};
|
|
997
|
-
for (const hipieKey in context._hipieResults) {
|
|
998
|
-
const hipieResult = context._hipieResults[hipieKey];
|
|
999
|
-
const outputFilter = {};
|
|
1000
|
-
for (let i = 0; i < hipieResult.filters.length; ++i) {
|
|
1001
|
-
const filter = hipieResult.filters[i];
|
|
1002
|
-
if (!filter.isRange()) {
|
|
1003
|
-
outputFilter[filter.fieldid] = changedFilter[filter.fieldid] || { value: undefined };
|
|
1004
|
-
outputFilter[filter.fieldid].filter = filter;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
retVal[hipieResult.id] = context._resultNameCache[hipieResult.from].filter(function (row) {
|
|
1008
|
-
for (const key2 in outputFilter) {
|
|
1009
|
-
if (!outputFilter[key2].filter.matches(row, outputFilter[key2].value)) {
|
|
1010
|
-
return false;
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
return true;
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
return retVal;
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
|
|
1020
|
-
// HIPIEDatabomb ---
|
|
1021
|
-
function HIPIEDatabomb() {
|
|
1022
|
-
HIPIEWorkunit.call(this);
|
|
1023
|
-
}
|
|
1024
|
-
HIPIEDatabomb.prototype = Object.create(HIPIEWorkunit.prototype);
|
|
1025
|
-
|
|
1026
|
-
HIPIEDatabomb.prototype.databomb = function (_) {
|
|
1027
|
-
if (!arguments.length) return this._databomb;
|
|
1028
|
-
this._databomb = _;
|
|
1029
|
-
return this;
|
|
1030
|
-
};
|
|
1031
|
-
|
|
1032
|
-
HIPIEDatabomb.prototype.databombOutput = function (from, id) {
|
|
1033
|
-
if (!arguments.length) return undefined;
|
|
1034
|
-
this._resultNameCacheCount++;
|
|
1035
|
-
if (this._databomb instanceof Array) {
|
|
1036
|
-
this._resultNameCache[from] = this._databomb.map(espRowFix);
|
|
1037
|
-
} else {
|
|
1038
|
-
this._resultNameCache[from] = this._databomb[from].map(espRowFix);
|
|
1039
|
-
}
|
|
1040
|
-
return this;
|
|
1041
|
-
};
|
|
1042
|
-
|
|
1043
|
-
HIPIEDatabomb.prototype.fetchResults = function (callback) {
|
|
1044
|
-
const context = this;
|
|
1045
|
-
return new Promise(function (resolve, reject) {
|
|
1046
|
-
if (callback) {
|
|
1047
|
-
console.error("Deprecated: callback, use promise (HIPIEDatabomb.prototype.fetchResults)");
|
|
1048
|
-
callback(context._resultNameCache);
|
|
1049
|
-
}
|
|
1050
|
-
resolve(context._resultNameCache);
|
|
1051
|
-
});
|
|
1052
|
-
};
|
|
1053
|
-
|
|
1054
|
-
export function createESPConnection(url) {
|
|
1055
|
-
url = url || document.URL;
|
|
1056
|
-
const testURL = new ESPUrl()
|
|
1057
|
-
.url(url)
|
|
1058
|
-
;
|
|
1059
|
-
if (testURL.isWsWorkunits_GetStats()) {
|
|
1060
|
-
return new WsWorkunits_GetStats()
|
|
1061
|
-
.url(url)
|
|
1062
|
-
;
|
|
1063
|
-
}
|
|
1064
|
-
if (testURL.isWsWorkunits()) {
|
|
1065
|
-
return new WsWorkunits()
|
|
1066
|
-
.url(url)
|
|
1067
|
-
;
|
|
1068
|
-
}
|
|
1069
|
-
if (testURL.isWsEcl()) {
|
|
1070
|
-
return new WsECL()
|
|
1071
|
-
.url(url)
|
|
1072
|
-
;
|
|
1073
|
-
}
|
|
1074
|
-
return null;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
export function hookJsonp(func) {
|
|
1078
|
-
jsonp = func;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
export {
|
|
1082
|
-
HIPIEWorkunit,
|
|
1083
|
-
HIPIERoxie,
|
|
1084
|
-
HIPIEDatabomb
|
|
1085
|
-
};
|
|
1
|
+
import { Utility } from "@hpcc-js/common";
|
|
2
|
+
|
|
3
|
+
const TIMEOUT_DEFAULT = 60;
|
|
4
|
+
function espValFix(val) {
|
|
5
|
+
if (val === undefined || val === null) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
if (!val.trim) {
|
|
9
|
+
if (val.Row) {
|
|
10
|
+
return espRowFix(val.Row);
|
|
11
|
+
}
|
|
12
|
+
return val;
|
|
13
|
+
}
|
|
14
|
+
const retVal = val.trim();
|
|
15
|
+
if (retVal !== "" && !isNaN(retVal)) {
|
|
16
|
+
if (retVal.length <= 1 || retVal[0] !== "0" || retVal[1] === ".") {
|
|
17
|
+
return Number(retVal);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return retVal;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function espRowFix(row) {
|
|
24
|
+
for (const key in row) {
|
|
25
|
+
row[key] = espValFix(row[key]);
|
|
26
|
+
}
|
|
27
|
+
return row;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class ESPUrl {
|
|
31
|
+
protected _protocol = "http:";
|
|
32
|
+
protected _hostname = "localhost";
|
|
33
|
+
protected _url;
|
|
34
|
+
protected _port;
|
|
35
|
+
protected _search;
|
|
36
|
+
protected _pathname;
|
|
37
|
+
protected _params;
|
|
38
|
+
protected _hash;
|
|
39
|
+
protected _host;
|
|
40
|
+
|
|
41
|
+
constructor() {
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
url(_: string): this;
|
|
45
|
+
url(): string;
|
|
46
|
+
url(_?): string | this {
|
|
47
|
+
if (!arguments.length) return this._url;
|
|
48
|
+
this._url = _;
|
|
49
|
+
const parser = document.createElement("a");
|
|
50
|
+
parser.href = this._url;
|
|
51
|
+
// eslint-disable-next-line no-self-assign
|
|
52
|
+
parser.href = parser.href; // This fixes an IE9/IE10 DOM value issue
|
|
53
|
+
|
|
54
|
+
const params = {};
|
|
55
|
+
if (parser.search.length) {
|
|
56
|
+
let tmp: any = parser.search;
|
|
57
|
+
if (tmp[0] === "?") {
|
|
58
|
+
tmp = tmp.substring(1);
|
|
59
|
+
}
|
|
60
|
+
tmp = tmp.split("&");
|
|
61
|
+
tmp.map(function (item) {
|
|
62
|
+
const tmpItem = item.split("=");
|
|
63
|
+
params[decodeURIComponent(tmpItem[0])] = decodeURIComponent(tmpItem[1]);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
this._protocol = parser.protocol;
|
|
67
|
+
this._hostname = parser.hostname;
|
|
68
|
+
this._port = parser.port;
|
|
69
|
+
this._pathname = parser.pathname;
|
|
70
|
+
while (this._pathname.length && this._pathname[0] === "/") {
|
|
71
|
+
this._pathname = this._pathname.substring(1);
|
|
72
|
+
}
|
|
73
|
+
this._search = parser.search;
|
|
74
|
+
this._params = params;
|
|
75
|
+
this._hash = parser.hash;
|
|
76
|
+
this._host = parser.host;
|
|
77
|
+
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protocol(_: string): this;
|
|
82
|
+
protocol(): string;
|
|
83
|
+
protocol(_?: string): string | this {
|
|
84
|
+
if (!arguments.length) return this._protocol;
|
|
85
|
+
this._protocol = _;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
hostname(_: string): this;
|
|
90
|
+
hostname(): string;
|
|
91
|
+
hostname(_?: string): string | this {
|
|
92
|
+
if (!arguments.length) return this._hostname;
|
|
93
|
+
this._hostname = _;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
port(_: string): this;
|
|
98
|
+
port(): string;
|
|
99
|
+
port(_?: string) {
|
|
100
|
+
if (!arguments.length) return this._port;
|
|
101
|
+
this._port = _;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
search(_: string): this;
|
|
106
|
+
search(): string;
|
|
107
|
+
search(_?: string) {
|
|
108
|
+
if (!arguments.length) return this._search;
|
|
109
|
+
this._search = _;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
pathname(_: string): this;
|
|
114
|
+
pathname(): string;
|
|
115
|
+
pathname(_?: string) {
|
|
116
|
+
if (!arguments.length) return this._pathname;
|
|
117
|
+
this._pathname = _;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
hash(_: string): this;
|
|
122
|
+
hash(): string;
|
|
123
|
+
hash(_?: string) {
|
|
124
|
+
if (!arguments.length) return this._hash;
|
|
125
|
+
this._hash = _;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
host(_: string): this;
|
|
130
|
+
host(): string;
|
|
131
|
+
host(_?: string) {
|
|
132
|
+
if (!arguments.length) return this._host;
|
|
133
|
+
this._host = _;
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
params(_: string): this;
|
|
138
|
+
params(): string;
|
|
139
|
+
params(_?: string) {
|
|
140
|
+
if (!arguments.length) return this._params;
|
|
141
|
+
this._params = _;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
param(key: string) {
|
|
146
|
+
return this._params[key];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
isWsWorkunits() {
|
|
150
|
+
return this._pathname.toLowerCase().indexOf("wsworkunits") >= 0 || this._params["Wuid"];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
isWorkunitResult() {
|
|
154
|
+
return this.isWsWorkunits() && (this._params["Sequence"] || this._params["ResultName"]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
isWsEcl() {
|
|
158
|
+
return this._pathname.toLowerCase().indexOf("wsecl") >= 0 || (this._params["QuerySetId"] && this._params["Id"]);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
isWsWorkunits_GetStats() {
|
|
162
|
+
return this._pathname.toLowerCase().indexOf("wsworkunits/wugetstats") >= 0 && this._params["WUID"];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getUrl(overrides) {
|
|
166
|
+
overrides = overrides || {};
|
|
167
|
+
return (overrides.protocol !== undefined ? overrides.protocol : this._protocol) + "//" +
|
|
168
|
+
(overrides.hostname !== undefined ? overrides.hostname : this._hostname) + ":" +
|
|
169
|
+
(overrides.port !== undefined ? overrides.port : this._port) + "/" +
|
|
170
|
+
(overrides.pathname !== undefined ? overrides.pathname : this._pathname);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function ESPMappings(mappings) {
|
|
175
|
+
this._mappings = mappings;
|
|
176
|
+
this._reverseMappings = {};
|
|
177
|
+
for (const resultName in this._mappings) {
|
|
178
|
+
this._reverseMappings[resultName] = {};
|
|
179
|
+
for (const key in this._mappings[resultName]) {
|
|
180
|
+
this._reverseMappings[resultName][this._mappings[resultName][key]] = key;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ESPMappings.prototype.contains = function (resultName, origField) {
|
|
186
|
+
return Utility.exists(resultName + "." + origField, this._mappings);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
ESPMappings.prototype.mapResult = function (response, resultName) {
|
|
190
|
+
const mapping = this._mappings[resultName];
|
|
191
|
+
if (mapping) {
|
|
192
|
+
response[resultName] = response[resultName].map(function (item) {
|
|
193
|
+
let row = [];
|
|
194
|
+
if (mapping.x && mapping.x instanceof Array) {
|
|
195
|
+
// LINE Mapping ---
|
|
196
|
+
row = [];
|
|
197
|
+
for (let i = 0; i < mapping.x.length; ++i) {
|
|
198
|
+
row.push(item[mapping.y[i]]);
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
// Regular Mapping ---
|
|
202
|
+
for (const key in mapping) {
|
|
203
|
+
if (mapping[key] === "label") {
|
|
204
|
+
row[0] = item[key];
|
|
205
|
+
} else if (mapping[key] === "weight") {
|
|
206
|
+
row[1] = item[key];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return row;
|
|
211
|
+
}, this);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
ESPMappings.prototype.mapResponse = function (response) {
|
|
216
|
+
for (const key in response) {
|
|
217
|
+
this.mapResult(response, key);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const serialize = function (obj) {
|
|
222
|
+
const str = [];
|
|
223
|
+
for (const key in obj) {
|
|
224
|
+
if (obj.hasOwnProperty(key)) {
|
|
225
|
+
const val = obj[key];
|
|
226
|
+
if (val !== undefined && val !== null) {
|
|
227
|
+
str.push(encodeURIComponent(key) + "=" + encodeURIComponent(val));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return str.join("&");
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
let jsonp = function (url, request, timeout) {
|
|
235
|
+
return new Promise(function (resolve, reject) {
|
|
236
|
+
let respondedTimeout = timeout * 1000;
|
|
237
|
+
const respondedTick = 5000;
|
|
238
|
+
const callbackName = "jsonp_callback_" + Math.round(Math.random() * 999999);
|
|
239
|
+
window[callbackName] = function (response) {
|
|
240
|
+
respondedTimeout = 0;
|
|
241
|
+
doCallback();
|
|
242
|
+
resolve(response);
|
|
243
|
+
};
|
|
244
|
+
const script = document.createElement("script");
|
|
245
|
+
script.src = url + (url.indexOf("?") >= 0 ? "&" : "?") + "jsonp=" + callbackName + "&" + serialize(request);
|
|
246
|
+
document.body.appendChild(script);
|
|
247
|
+
const progress = setInterval(function () {
|
|
248
|
+
if (respondedTimeout <= 0) {
|
|
249
|
+
clearInterval(progress);
|
|
250
|
+
} else {
|
|
251
|
+
respondedTimeout -= respondedTick;
|
|
252
|
+
if (respondedTimeout <= 0) {
|
|
253
|
+
clearInterval(progress);
|
|
254
|
+
doCallback();
|
|
255
|
+
reject(Error("Request timeout: " + script.src));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}, respondedTick);
|
|
259
|
+
|
|
260
|
+
function doCallback() {
|
|
261
|
+
delete window[callbackName];
|
|
262
|
+
document.body.removeChild(script);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export class Comms extends ESPUrl {
|
|
268
|
+
protected _proxyMappings;
|
|
269
|
+
protected _mappings;
|
|
270
|
+
protected _timeout;
|
|
271
|
+
protected _hipieResults;
|
|
272
|
+
protected _hipieResultsLength;
|
|
273
|
+
|
|
274
|
+
constructor() {
|
|
275
|
+
super();
|
|
276
|
+
this._proxyMappings = {};
|
|
277
|
+
this._mappings = new ESPMappings({});
|
|
278
|
+
this._timeout = TIMEOUT_DEFAULT;
|
|
279
|
+
this._hipieResults = {};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
hipieResults(_) {
|
|
283
|
+
if (!arguments.length) return this._hipieResults;
|
|
284
|
+
this._hipieResultsLength = 0;
|
|
285
|
+
this._hipieResults = {};
|
|
286
|
+
const context = this;
|
|
287
|
+
_.forEach(function (item) {
|
|
288
|
+
context._hipieResultsLength++;
|
|
289
|
+
context._hipieResults[item.id] = item;
|
|
290
|
+
});
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
jsonp(url, request) {
|
|
295
|
+
for (const key in this._proxyMappings) {
|
|
296
|
+
const newUrlParts = url.split(key);
|
|
297
|
+
const newUrl = newUrlParts[0];
|
|
298
|
+
if (newUrlParts.length > 1) {
|
|
299
|
+
const espUrl = new ESPUrl()
|
|
300
|
+
.url(url)
|
|
301
|
+
;
|
|
302
|
+
url = newUrl + this._proxyMappings[key];
|
|
303
|
+
request.IP = espUrl.hostname();
|
|
304
|
+
request.PORT = espUrl.port();
|
|
305
|
+
if (newUrlParts.length > 0) {
|
|
306
|
+
request.PATH = newUrlParts[1];
|
|
307
|
+
}
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return jsonp(url, request, this.timeout());
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
ajax(method, url, request?) {
|
|
315
|
+
return new Promise(function (resolve, reject) {
|
|
316
|
+
let uri = url;
|
|
317
|
+
if (method === "GET" && request) {
|
|
318
|
+
uri += "?" + serialize(request);
|
|
319
|
+
}
|
|
320
|
+
const xhr: any = new XMLHttpRequest();
|
|
321
|
+
xhr.onload = function (e) {
|
|
322
|
+
if (this.status >= 200 && this.status < 300) {
|
|
323
|
+
resolve(JSON.parse(this.response));
|
|
324
|
+
} else {
|
|
325
|
+
reject(Error(this.statusText));
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
xhr.onerror = function () {
|
|
329
|
+
reject(Error(this.statusText));
|
|
330
|
+
};
|
|
331
|
+
xhr.open(method, uri);
|
|
332
|
+
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
333
|
+
if (method === "GET") {
|
|
334
|
+
xhr.send();
|
|
335
|
+
} else {
|
|
336
|
+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
337
|
+
xhr.send(serialize(request));
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
get(url, request?) {
|
|
343
|
+
return this.ajax("GET", url, request);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
post(url, request) {
|
|
347
|
+
return this.ajax("POST", url, request);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
mappings(_?) {
|
|
351
|
+
if (!arguments.length) return this._mappings;
|
|
352
|
+
this._mappings = new ESPMappings(_);
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
proxyMappings(_?) {
|
|
357
|
+
if (!arguments.length) return this._proxyMappings;
|
|
358
|
+
this._proxyMappings = _;
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
timeout(_?) {
|
|
363
|
+
if (!arguments.length) return this._timeout;
|
|
364
|
+
this._timeout = _ || TIMEOUT_DEFAULT;
|
|
365
|
+
return this;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export class Basic extends Comms {
|
|
370
|
+
|
|
371
|
+
protected _cacheCalls;
|
|
372
|
+
|
|
373
|
+
constructor() {
|
|
374
|
+
super();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
cacheCalls(_?) {
|
|
378
|
+
if (!arguments.length) return this._cacheCalls;
|
|
379
|
+
this._cacheCalls = _;
|
|
380
|
+
return this;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
call(request, callback) {
|
|
384
|
+
const url = this._url + (this._url.indexOf("?") >= 0 ? "&" : "?") + serialize(request);
|
|
385
|
+
if (this._cacheCalls) {
|
|
386
|
+
const context = this;
|
|
387
|
+
return new Promise(function (resolve, reject) {
|
|
388
|
+
const response = JSON.parse(localStorage.getItem("hpcc.viz." + url));
|
|
389
|
+
if (!response) {
|
|
390
|
+
throw Error("not cached");
|
|
391
|
+
}
|
|
392
|
+
if (callback) {
|
|
393
|
+
console.error("Deprecated: callback, use promise (Basic.prototype.call)");
|
|
394
|
+
callback(response);
|
|
395
|
+
}
|
|
396
|
+
resolve(response);
|
|
397
|
+
}).catch(function (response) {
|
|
398
|
+
return context.get(url).then(function (response2) {
|
|
399
|
+
localStorage.setItem("hpcc.viz." + url, JSON.stringify(response2));
|
|
400
|
+
if (callback) {
|
|
401
|
+
console.error("Deprecated: callback, use promise (Basic.prototype.call)");
|
|
402
|
+
callback(response2);
|
|
403
|
+
}
|
|
404
|
+
return response2;
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
} else {
|
|
408
|
+
localStorage.removeItem("hpcc.viz." + url);
|
|
409
|
+
return this.get(url).then(function (response) {
|
|
410
|
+
if (callback) {
|
|
411
|
+
console.error("Deprecated: callback, use promise (Basic.prototype.call)");
|
|
412
|
+
callback(response);
|
|
413
|
+
}
|
|
414
|
+
return response;
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function locateRoxieResponse(response): object {
|
|
421
|
+
// v5 and v6 compatible ---
|
|
422
|
+
for (const key in response) {
|
|
423
|
+
if (response[key].Row && response[key].Row instanceof Array) {
|
|
424
|
+
return response;
|
|
425
|
+
}
|
|
426
|
+
let retVal;
|
|
427
|
+
if (typeof (response[key]) !== "string") {
|
|
428
|
+
retVal = locateRoxieResponse(response[key]);
|
|
429
|
+
}
|
|
430
|
+
if (retVal) {
|
|
431
|
+
return retVal;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function locateRoxieException(response) {
|
|
438
|
+
for (const key in response) {
|
|
439
|
+
if (response[key].Exception && response[key].Exception instanceof Array) {
|
|
440
|
+
return response[key];
|
|
441
|
+
}
|
|
442
|
+
const retVal = locateRoxieException(response[key]);
|
|
443
|
+
if (retVal) {
|
|
444
|
+
return retVal;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export class WsECL extends Comms {
|
|
451
|
+
|
|
452
|
+
protected _target;
|
|
453
|
+
protected _query;
|
|
454
|
+
|
|
455
|
+
constructor() {
|
|
456
|
+
super();
|
|
457
|
+
|
|
458
|
+
this._port = "8002";
|
|
459
|
+
this._target = "";
|
|
460
|
+
this._query = "";
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
url(_?) {
|
|
464
|
+
const retVal = super.url.apply(this, arguments);
|
|
465
|
+
if (arguments.length) {
|
|
466
|
+
// http://localhost:8010/esp/files/stub.htm?QuerySetId=roxie&Id=stock.3&Widget=QuerySetDetailsWidget
|
|
467
|
+
this._port = this._port === "8010" ? "8002" : this._port; // Need a better way ---
|
|
468
|
+
for (const key in this._params) {
|
|
469
|
+
switch (key) {
|
|
470
|
+
case "QuerySetId":
|
|
471
|
+
this.target(this._params[key]);
|
|
472
|
+
break;
|
|
473
|
+
case "Id":
|
|
474
|
+
this.query(this._params[key]);
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
let pathParts;
|
|
480
|
+
let queryParts;
|
|
481
|
+
if (!this._target || !this._query) {
|
|
482
|
+
// http://localhost:8002/WsEcl/forms/default/query/roxie/wecare
|
|
483
|
+
pathParts = this._pathname.split("/query/");
|
|
484
|
+
if (pathParts.length >= 2) {
|
|
485
|
+
queryParts = pathParts[1].split("/");
|
|
486
|
+
if (queryParts.length >= 2) {
|
|
487
|
+
this.target(queryParts[0]);
|
|
488
|
+
this.query(queryParts[1]);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return retVal;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
target(_?) {
|
|
497
|
+
if (!arguments.length) return this._target;
|
|
498
|
+
this._target = _;
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
query(_?) {
|
|
503
|
+
if (!arguments.length) return this._query;
|
|
504
|
+
this._query = _;
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
constructUrl() {
|
|
509
|
+
return Comms.prototype.getUrl.call(this, {
|
|
510
|
+
pathname: "WsEcl/submit/query/" + this._target + "/" + this._query + "/json"
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
call(target, request, callback) {
|
|
515
|
+
target = target || {};
|
|
516
|
+
target.target = target.target || this._target;
|
|
517
|
+
target.query = target.query || this._query;
|
|
518
|
+
const context = this;
|
|
519
|
+
const url = this.getUrl({
|
|
520
|
+
pathname: "WsEcl/submit/query/" + target.target + "/" + target.query + "/json"
|
|
521
|
+
});
|
|
522
|
+
return this.jsonp(url, request).then(function (response: any) {
|
|
523
|
+
let _response = locateRoxieResponse(response);
|
|
524
|
+
if (!_response) {
|
|
525
|
+
_response = locateRoxieException(response);
|
|
526
|
+
}
|
|
527
|
+
response = _response;
|
|
528
|
+
|
|
529
|
+
// Check for exceptions
|
|
530
|
+
if (response.Exception) {
|
|
531
|
+
throw Error(response.Exception.reduce(function (previousValue, exception, index, array) {
|
|
532
|
+
if (previousValue.length) {
|
|
533
|
+
previousValue += "\n";
|
|
534
|
+
}
|
|
535
|
+
return previousValue + exception.Source + " " + exception.Code + ": " + exception.Message;
|
|
536
|
+
}, ""));
|
|
537
|
+
}
|
|
538
|
+
// Remove "response.result.Row"
|
|
539
|
+
for (const key in response) {
|
|
540
|
+
if (response[key].Row) {
|
|
541
|
+
response[key] = response[key].Row.map(espRowFix);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
context._mappings.mapResponse(response);
|
|
545
|
+
if (callback) {
|
|
546
|
+
console.error("Deprecated: callback, use promise (WsECL.prototype.call)");
|
|
547
|
+
callback(response);
|
|
548
|
+
}
|
|
549
|
+
return response;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
send(request, callback) {
|
|
554
|
+
return this.call({ target: this._target, query: this._query }, request, callback);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export class WsWorkunits extends Comms {
|
|
559
|
+
|
|
560
|
+
protected _wuid = "";
|
|
561
|
+
protected _jobname = "";
|
|
562
|
+
protected _sequence = null;
|
|
563
|
+
protected _resultName = null;
|
|
564
|
+
|
|
565
|
+
protected _fetchResultNamesPromise = null;
|
|
566
|
+
protected _fetchResultPromise = {};
|
|
567
|
+
protected _resultNameCache = {};
|
|
568
|
+
protected _resultNameCacheCount = 0;
|
|
569
|
+
protected _total;
|
|
570
|
+
|
|
571
|
+
constructor() {
|
|
572
|
+
super();
|
|
573
|
+
this._port = "8010";
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
url(_?) {
|
|
577
|
+
const retVal = Comms.prototype.url.apply(this, arguments);
|
|
578
|
+
if (arguments.length) {
|
|
579
|
+
// http://localhost:8010/WsWorkunit/WuResult?Wuid=xxx&ResultName=yyy
|
|
580
|
+
for (const key in this._params) {
|
|
581
|
+
switch (key) {
|
|
582
|
+
case "Wuid":
|
|
583
|
+
this.wuid(this._params[key]);
|
|
584
|
+
break;
|
|
585
|
+
case "ResultName":
|
|
586
|
+
this.resultName(this._params[key]);
|
|
587
|
+
break;
|
|
588
|
+
case "Sequence":
|
|
589
|
+
this.sequence(this._params[key]);
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (!this._wuid) {
|
|
594
|
+
// http://localhost:8010/WsWorkunits/res/W20140922-213329/c:/temp/index.html
|
|
595
|
+
const urlParts = this._url.split("/res/");
|
|
596
|
+
if (urlParts.length >= 2) {
|
|
597
|
+
const urlParts2 = urlParts[1].split("/");
|
|
598
|
+
this.wuid(urlParts2[0]);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return retVal;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
wuid(_?) {
|
|
606
|
+
if (!arguments.length) return this._wuid;
|
|
607
|
+
this._wuid = _;
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
jobname(_?) {
|
|
612
|
+
if (!arguments.length) return this._jobname;
|
|
613
|
+
this._jobname = _;
|
|
614
|
+
return this;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
sequence(_?) {
|
|
618
|
+
if (!arguments.length) return this._sequence;
|
|
619
|
+
this._sequence = _;
|
|
620
|
+
return this;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
resultName(_?) {
|
|
624
|
+
if (!arguments.length) return this._resultName;
|
|
625
|
+
this._resultName = _;
|
|
626
|
+
return this;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
appendParam(label, value, params) {
|
|
630
|
+
if (value) {
|
|
631
|
+
if (params) {
|
|
632
|
+
params += "&";
|
|
633
|
+
}
|
|
634
|
+
return params + label + "=" + value;
|
|
635
|
+
}
|
|
636
|
+
return params;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
constructUrl() {
|
|
640
|
+
const url = Comms.prototype.getUrl.call(this, {
|
|
641
|
+
pathname: "WsWorkunits/res/" + this._wuid + "/"
|
|
642
|
+
});
|
|
643
|
+
let params = "";
|
|
644
|
+
params = this.appendParam("ResultName", this._resultName, params);
|
|
645
|
+
return url + (params ? "?" + params : "");
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
_fetchResult(target, callback, skipMapping) {
|
|
649
|
+
target = target || {};
|
|
650
|
+
if (!this._fetchResultPromise[target.resultname]) {
|
|
651
|
+
target._start = target._start || 0;
|
|
652
|
+
target._count = target._count || -1;
|
|
653
|
+
const url = this.getUrl({
|
|
654
|
+
pathname: "WsWorkunits/WUResult.json"
|
|
655
|
+
});
|
|
656
|
+
const request = {
|
|
657
|
+
Wuid: target.wuid,
|
|
658
|
+
ResultName: target.resultname,
|
|
659
|
+
SuppressXmlSchema: true,
|
|
660
|
+
Start: target._start,
|
|
661
|
+
Count: target._count
|
|
662
|
+
};
|
|
663
|
+
this._resultNameCache[target.resultname] = {};
|
|
664
|
+
const context = this;
|
|
665
|
+
this._fetchResultPromise[target.resultname] = this.jsonp(url, request).then(function (response: any) {
|
|
666
|
+
// Remove "xxxResponse.Result"
|
|
667
|
+
for (const key in response) {
|
|
668
|
+
if (!response[key].Result) {
|
|
669
|
+
throw new Error("No result found.");
|
|
670
|
+
}
|
|
671
|
+
context._total = response[key].Total;
|
|
672
|
+
response = response[key].Result;
|
|
673
|
+
for (const responseKey in response) {
|
|
674
|
+
response = response[responseKey].Row.map(espRowFix);
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
context._resultNameCache[target.resultname] = response;
|
|
680
|
+
if (!skipMapping) {
|
|
681
|
+
context._mappings.mapResult(context._resultNameCache, target.resultname);
|
|
682
|
+
}
|
|
683
|
+
if (callback) {
|
|
684
|
+
console.error("Deprecated: callback, use promise (WsWorkunits.prototype._fetchResult)");
|
|
685
|
+
callback(context._resultNameCache[target.resultname]);
|
|
686
|
+
}
|
|
687
|
+
return context._resultNameCache[target.resultname];
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
return this._fetchResultPromise[target.resultname];
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
fetchResult(target, callback, skipMapping) {
|
|
694
|
+
if (target.wuid) {
|
|
695
|
+
return this._fetchResult(target, callback, skipMapping);
|
|
696
|
+
} else if (target.jobname) {
|
|
697
|
+
const context = this;
|
|
698
|
+
return this.WUQuery(target, function (response) {
|
|
699
|
+
target.wuid = response[0].Wuid;
|
|
700
|
+
return context._fetchResult(target, callback, skipMapping);
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
WUQuery(_request, callback) {
|
|
706
|
+
const url = this.getUrl({
|
|
707
|
+
pathname: "WsWorkunits/WUQuery.json"
|
|
708
|
+
});
|
|
709
|
+
const request = {
|
|
710
|
+
Jobname: _request.jobname,
|
|
711
|
+
Count: 1
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
this._resultNameCache = {};
|
|
715
|
+
this._resultNameCacheCount = 0;
|
|
716
|
+
return this.jsonp(url, request).then(function (response: any) {
|
|
717
|
+
if (!Utility.exists("WUQueryResponse.Workunits.ECLWorkunit", response)) {
|
|
718
|
+
throw Error("No workunit found.");
|
|
719
|
+
}
|
|
720
|
+
response = response.WUQueryResponse.Workunits.ECLWorkunit;
|
|
721
|
+
if (callback) {
|
|
722
|
+
console.error("Deprecated: callback, use promise (WsWorkunits.prototype.WUQuery)");
|
|
723
|
+
callback(response);
|
|
724
|
+
}
|
|
725
|
+
return response;
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
fetchResultNames(callback?) {
|
|
730
|
+
if (!this._fetchResultNamesPromise) {
|
|
731
|
+
const url = this.getUrl({
|
|
732
|
+
pathname: "WsWorkunits/WUInfo.json"
|
|
733
|
+
});
|
|
734
|
+
const request = {
|
|
735
|
+
Wuid: this._wuid,
|
|
736
|
+
TruncateEclTo64k: true,
|
|
737
|
+
IncludeExceptions: false,
|
|
738
|
+
IncludeGraphs: false,
|
|
739
|
+
IncludeSourceFiles: false,
|
|
740
|
+
IncludeResults: true,
|
|
741
|
+
IncludeResultsViewNames: false,
|
|
742
|
+
IncludeVariables: false,
|
|
743
|
+
IncludeTimers: false,
|
|
744
|
+
IncludeResourceURLs: false,
|
|
745
|
+
IncludeDebugValues: false,
|
|
746
|
+
IncludeApplicationValues: false,
|
|
747
|
+
IncludeWorkflows: false,
|
|
748
|
+
IncludeXmlSchemas: false,
|
|
749
|
+
SuppressResultSchemas: true
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
this._resultNameCache = {};
|
|
753
|
+
this._resultNameCacheCount = 0;
|
|
754
|
+
const context = this;
|
|
755
|
+
this._fetchResultNamesPromise = this.jsonp(url, request).then(function (response: any) {
|
|
756
|
+
if (Utility.exists("WUInfoResponse.Workunit.Archived", response) && response.WUInfoResponse.Workunit.Archived) {
|
|
757
|
+
console.warn("WU is archived: " + url + " " + JSON.stringify(request));
|
|
758
|
+
}
|
|
759
|
+
if (Utility.exists("WUInfoResponse.Workunit.Results.ECLResult", response)) {
|
|
760
|
+
response.WUInfoResponse.Workunit.Results.ECLResult.map(function (item) {
|
|
761
|
+
context._resultNameCache[item.Name] = [];
|
|
762
|
+
++context._resultNameCacheCount;
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
if (callback) {
|
|
766
|
+
console.error("Deprecated: callback, use promise (WsWorkunits.prototype.fetchResultNames)");
|
|
767
|
+
callback(context._resultNameCache);
|
|
768
|
+
}
|
|
769
|
+
return context._resultNameCache;
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
return this._fetchResultNamesPromise;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
fetchResults(callback, skipMapping) {
|
|
776
|
+
const context = this;
|
|
777
|
+
return this.fetchResultNames().then(function (response) {
|
|
778
|
+
const fetchArray = [];
|
|
779
|
+
for (const key in context._resultNameCache) {
|
|
780
|
+
fetchArray.push(context.fetchResult({ wuid: context._wuid, resultname: key }, null, skipMapping));
|
|
781
|
+
}
|
|
782
|
+
return Promise.all(fetchArray).then(function (responseArray) {
|
|
783
|
+
if (callback) {
|
|
784
|
+
console.error("Deprecated: callback, use promise (WsWorkunits.prototype.fetchResults)");
|
|
785
|
+
callback(context._resultNameCache);
|
|
786
|
+
}
|
|
787
|
+
return context._resultNameCache;
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
postFilter(request, response) {
|
|
793
|
+
const retVal = {};
|
|
794
|
+
for (const key in response) {
|
|
795
|
+
retVal[key] = response[key].filter(function (row, idx) {
|
|
796
|
+
for (const request_key in request) {
|
|
797
|
+
if (row[request_key] !== undefined && request[request_key] !== undefined && row[request_key] != request[request_key]) {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return true;
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
this._mappings.mapResponse(retVal);
|
|
805
|
+
return retVal;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
send(request, callback) {
|
|
809
|
+
const context = this;
|
|
810
|
+
if (!this._resultNameCacheCount) {
|
|
811
|
+
this.fetchResults(function (response) {
|
|
812
|
+
callback(context.postFilter(request, response));
|
|
813
|
+
}, true);
|
|
814
|
+
} else {
|
|
815
|
+
callback(context.postFilter(request, this._resultNameCache));
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function WsWorkunits_GetStats() {
|
|
821
|
+
Comms.call(this);
|
|
822
|
+
|
|
823
|
+
this._port = "8010";
|
|
824
|
+
this._wuid = null;
|
|
825
|
+
}
|
|
826
|
+
WsWorkunits_GetStats.prototype = Object.create(Comms.prototype);
|
|
827
|
+
|
|
828
|
+
WsWorkunits_GetStats.prototype.url = function (_) {
|
|
829
|
+
const retVal = Comms.prototype.url.apply(this, arguments);
|
|
830
|
+
if (arguments.length) {
|
|
831
|
+
// http://localhost:8010/WsWorkunits/WUGetStats?WUID="xxx"
|
|
832
|
+
for (const key in this._params) {
|
|
833
|
+
switch (key) {
|
|
834
|
+
case "WUID":
|
|
835
|
+
this.wuid(this._params[key]);
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return retVal;
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
WsWorkunits_GetStats.prototype.wuid = function (_) {
|
|
844
|
+
if (!arguments.length) return this._wuid;
|
|
845
|
+
this._wuid = _;
|
|
846
|
+
return this;
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
WsWorkunits_GetStats.prototype.constructUrl = function () {
|
|
850
|
+
return Comms.prototype.getUrl.call(this, {
|
|
851
|
+
pathname: "WsWorkunits/WUGetStats?WUID=" + this._wuid
|
|
852
|
+
});
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
WsWorkunits_GetStats.prototype.send = function (request, callback) {
|
|
856
|
+
const url = this.getUrl({
|
|
857
|
+
pathname: "WsWorkunits/WUGetStats.json?WUID=" + this._wuid
|
|
858
|
+
});
|
|
859
|
+
return this.jsonp(url, request).then(function (response) {
|
|
860
|
+
if (Utility.exists("WUGetStatsResponse.Statistics.WUStatisticItem", response)) {
|
|
861
|
+
if (callback) {
|
|
862
|
+
console.error("Deprecated: callback, use promise (WsWorkunits_GetStats.prototype.send)");
|
|
863
|
+
callback(response.WUGetStatsResponse.Statistics.WUStatisticItem);
|
|
864
|
+
}
|
|
865
|
+
return response.WUGetStatsResponse.Statistics.WUStatisticItem;
|
|
866
|
+
} else {
|
|
867
|
+
if (callback) {
|
|
868
|
+
console.error("Deprecated: callback, use promise (WsWorkunits_GetStats.prototype.send)");
|
|
869
|
+
callback([]);
|
|
870
|
+
}
|
|
871
|
+
return [];
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
// HIPIERoxie ---
|
|
877
|
+
function HIPIERoxie() {
|
|
878
|
+
Comms.call(this);
|
|
879
|
+
}
|
|
880
|
+
HIPIERoxie.prototype = Object.create(Comms.prototype);
|
|
881
|
+
|
|
882
|
+
HIPIERoxie.prototype.fetchResults = function (request, callback) {
|
|
883
|
+
const url = this.getUrl({});
|
|
884
|
+
this._resultNameCache = {};
|
|
885
|
+
this._resultNameCacheCount = 0;
|
|
886
|
+
const context = this;
|
|
887
|
+
return this.jsonp(url, request).then(function (response) {
|
|
888
|
+
let _response = locateRoxieResponse(response);
|
|
889
|
+
if (!_response) {
|
|
890
|
+
_response = locateRoxieException(response);
|
|
891
|
+
}
|
|
892
|
+
response = _response;
|
|
893
|
+
|
|
894
|
+
// Check for exceptions
|
|
895
|
+
if (response.Exception) {
|
|
896
|
+
throw Error(response.Exception.reduce(function (previousValue, exception, index, array) {
|
|
897
|
+
if (previousValue.length) {
|
|
898
|
+
previousValue += "\n";
|
|
899
|
+
}
|
|
900
|
+
return previousValue + exception.Source + " " + exception.Code + ": " + exception.Message;
|
|
901
|
+
}, ""));
|
|
902
|
+
}
|
|
903
|
+
// Remove "response.result.Row"
|
|
904
|
+
for (const key in response) {
|
|
905
|
+
if (response[key].Row) {
|
|
906
|
+
context._resultNameCache[key] = response[key].Row.map(espRowFix);
|
|
907
|
+
++context._resultNameCacheCount;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
if (callback) {
|
|
911
|
+
console.error("Deprecated: callback, use promise (HIPIERoxie.prototype.fetchResults)");
|
|
912
|
+
callback(context._resultNameCache);
|
|
913
|
+
}
|
|
914
|
+
return context._resultNameCache;
|
|
915
|
+
});
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
HIPIERoxie.prototype.fetchResult = function (name, callback) {
|
|
919
|
+
const context = this;
|
|
920
|
+
return new Promise(function (resolve, reject) {
|
|
921
|
+
if (callback) {
|
|
922
|
+
console.error("Deprecated: callback, use promise (HIPIERoxie.prototype.fetchResult)");
|
|
923
|
+
callback(context._resultNameCache[name]);
|
|
924
|
+
}
|
|
925
|
+
resolve(context._resultNameCache[name]);
|
|
926
|
+
});
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
HIPIERoxie.prototype.call = function (request, callback) {
|
|
930
|
+
const context = this;
|
|
931
|
+
return this.fetchResults(request, callback).then(function (response) {
|
|
932
|
+
const retVal = {};
|
|
933
|
+
for (const hipieKey in context._hipieResults) {
|
|
934
|
+
const item = context._hipieResults[hipieKey];
|
|
935
|
+
retVal[item.id] = response[item.from];
|
|
936
|
+
}
|
|
937
|
+
return retVal;
|
|
938
|
+
});
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
// HIPIEWorkunit ---
|
|
942
|
+
function HIPIEWorkunit() {
|
|
943
|
+
WsWorkunits.call(this);
|
|
944
|
+
}
|
|
945
|
+
HIPIEWorkunit.prototype = Object.create(WsWorkunits.prototype);
|
|
946
|
+
|
|
947
|
+
HIPIEWorkunit.prototype.fetchResults = function (callback) {
|
|
948
|
+
const context = this;
|
|
949
|
+
return WsWorkunits.prototype.fetchResultNames.call(this).then(function (response) {
|
|
950
|
+
const fetchArray = [];
|
|
951
|
+
for (const key in context._hipieResults) {
|
|
952
|
+
const item = context._hipieResults[key];
|
|
953
|
+
fetchArray.push(context.fetchResult(item.from));
|
|
954
|
+
}
|
|
955
|
+
return Promise.all(fetchArray).then(function (response2) {
|
|
956
|
+
if (callback) {
|
|
957
|
+
console.error("Deprecated: callback, use promise (HIPIEWorkunit.prototype.fetchResults)");
|
|
958
|
+
callback(context._resultNameCache);
|
|
959
|
+
}
|
|
960
|
+
return context._resultNameCache;
|
|
961
|
+
});
|
|
962
|
+
});
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
HIPIEWorkunit.prototype.fetchResult = function (name, callback) {
|
|
966
|
+
return WsWorkunits.prototype.fetchResult.call(this, { wuid: this._wuid, resultname: name }).then(function (response) {
|
|
967
|
+
if (callback) {
|
|
968
|
+
console.error("Deprecated: callback, use promise (HIPIEWorkunit.prototype.fetchResult)");
|
|
969
|
+
callback(response);
|
|
970
|
+
}
|
|
971
|
+
return response;
|
|
972
|
+
});
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
HIPIEWorkunit.prototype.call = function (request, callback) {
|
|
976
|
+
const context = this;
|
|
977
|
+
if (request.refresh || !this._resultNameCache || !this._resultNameCacheCount) {
|
|
978
|
+
return this.fetchResults(callback).then(function (response) {
|
|
979
|
+
return filterResults(request);
|
|
980
|
+
});
|
|
981
|
+
} else {
|
|
982
|
+
return new Promise(function (resolve, reject) {
|
|
983
|
+
resolve(filterResults(request));
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function filterResults(request2) {
|
|
988
|
+
const changedFilter = {};
|
|
989
|
+
for (const key in request2) {
|
|
990
|
+
if (request2[key + "_changed"] !== undefined) {
|
|
991
|
+
changedFilter[key] = {
|
|
992
|
+
value: request2[key]
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
const retVal = {};
|
|
997
|
+
for (const hipieKey in context._hipieResults) {
|
|
998
|
+
const hipieResult = context._hipieResults[hipieKey];
|
|
999
|
+
const outputFilter = {};
|
|
1000
|
+
for (let i = 0; i < hipieResult.filters.length; ++i) {
|
|
1001
|
+
const filter = hipieResult.filters[i];
|
|
1002
|
+
if (!filter.isRange()) {
|
|
1003
|
+
outputFilter[filter.fieldid] = changedFilter[filter.fieldid] || { value: undefined };
|
|
1004
|
+
outputFilter[filter.fieldid].filter = filter;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
retVal[hipieResult.id] = context._resultNameCache[hipieResult.from].filter(function (row) {
|
|
1008
|
+
for (const key2 in outputFilter) {
|
|
1009
|
+
if (!outputFilter[key2].filter.matches(row, outputFilter[key2].value)) {
|
|
1010
|
+
return false;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return true;
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
return retVal;
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
// HIPIEDatabomb ---
|
|
1021
|
+
function HIPIEDatabomb() {
|
|
1022
|
+
HIPIEWorkunit.call(this);
|
|
1023
|
+
}
|
|
1024
|
+
HIPIEDatabomb.prototype = Object.create(HIPIEWorkunit.prototype);
|
|
1025
|
+
|
|
1026
|
+
HIPIEDatabomb.prototype.databomb = function (_) {
|
|
1027
|
+
if (!arguments.length) return this._databomb;
|
|
1028
|
+
this._databomb = _;
|
|
1029
|
+
return this;
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
HIPIEDatabomb.prototype.databombOutput = function (from, id) {
|
|
1033
|
+
if (!arguments.length) return undefined;
|
|
1034
|
+
this._resultNameCacheCount++;
|
|
1035
|
+
if (this._databomb instanceof Array) {
|
|
1036
|
+
this._resultNameCache[from] = this._databomb.map(espRowFix);
|
|
1037
|
+
} else {
|
|
1038
|
+
this._resultNameCache[from] = this._databomb[from].map(espRowFix);
|
|
1039
|
+
}
|
|
1040
|
+
return this;
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
HIPIEDatabomb.prototype.fetchResults = function (callback) {
|
|
1044
|
+
const context = this;
|
|
1045
|
+
return new Promise(function (resolve, reject) {
|
|
1046
|
+
if (callback) {
|
|
1047
|
+
console.error("Deprecated: callback, use promise (HIPIEDatabomb.prototype.fetchResults)");
|
|
1048
|
+
callback(context._resultNameCache);
|
|
1049
|
+
}
|
|
1050
|
+
resolve(context._resultNameCache);
|
|
1051
|
+
});
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
export function createESPConnection(url) {
|
|
1055
|
+
url = url || document.URL;
|
|
1056
|
+
const testURL = new ESPUrl()
|
|
1057
|
+
.url(url)
|
|
1058
|
+
;
|
|
1059
|
+
if (testURL.isWsWorkunits_GetStats()) {
|
|
1060
|
+
return new WsWorkunits_GetStats()
|
|
1061
|
+
.url(url)
|
|
1062
|
+
;
|
|
1063
|
+
}
|
|
1064
|
+
if (testURL.isWsWorkunits()) {
|
|
1065
|
+
return new WsWorkunits()
|
|
1066
|
+
.url(url)
|
|
1067
|
+
;
|
|
1068
|
+
}
|
|
1069
|
+
if (testURL.isWsEcl()) {
|
|
1070
|
+
return new WsECL()
|
|
1071
|
+
.url(url)
|
|
1072
|
+
;
|
|
1073
|
+
}
|
|
1074
|
+
return null;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
export function hookJsonp(func) {
|
|
1078
|
+
jsonp = func;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
export {
|
|
1082
|
+
HIPIEWorkunit,
|
|
1083
|
+
HIPIERoxie,
|
|
1084
|
+
HIPIEDatabomb
|
|
1085
|
+
};
|