From e938a285b98ccb545adb04d59fff1d65ca08f512 Mon Sep 17 00:00:00 2001 From: Mohammad Naghavi Date: Tue, 9 Feb 2016 11:37:01 +0100 Subject: [PATCH 1/4] adding options to allow altering CSV output --- extension/scripts/Sitemap.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/extension/scripts/Sitemap.js b/extension/scripts/Sitemap.js index 0cfaf47a..144acd53 100644 --- a/extension/scripts/Sitemap.js +++ b/extension/scripts/Sitemap.js @@ -174,12 +174,19 @@ Sitemap.prototype = { return columns; }, - getDataExportCsvBlob: function (data) { - - var columns = this.getDataColumns(), - delimiter = ',', - newline = "\n", - csvData = ['\ufeff']; // utf-8 bom char + getDataExportCsvBlob: function (data, option) { + + var delimiterKey = "delimiter"; + var newlineKey = "newline"; + var containBomKey = "containBom"; + + var columns = this.getDataColumns(), + // default delimiter is comma + delimiter = option.hasOwnProperty(delimiterKey) ? option[delimiterKey] : ',', + // per default, new line is included at end of lines + newline = option.hasOwnProperty(newlineKey) ? (option[newlineKey] == true ? "\n" : "") : "\n", + // per default, utf8 BOM is included at the beginning. + csvData = option.hasOwnProperty(containBomKey) ? (option[containBomKey] == true ? ['\ufeff'] : []) : ['\ufeff']; // utf-8 bom char // header csvData.push(columns.join(delimiter) + newline) From c6daaa1e081cb05a62cd77ac11f97974e4e84b1f Mon Sep 17 00:00:00 2001 From: Mohammad Naghavi Date: Tue, 9 Feb 2016 11:37:26 +0100 Subject: [PATCH 2/4] adding necessary inputs for getting CSV output data from user --- .../devtools/views/SitemapExportDataCSV.html | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/extension/devtools/views/SitemapExportDataCSV.html b/extension/devtools/views/SitemapExportDataCSV.html index 4cfc595a..b9e12a44 100644 --- a/extension/devtools/views/SitemapExportDataCSV.html +++ b/extension/devtools/views/SitemapExportDataCSV.html @@ -1,4 +1,22 @@ -

- Export {{_id}} data as CSV.
Waiting for the download button to appear. > - Download now! +

Export {{_id}} data as CSV

+
+ + + +
+ + + +
+ + + +
+ + +
+
+ +

+ Waiting for process to finish. > Download now!

\ No newline at end of file From 4b719974d1a12ae70e73dab1f7a235ccfb37007d Mon Sep 17 00:00:00 2001 From: Mohammad Naghavi Date: Tue, 9 Feb 2016 11:38:20 +0100 Subject: [PATCH 3/4] controller also to support CSV output options --- extension/scripts/Controller.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/extension/scripts/Controller.js b/extension/scripts/Controller.js index 3caa4cab..4212266f 100644 --- a/extension/scripts/Controller.js +++ b/extension/scripts/Controller.js @@ -1070,13 +1070,26 @@ SitemapController.prototype = { var exportPanel = ich.SitemapExportDataCSV(sitemap); $("#viewport").html(exportPanel); + $(".result").hide(); + // generate data - $(".download-button").hide(); - this.store.getSitemapData(sitemap, function (data) { - var blob = sitemap.getDataExportCsvBlob(data); - $(".download-button a").attr("href", window.URL.createObjectURL(blob)); - $(".download-button a").attr("download", sitemap._id + ".csv"); - $(".download-button").show(); + $("#generate-csv").click(function () { + $(".result").show(); + $(".download-button").hide(); + + var options = { + "delimiter": $("#delimiter").val(), + "newline": $("#newline").prop('checked'), + "containBom": $("#utf-bom").prop('checked') + }; + + this.store.getSitemapData(sitemap, function (data) { + var blob = sitemap.getDataExportCsvBlob(data, options); + $(".download-button a").attr("href", window.URL.createObjectURL(blob)); + $(".download-button a").attr("download", sitemap._id + ".csv"); + $(".download-button").show(); + }.bind(this)); + }.bind(this)); return true; From c5a965fcc57ab41621555a3c35dbe81fdbdaa82e Mon Sep 17 00:00:00 2001 From: Mohammad Naghavi Date: Tue, 9 Feb 2016 11:40:57 +0100 Subject: [PATCH 4/4] minor visual change on CSV generation UI --- extension/devtools/views/SitemapExportDataCSV.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/devtools/views/SitemapExportDataCSV.html b/extension/devtools/views/SitemapExportDataCSV.html index b9e12a44..87e232f7 100644 --- a/extension/devtools/views/SitemapExportDataCSV.html +++ b/extension/devtools/views/SitemapExportDataCSV.html @@ -1,4 +1,4 @@ -

Export {{_id}} data as CSV

+

Export {{_id}} data as CSV