<commit_before>/*
Alternate Downloader
--------------------

Certain browsers (ahem, Safari 9,ahem) have poor HTML5 support for downloads, so
the SaveAs won't work nor the 'download' attr in <a href="file.csv" download>.

This component creates a hidden <form> that submits the data you want Safari to
download to EduAPI's download service, which echoes the content back as a HTTP
response with 'content-disposition' headers to force a download dialog.
 */

import { Component, PropTypes } from 'react';
import config from '../../../constants/config';

class AlternateDownloader extends Component {
  constructor(props) {
    super(props);
    this.download = this.download.bind(this);
  }

  render() {
    return (
      <form className="hidden" action={config.eduAPI.root + 'downloads/'} method="POST" ref={ele => this.form = ele}>
        <textarea name="data" ref={ele => this.formData = ele} />
        <input name="content_type" value={this.props.contentType} />
        <input name="filename" value={this.props.filename} />
      </form>
    );
  }
  
  download(data) {
    console.log('Downloading CSV, Safari workaround active');
    //let zippedData = gzip.zip(data, { name: this.generateFilename('.csv') });
    this.formData.value = data;  //this.binToStr(zippedData);
    this.form.submit();
  }
  
  binToStr(binarray){
    return binarray.reduce((str, val, index, arr) => {
        return str + (String.fromCharCode(val));
      }, '');
  }
}

export function generateFilename(basename = 'wildcam-', 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 basename + timeString + extension;
}

AlternateDownloader.propTypes = {
  contentType: PropTypes.string,
  filename: PropTypes.string,
};
AlternateDownloader.defaultProps = {
  contentType: 'text/csv',
  filename: generateFilename(),
};
export default AlternateDownloader;
<commit_msg>Derp, missed some default properties<commit_after>/*
Alternate Downloader
--------------------

Certain browsers (ahem, Safari 9,ahem) have poor HTML5 support for downloads, so
the SaveAs won't work nor the 'download' attr in <a href="file.csv" download>.

This component creates a hidden <form> that submits the data you want Safari to
download to EduAPI's download service, which echoes the content back as a HTTP
response with 'content-disposition' headers to force a download dialog.
 */

import { Component, PropTypes } from 'react';
import config from '../../../constants/config';

class AlternateDownloader extends Component {
  constructor(props) {
    super(props);
    this.download = this.download.bind(this);
  }

  render() {
    return (
      <form className="hidden" action={config.eduAPI.root + 'downloads/'} method="POST" ref={ele => this.form = ele}>
        <textarea name="data" ref={ele => this.formData = ele} />
        <input name="content_type" value={this.props.contentType} />
        <input name="filename" value={this.props.filename} />
      </form>
    );
  }
  
  download(data) {
    console.log('Downloading CSV, Safari workaround active');
    //let zippedData = gzip.zip(data, { name: this.generateFilename('.csv') });
    this.formData.value = data;  //this.binToStr(zippedData);
    this.form.submit();
  }
  
  binToStr(binarray){
    return binarray.reduce((str, val, index, arr) => {
        return str + (String.fromCharCode(val));
      }, '');
  }
}

AlternateDownloader.propTypes = {
  contentType: PropTypes.string,
  filename: PropTypes.string,
};
AlternateDownloader.defaultProps = {
  contentType: 'text/csv',
  filename: 'wildcam.csv',
};
export default AlternateDownloader;

{'fraction_non_alphanumeric': 0.1520127118644068, 'fraction_numerical': 0.001059322033898305, 'mean_word_length': 3.6230110159118727, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3517363', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1128, 'n_words': 311}