-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerIO.js
158 lines (140 loc) · 6.7 KB
/
ServerIO.js
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
// This file is part of DQX - (C) Copyright 2014, Paul Vauterin, Ben Jeffery, Alistair Miles <[email protected]>
// This program is free software licensed under the GNU Affero General Public License.
// You can find a copy of this license in LICENSE in the top directory of the source code or at <http://opensource.org/licenses/AGPL-3.0>
define(["require", "DQX/Framework", "DQX/Popup", "DQX/Msg", "DQX/Utils", "DQX/DocEl", "DQX/Controls", "DQX/base64"],
function (require, Framework, Popup, Msg, DQX, DocEl, Controls, Base64) {
var ServerIO = {};
ServerIO.waitForCompletion = function(serverUrl, calculationid, onCompleted, initialResponse, onFailed) {
var content = 'Server is processing. This may take a while!<p>';
var progressDivId = 'calculationprogressbox'+DQX.getNextUniqueID();
var logDivId1 = 'logbox'+DQX.getNextUniqueID();
var logDivId2 = 'logbox'+DQX.getNextUniqueID();
content += '<div id="{id}" style="min-width:400px"></div><br>'.DQXformat({id: progressDivId});
content += '<div id="{id1}" class="DQXFloatBoxContent2" style="width:500px;height:300px; resize:both; overflow: scroll"><div id="{id2}"></div></div>'.DQXformat({id1: logDivId1, id2: logDivId2});
var popupid = Popup.create('Processing', content, null, {} );
var poll = function() {
data = {};
DQX.customRequest(serverUrl, PnServerModule, 'querycalculation', { calculationid: calculationid, showlog:'1' }, function(resp) {
if (resp.failed) {
alert(resp.status);
DQX.ClosePopup(popupid);
if (onFailed)
onFailed(initialResponse);
}
else {
if (resp.completed) {
DQX.ClosePopup(popupid);
if (onCompleted)
onCompleted(initialResponse);
}
else {
var str = resp.status;
if (resp.progress)
str+=' ('+(100*resp.progress).toFixed(0)+'%)';
if ($('#'+progressDivId).length>0) {
$('#'+progressDivId).html('<h3>'+str+'</h3>');
$('#'+logDivId2).html(ServerIO.formatLog(resp.log));
$('#'+logDivId1).scrollTop($('#'+logDivId2).innerHeight());
setTimeout(poll, 1000);
}
}
}
});
};
setTimeout(poll, 200);
};
ServerIO.customAsyncRequest = function(serverUrl, respmodule, request, data, onCompleted, onFailed) {
DQX.customRequest(serverUrl, respmodule, request, data, function(resp) {
ServerIO.waitForCompletion(serverUrl, resp.calculationid, onCompleted, resp, onFailed);
});
};
ServerIO.formatLog = function(origcontent) {
if (!origcontent)
return '';
var div = DocEl.Div();
div.setCssClass('DQXLogReport');
var content = '';
var indent = -1;
var isDataDump = false;
var lines = origcontent.split('\n');
$.each(lines, function(idx, line) {
var linediv = DocEl.Div();
var addLine = true;
linediv.setCssClass('DQXLogReportLine');
if (line.substring(0,3) == '==>') {
linediv.setCssClass('DQXLogReportHeader');
line = line.substring(3);
indent += 1;
}
if (line.substring(0,3) == '-->') {
linediv.setCssClass('DQXLogReportHeaderSub');
line = line.substring(3);
indent += 1;
}
if (line.substring(0,3) == 'DD>') {
indent += 1;
addLine = false;
isDataDump = true;
}
linediv.addStyle('margin-left',30*Math.max(0,indent)+'px')
if (line.substring(0,3) == '<==') {
indent -= 1;
linediv.setCssClass('DQXLogReportFooter');
line = line.substring(3);
}
if (line.substring(0,3) == '<--') {
indent -= 1;
linediv.setCssClass('DQXLogReportFooterSub');
line = line.substring(3);
}
if (line.substring(0,3) == '<DD') {
indent -= 1;
addLine = false;
isDataDump = false;
}
if (line.substring(0,8) == 'COMMAND:') {
linediv.setCssClass('DQXLogReportCommand');
line = line.substring(8);
}
if (line.substring(0,4) == 'SQL:') {
linediv.setCssClass('DQXLogReportCommand');
line = line.substring(4);
}
if (line.substring(0,6) == 'ERROR:') {
linediv.setCssClass('DQXLogReportError');
}
if (line.substring(0,8) == 'WARNING:') {
linediv.setCssClass('DQXLogReportWarning');
}
if (line.substring(0,2) == '[<') {
addLine = false;
}
if (line.substring(0,3) == '@@@') {
addLine = false;
}
if (addLine) {
if (isDataDump) {
line = line.replace(/ /g,' ')
line = '<div class="DQXLogReportDataDump">' + line +'</div>';
}
linediv.addElem(line);
content += linediv.toString();
}
});
div.addElem(content)
return div.toString();
}
ServerIO.showLog = function(serverUrl, logid) {
//!!! todo: move server side out of Pn Server Module and into DQXServer
DQX.setProcessing();
DQX.customRequest(serverUrl, PnServerModule,'getcalculationlog',{ id: logid },function(resp) {
DQX.stopProcessing();
if (resp.Error)
Popup.create('Calculation log', 'No log data present');
else {
Popup.create('Calculation log '+logid, ServerIO.formatLog(resp.Content) );
}
});
};
return ServerIO;
});