From c1083621cc4e6d61e15a3a497c395c3d846fa738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santanch=C3=A8?= Date: Tue, 5 Mar 2024 21:34:05 -0300 Subject: [PATCH] fix (logger): handle empty cases --- src/adonisjs/public/report/js/report.js | 58 +++++++++++++------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/adonisjs/public/report/js/report.js b/src/adonisjs/public/report/js/report.js index d09db6b4..13972d6a 100644 --- a/src/adonisjs/public/report/js/report.js +++ b/src/adonisjs/public/report/js/report.js @@ -43,35 +43,37 @@ class ReportManager { for (const l of logSet) { const answers = l.log - const track = this._prepareTrack(answers.knotTrack, answers.varTrack) - let lastTime = new Date(track.timeStart) - table += '"' + l.user_id + '","' + l.username + '","' + - track.timeStart + '","' + - zeroPad(lastTime.getDate()) + '/' + - zeroPad(lastTime.getMonth() + 1) + '/' + - zeroPad(lastTime.getFullYear()) + '"' - for (const s of schema) { - let time = -1 - if (track[s] != null) { - const t = new Date(track[s]) - time = new Date(t - lastTime) - lastTime = t + if (answers.varTrack != null) { + const track = this._prepareTrack(answers.knotTrack, answers.varTrack) + let lastTime = new Date(track.timeStart) + table += '"' + l.user_id + '","' + l.username + '","' + + track.timeStart + '","' + + zeroPad(lastTime.getDate()) + '/' + + zeroPad(lastTime.getMonth() + 1) + '/' + + zeroPad(lastTime.getFullYear()) + '"' + for (const s of schema) { + let time = -1 + if (track[s] != null) { + const t = new Date(track[s]) + time = new Date(t - lastTime) + lastTime = t + } + console.log('=== variable ' + s) + console.log(answers.variables[s]) + table += ',"' + + (answers.variables[s] == null + ? '' + : (typeof answers.variables[s] === 'string' || answers.variables[s] instanceof String) + ? answers.variables[s].replace(/"/g, '""') + : answers.variables[s] + ) + + '","' + (time == -1 ? '' + : zeroPad(time.getMinutes()) + ':' + + zeroPad(time.getSeconds())) + '","' + + ((time == -1) ? '' : time.getTime()) + '"' } - console.log('=== variable ' + s) - console.log(answers.variables[s]) - table += ',"' + - (answers.variables[s] == null - ? '' - : (typeof answers.variables[s] === 'string' || answers.variables[s] instanceof String) - ? answers.variables[s].replace(/"/g, '""') - : answers.variables[s] - ) + - '","' + (time == -1 ? '' - : zeroPad(time.getMinutes()) + ':' + - zeroPad(time.getSeconds())) + '","' + - ((time == -1) ? '' : time.getTime()) + '"' + table += '\n' } - table += '\n' } const element = document.createElement('a') @@ -89,7 +91,7 @@ class ReportManager { const toAdd = ['knotTrack', 'varTrack'] const toUpdate = ['variables', 'varUpdated', 'mandatoryFilled'] const toReplace = ['groupInput', 'caseCompleted'] - const pp = (aggregate) ? [] : logs[l] + const pp = (aggregate) ? [] : logs let agg = null let l = 0 let prev = null