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

Return JSON #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions extension/devtools/views/SitemapExportDataJSON.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>
Export {{_id}} data as JSON. <br /> Waiting for the download button to appear. >
<span class="download-button" href="#"><a>Download now!</a></span>
</p>
1 change: 1 addition & 0 deletions extension/devtools/views/Viewport.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<li><a id="sitemap-browse-nav-button">Browse</a></li>
<li><a id="sitemap-export-nav-button">Export Sitemap</a></li>
<li><a id="sitemap-export-data-csv-nav-button">Export data as CSV</a></li>
<li><a id="sitemap-export-data-json-nav-button">Export data as JSON</a></li>
</ul>
</li>
<li>
Expand Down
28 changes: 26 additions & 2 deletions extension/scripts/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SitemapController.prototype = {
'SitemapBrowseData',
'SitemapScrapeConfig',
'SitemapExportDataCSV',
'SitemapExportDataJSON',
'SitemapEditMetadata',
'SelectorList',
'SelectorListItem',
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1407,7 +1431,7 @@ SitemapController.prototype = {
// remove from validator
var validator = this.getFormValidator();
validator.removeField($block.find("input"));

$block.remove();
}
}
Expand Down
5 changes: 4 additions & 1 deletion extension/scripts/Sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -216,4 +220,3 @@ Sitemap.prototype = {
return sitemap;
}
};