diff --git a/Gemfile.lock b/Gemfile.lock index 21a8c6d27..d37431c15 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -226,6 +226,8 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.9) + nokogiri (1.14.3-aarch64-linux) + racc (~> 1.4) nokogiri (1.14.3-x86_64-linux) racc (~> 1.4) oauth2 (2.0.9) @@ -425,6 +427,7 @@ GEM zeitwerk (2.6.7) PLATFORMS + aarch64-linux x86_64-linux DEPENDENCIES diff --git a/app/assets/javascripts/services/caseCSVSvc.js b/app/assets/javascripts/services/caseCSVSvc.js index 8277f666f..d48fa9412 100644 --- a/app/assets/javascripts/services/caseCSVSvc.js +++ b/app/assets/javascripts/services/caseCSVSvc.js @@ -343,6 +343,32 @@ return csvContent; } + const stringifyField = function (data) { + if (typeof data === 'object'){ + if (data === null){ + data = ''; + } + else { + data = data.join(','); + } + } + if (typeof data === 'string') { + data = data.trim().replace(/"/g, '""'); // Escape double quotes + + if (data.indexOf(',') > -1 || data.indexOf('\n') > -1 || data.indexOf('\r') > -1) { + data = textDelimiter + data + textDelimiter; + } + + if (data.startsWith('=') || data.startsWith('@') || data.startsWith('+') || data.startsWith('-')) { + data = ` ${data}`; + } + + return data; + } + + return data; + }; + /** * Creates CSV string of snapshot * @@ -351,35 +377,37 @@ */ function stringifySnapshot (aCase, snapshot, withHeader) { - var csvContent = ''; - + const snapshotName = snapshot.name(); + const snapshotTime = snapshot.time; + const caseNumber = aCase.caseNo; + let csvContent = ''; if (withHeader) { csvContent += self.snapshotHeaderToCSV(); } - angular.forEach(snapshot.docs, function (docs,queryId) { - angular.forEach(docs, function (doc,idx) { - var dataString; - var infoArray = []; - - infoArray.push(stringifyField(snapshot.name())); - infoArray.push(stringifyField(snapshot.time)); - infoArray.push(stringifyField(aCase.caseNo)); - - queryId = parseInt(queryId,10); - var query = snapshot.queries.filter(function(q) { return q.queryId === queryId; })[0]; - - infoArray.push(stringifyField(query.query_text)); - infoArray.push(stringifyField(doc.id)); - infoArray.push(stringifyField(idx+1)); - - dataString = infoArray.join(','); - csvContent += dataString + EOL; + angular.forEach(snapshot.docs, function (docs, queryId) { + const queryIdToMatch = parseInt(queryId, 10); + const matchingQuery = snapshot.queries.filter(function(query) { + return query.queryId === queryIdToMatch; }); + if (matchingQuery[0]) { + const matchingQueryText = matchingQuery[0].query_text; + if (matchingQueryText) { + angular.forEach(docs, function (doc, idx) { + const infoArray = []; + infoArray.push(stringifyField(snapshotName)); + infoArray.push(stringifyField(snapshotTime)); + infoArray.push(stringifyField(caseNumber)); + infoArray.push(stringifyField(matchingQueryText)); + infoArray.push(stringifyField(doc.id)); + infoArray.push(stringifyField(idx + 1)); + csvContent += infoArray.join(',') + EOL; + }); + } + } }); - return csvContent; } @@ -396,32 +424,6 @@ return downloadFileName; } - - var stringifyField = function (data) { - if (typeof data === 'object'){ - if (data === null){ - data = ''; - } - else { - data = data.join(','); - } - } - if (typeof data === 'string') { - data = data.trim().replace(/"/g, '""'); // Escape double quotes - - if (data.indexOf(',') > -1 || data.indexOf('\n') > -1 || data.indexOf('\r') > -1) { - data = textDelimiter + data + textDelimiter; - } - - if (data.startsWith('=') || data.startsWith('@') || data.startsWith('+') || data.startsWith('-')) { - data = ' ' + data; - } - - return data; - } - - return data; - }; } ]); })(); diff --git a/app/assets/javascripts/services/snapshotFactory.js b/app/assets/javascripts/services/snapshotFactory.js index 92f1b3489..b4ce5a49f 100644 --- a/app/assets/javascripts/services/snapshotFactory.js +++ b/app/assets/javascripts/services/snapshotFactory.js @@ -26,6 +26,12 @@ self.timestamp = timestamp; self.docIdsPerQuery = {}; + + // Map from snake_case to camelCase. + angular.forEach(self.queries, function(query) { + query.queryId = query.query_id; + delete query.query_id; + }); angular.forEach(self.docs, function(docs, queryId) { self.docIdsPerQuery[queryId] = []; diff --git a/spec/javascripts/angular/services/teamSvc_spec.js b/spec/javascripts/angular/services/teamSvc_spec.js index 93056c194..280b612c8 100644 --- a/spec/javascripts/angular/services/teamSvc_spec.js +++ b/spec/javascripts/angular/services/teamSvc_spec.js @@ -115,7 +115,7 @@ describe('Service: teamSvc', function () { .then(function(response) { // Magic commented out console calls make test pass?? WTF? //console.log("Response is"); - //console.log(response) + console.log(response) expect(response).toEqual(mockTeam); }); $httpBackend.flush();