Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export snapshot #722

Merged
merged 9 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -425,6 +427,7 @@ GEM
zeitwerk (2.6.7)

PLATFORMS
aarch64-linux
x86_64-linux

DEPENDENCIES
Expand Down
96 changes: 49 additions & 47 deletions app/assets/javascripts/services/caseCSVSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}

Expand All @@ -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;
};
}
]);
})();
6 changes: 6 additions & 0 deletions app/assets/javascripts/services/snapshotFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
depahelix2021 marked this conversation as resolved.
Show resolved Hide resolved

angular.forEach(self.docs, function(docs, queryId) {
self.docIdsPerQuery[queryId] = [];
Expand Down
2 changes: 1 addition & 1 deletion spec/javascripts/angular/services/teamSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down