Skip to content

Commit 1d089ff

Browse files
committed
Fix history again for new ui
1 parent ff51ab4 commit 1d089ff

1 file changed

Lines changed: 89 additions & 49 deletions

File tree

install/cws-ui/history.ftl

Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,22 @@
336336
}
337337
338338
function processData(historyData, logData) {
339-
340-
const historyRows = buildHistoryRows(historyData[0]);
341-
const logRows = buildLogRows(logData[0]);
342-
343-
renderSet(historyRows.concat(logRows));
339+
const historyRows = buildHistoryRows(historyData);
344340
345-
// Get rest of log data (if exists)
346-
getMoreLogData(logData[0]._scroll_id);
341+
// Check if logData is valid and contains hits (Elasticsearch is enabled)
342+
if (logData && logData.hits && logData.hits.hits && logData.hits.hits.length > 0) {
343+
const logRows = buildLogRows(logData);
344+
renderSet(historyRows.concat(logRows));
345+
346+
// Get rest of log data (if exists)
347+
getMoreLogData(logData._scroll_id);
348+
} else {
349+
// Elasticsearch is disabled or no log data available, only show history
350+
renderSet(historyRows);
351+
$(".ajax-spinner").hide();
352+
var table = $("#logData").DataTable();
353+
table.draw();
354+
}
347355
}
348356
349357
function processFailed(historyError, logError) {
@@ -352,7 +360,15 @@
352360
353361
console.log("Errors", historyError, logError);
354362
355-
alert("Error retrieving history data.");
363+
// If only log error (Elasticsearch disabled), try to process history data alone
364+
if (historyError && historyError.status === 200) {
365+
const historyRows = buildHistoryRows(historyError);
366+
renderSet(historyRows);
367+
var table = $("#logData").DataTable();
368+
table.draw();
369+
} else {
370+
alert("Error retrieving history data.");
371+
}
356372
}
357373
358374
function downloadLogCSV() {
@@ -523,9 +539,29 @@
523539
524540
esReq.query.bool.must.push({"query_string":{"fields":["procInstId"],"query" : "\"" + decodeURIComponent(params.procInstId) + "\""}});
525541
526-
// Get history and log data (first scroll) in parallel
527-
$.when( $.getJSON("/${base}/rest/history/" + params.procInstId),
528-
$.getJSON("/${base}/rest/logs/get?source=" + encodeURIComponent(JSON.stringify(esReq))) ).then(processData, processFailed);
542+
// Get history data
543+
var historyPromise = $.getJSON("/${base}/rest/history/" + params.procInstId);
544+
545+
// Get log data (may fail if Elasticsearch is disabled)
546+
var logPromise = $.getJSON("/${base}/rest/logs/get?source=" + encodeURIComponent(JSON.stringify(esReq)))
547+
.fail(function() {
548+
// Silently ignore log errors (Elasticsearch may be disabled)
549+
return $.Deferred().resolve(null);
550+
});
551+
552+
// Process data when both complete (or log fails gracefully)
553+
$.when(historyPromise, logPromise).then(
554+
function(historyResult, logResult) {
555+
// Handle successful responses
556+
var historyData = historyResult[0];
557+
var logData = logResult ? logResult[0] : null;
558+
processData(historyData, logData);
559+
},
560+
function(historyError, logError) {
561+
// Handle errors
562+
processFailed(historyError, logError);
563+
}
564+
);
529565
530566
// In case of unknown problems, just hide spinner
531567
setTimeout(function() {
@@ -972,46 +1008,50 @@
9721008
dataType: "json",
9731009
async: false,
9741010
success: function(data) {
975-
var finished = false;
976-
scrollId = data._scroll_id;
977-
if (data.hits) {
978-
for (const hit of data.hits.hits) {
979-
const source = hit._source;
980-
const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, "<br/>") + "</p>"];
981-
logLines.push(row);
982-
983-
}
984-
}
985-
while (!finished) {
986-
$.ajax({
987-
type: "POST",
988-
url: "/${base}/rest/logs/get/scroll",
989-
data: "scrollId=" + scrollId,
990-
async: false,
991-
success: function(data) {
992-
if (data.hits) {
993-
994-
if (data.hits.hits.length > 0) {
995-
for (const hit of data.hits.hits) {
996-
const source = hit._source;
997-
const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, "<br/>") + "</p>"];
998-
logLines.push(row);
999-
}
1000-
scrollId = data._scroll_id;
1001-
}
1002-
else {
1003-
finished = true;
1004-
}
1005-
}
1006-
},
1007-
error: function(e) {
1008-
alert("Error retrieving history data.");
1009-
}
1010-
});
1011-
}
1011+
// Check if data is valid (Elasticsearch enabled)
1012+
if (data && data.hits) {
1013+
var finished = false;
1014+
scrollId = data._scroll_id;
1015+
if (data.hits) {
1016+
for (const hit of data.hits.hits) {
1017+
const source = hit._source;
1018+
const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, "<br/>") + "</p>"];
1019+
logLines.push(row);
1020+
1021+
}
1022+
}
1023+
while (!finished) {
1024+
$.ajax({
1025+
type: "POST",
1026+
url: "/${base}/rest/logs/get/scroll",
1027+
data: "scrollId=" + scrollId,
1028+
async: false,
1029+
success: function(data) {
1030+
if (data.hits) {
1031+
1032+
if (data.hits.hits.length > 0) {
1033+
for (const hit of data.hits.hits) {
1034+
const source = hit._source;
1035+
const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, "<br/>") + "</p>"];
1036+
logLines.push(row);
1037+
}
1038+
scrollId = data._scroll_id;
1039+
}
1040+
else {
1041+
finished = true;
1042+
}
1043+
}
1044+
},
1045+
error: function(e) {
1046+
console.log("Error retrieving more log data - Elasticsearch may be disabled");
1047+
finished = true;
1048+
}
1049+
});
1050+
}
1051+
}
10121052
}
10131053
}).fail(function(xhr, err) {
1014-
console.error("Error getting instance JSON: " + xhr.responseText);
1054+
console.log("Error getting log data for JSON export - Elasticsearch may be disabled: " + xhr.responseText);
10151055
});
10161056
logLines.sort(function(a, b) {
10171057
var aDate = moment(a[0].trim());

0 commit comments

Comments
 (0)