Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #124 from zooniverse/fix-115-119-120-122
Browse files Browse the repository at this point in the history
Fixes for Issues #115, #119, #120, #122 - Better CSV labelling and handling plus HTTP stuff
  • Loading branch information
simoneduca committed Mar 24, 2016
2 parents f6b5f6e + 43ae45d commit 973cf56
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/constants/mapExplorer.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"baseLayers": [
{
"name": "Terrain",
"url": "http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png",
"url": "//{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png",
"attribution": "&copy; <a href=\"http://www.opencyclemap.org\">OpenCycleMap</a>, &copy; <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>"
},
{
"name": "Satellite",
"url": "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
"url": "//server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
"attribution": "Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community"
}
],
Expand Down
4 changes: 2 additions & 2 deletions src/containers/MapExplorer-SelectorPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export default class SelectorPanel extends React.Component {
this.setState({
downloadDialog: {
status: DialogScreen.DIALOG_ACTOVE,
message: 'Preparing CSV file...',
message: 'Preparing data file...',
data: null
}});

Expand Down Expand Up @@ -323,7 +323,7 @@ export default class SelectorPanel extends React.Component {
this.setState({
downloadDialog: {
status: DialogScreen.DIALOG_ACTIVE,
message: 'CSV ready!',
message: 'Data file ready!',
data: data
}});
})
Expand Down
33 changes: 30 additions & 3 deletions src/presentational/DialogScreen-Download.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default class DialogScreen_DownloadCSV extends DialogScreen {
constructor(props) {
super(props);
this.downloadCsv = this.downloadCsv.bind(this);
this.blobbifyCsvData = this.blobbifyCsvData.bind(this);
this.generateFilename = this.generateFilename.bind(this);
}

render() {
Expand All @@ -19,7 +21,11 @@ export default class DialogScreen_DownloadCSV extends DialogScreen {
: null}

{(this.props.data)
? <div><a className="btn" onClick={this.downloadCsv}>Download</a></div>
? <div><a className="btn" href={window.URL.createObjectURL(this.blobbifyCsvData())} download={this.generateFilename()} onClick={this.downloadCsv}>Download</a></div>
: null}

{(this.props.data)
? <div className="note">(Depending on your computer setup, you may need to right-click on the link above and choose "Save As", then open the downloaded file in Excel.)</div>
: null}

</div>
Expand All @@ -28,13 +34,34 @@ export default class DialogScreen_DownloadCSV extends DialogScreen {
);
}

//NOTE: The onClick=downloadCsv() feature is required because, by default,
//React 'eats' the click event of <a download>s which would otherwise trigger
//a native browser download event.
downloadCsv(e) {
if (this.props.data) {
let dataBlob = new Blob([this.props.data], {type: 'text/csv'});
saveAs(dataBlob, 'wildcam.csv');
let dataBlob = this.blobbifyCsvData();
let filename = this.generateFilename();
saveAs(dataBlob, filename);
this.closeMe();
} else {
console.error('Download CSV Error: no CSV');
}
}

blobbifyCsvData() {
if (this.props.data) {
let dataBlob = new Blob([this.props.data], {type: 'text/csv'});
return dataBlob;
}
return null;
}

generateFilename(extension = '.csv') {
let timeString = new Date();
timeString =
timeString.getDate() +
['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'][timeString.getMonth()] +
timeString.getFullYear();
return 'wildcam-' + timeString + extension;
}
}
5 changes: 5 additions & 0 deletions src/styles/components/dialog-screen.styl
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@

> div
text-align: center

.note
color: #999
font-size: 0.8em
max-width: 20em

0 comments on commit 973cf56

Please sign in to comment.