diff --git a/extension/devtools/views/SitemapExportDataJSON.html b/extension/devtools/views/SitemapExportDataJSON.html new file mode 100644 index 00000000..d9b44a1e --- /dev/null +++ b/extension/devtools/views/SitemapExportDataJSON.html @@ -0,0 +1,4 @@ +

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

diff --git a/extension/devtools/views/Viewport.html b/extension/devtools/views/Viewport.html index c9ac4b9b..2c580378 100644 --- a/extension/devtools/views/Viewport.html +++ b/extension/devtools/views/Viewport.html @@ -26,6 +26,7 @@
  • Browse
  • Export Sitemap
  • Export data as CSV
  • +
  • Export data as JSON
  • diff --git a/extension/scripts/Controller.js b/extension/scripts/Controller.js index 3caa4cab..ae875b8f 100644 --- a/extension/scripts/Controller.js +++ b/extension/scripts/Controller.js @@ -43,6 +43,7 @@ SitemapController.prototype = { 'SitemapBrowseData', 'SitemapScrapeConfig', 'SitemapExportDataCSV', + 'SitemapExportDataJSON', 'SitemapEditMetadata', 'SelectorList', 'SelectorListItem', @@ -95,6 +96,9 @@ SitemapController.prototype = { '#sitemap-export-data-csv-nav-button': { click: this.showSitemapExportDataCsvPanel }, + '#sitemap-export-data-json-nav-button': { + click: this.showSitemapExportDataJSONPanel + }, '#submit-create-sitemap': { click: this.createSitemap }, @@ -1042,7 +1046,7 @@ SitemapController.prototype = { $("#viewport").html(dataPanel); // display data - // Doing this the long way so there aren't xss vulnerubilites + // Doing this the long way so there aren't xss vulnerubilites // while working with data or with the selector titles var $tbody = $("#sitemap-data tbody"); data.forEach(function (row) { @@ -1082,6 +1086,26 @@ SitemapController.prototype = { return true; }, + showSitemapExportDataJSONPanel: function () { + this.setActiveNavigationButton('sitemap-export-data-json'); + + var sitemap = this.state.currentSitemap; + var exportPanel = ich.SitemapExportDataJSON(sitemap); + $("#viewport").html(exportPanel); + + // generate data + $(".download-button").hide(); + this.store.getSitemapData(sitemap, function (data) { + var blob = sitemap.getDataExportJSONBlob(data); + //$("#viewport").html(JSON.stringify(data)); + $(".download-button a").attr("href", window.URL.createObjectURL(blob)); + $(".download-button a").attr("download", sitemap._id + ".json"); + $(".download-button").show(); + }.bind(this)); + + return true; + }, + selectSelector: function (button) { var input = $(button).closest(".form-group").find("input.selector-value"); @@ -1407,7 +1431,7 @@ SitemapController.prototype = { // remove from validator var validator = this.getFormValidator(); validator.removeField($block.find("input")); - + $block.remove(); } } diff --git a/extension/scripts/Sitemap.js b/extension/scripts/Sitemap.js index 0cfaf47a..b14f4805 100644 --- a/extension/scripts/Sitemap.js +++ b/extension/scripts/Sitemap.js @@ -203,6 +203,10 @@ Sitemap.prototype = { return new Blob(csvData, {type: 'text/csv'}); }, + getDataExportJSONBlob: function (data) { + var jsonData = JSON.stringify(data, undefined, 4); + return new Blob([jsonData], {type: 'application/json'}); + }, getSelectorById: function (selectorId) { return this.selectors.getSelectorById(selectorId); }, @@ -216,4 +220,3 @@ Sitemap.prototype = { return sitemap; } }; -