Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ function checker_stat(stat) {
function downloadCSV() {
const _values = [];
statistics.value.forEach(stat => {
if (!stat.checkers.length) {
_values.push([
stat.guidelineName,
stat.guidelineRule,
stat.guidelineRuleTitle,
"",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use "none" instead of empty string to match what we have in the GUI table?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue came up previously on this PR, where the result of the dicussion was to simly omit the none word and use the empty string instead. I see your point to make the CSV similar to the UI but whilst UI is for humans, CSV will be read by code and it is easier to distiguish between string or "" than a string or another string. Also currently all other columns also have the none word on the UI whereas the CSV does not.

"",
"",
"",
""
]);
return;
}

stat.checkers.forEach(checker => {
const _value = [
stat.guidelineName,
Expand Down
10 changes: 9 additions & 1 deletion web/server/vue-cli/src/composables/useToCSV.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
export function useToCSV() {
function escapeCSVField(value) {
const _str = value === null || value === undefined ? "" : String(value);

return `"${_str.replaceAll('"', '""')}"`;
}

/**
* Exports the given data with the given file name.
* @param {Array.<Array.<string>>} data - csv data. The first item is the
* header and other items represent rows.
* @param {string} fileName - default file name for export.
*/
function toCSV(data, fileName) {
const _content = data.map(_d => _d.join(",")).join("\n");
const _content = data
.map(_d => _d.map(_field => escapeCSVField(_field)).join(","))
.join("\n");

const _csvContent = `data:text/csv;charset=utf-8,${
encodeURIComponent(_content)}`;
Expand Down
Loading