<commit_before>import Ember from 'ember';

export default Ember.Component.extend({
  classNames: ['form-group'],
  attributeBindings: ['start', 'end'],
  start: null,
  end: null,
  timePicker: false,
  format: 'MMM D, YYYY',
  serverFormat: 'YYYY-MM-DD',
  rangeText: function() {
    var format = this.get('format');
    if (!Ember.isEmpty(this.get('start')) && !Ember.isEmpty(this.get('end'))) {
      return moment(this.get('start')).format(format) + " - " + moment(this.get('end')).format(format);
    }
  }.property('start', 'end'),
  opens: "left",
  placeholder: "",
  didInsertElement: function() {
    var self = this;
    var format = this.get('format');

    this.$('.daterangepicker-input').daterangepicker({
      locale: {
        cancelLabel: 'Clear'
      },
      format: format,
      startDate: this.get('start'),
      endDate: this.get('end'),
      timePicker: this.get('timePicker'),
      ranges: {
        Today: [moment(), moment()],
        Yesterday: [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
        'Last 7 Days': [moment().subtract(6, 'days'), moment()],
        'Last 30 Days': [moment().subtract(29, 'days'), moment()],
        'This Month': [moment().startOf('month'), moment().endOf('month')],
        'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
      },
      opens: this.get("opens")
    });
    this.$('.daterangepicker-input').on('apply.daterangepicker', function(ev, picker) {
      self.set('start', picker.startDate.format(self.get('serverFormat')));
      self.set('end', picker.endDate.format(self.get('serverFormat')));
    });

    this.$('.daterangepicker-input').on('cancel.daterangepicker', function() {
      self.$('.daterangepicker-input').val('');
      self.set('start', null);
      self.set('end', null);
    });

    this.$('.daterangepicker-input').on('show.daterangepicker', function(ev, picker) {
      if (Ember.isEmpty(self.get('start')) && Ember.isEmpty(self.get('end'))) {
        picker.setStartDate(moment());
        picker.setEndDate(moment());
      }
    });
  }
});<commit_msg>Ability to pass in properties for the picker.  Remove the dropdown when the component is destroyed.<commit_after>import Ember from 'ember';

export default Ember.Component.extend({
  classNames: ['form-group'],
  attributeBindings: ['start', 'end'],
  start: undefined,
  end: undefined,
  timePicker: false,
  format: 'MMM D, YYYY',
  serverFormat: 'YYYY-MM-DD',
  rangeText: function() {
    var format = this.get('format');
    if (!Ember.isEmpty(this.get('start')) && !Ember.isEmpty(this.get('end'))) {
      return moment(this.get('start')).format(format) + this.get('separator') + moment(this.get('end')).format(format);
    }
    return '';
  }.property('start', 'end'),
  opens: null,
  drops: null,
  separator: ' - ',
  singleDatePicker: false,
  placeholder: null,
  buttonClasses: [],
  applyClass: null,
  cancelClass: null,
  ranges: {
    'Today': [moment(), moment()],
    'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
    'Last 7 Days': [moment().subtract(6, 'days'), moment()],
    'Last 30 Days': [moment().subtract(29, 'days'), moment()],
    'This Month': [moment().startOf('month'), moment().endOf('month')],
    'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  },

  //Init the dropdown when the component is added to the DOM
  didInsertElement: function() {
    var self = this;

    this.$('.daterangepicker-input').daterangepicker({
      locale: {
        cancelLabel: 'Clear'
      },
      format: this.get('format'),
      startDate: this.get('start'),
      endDate: this.get('end'),
      timePicker: this.get('timePicker'),
      ranges: this.get('ranges'),
      buttonClasses: this.get('buttonClasses'),
      applyClass: this.get('applyClass'),
      cancelClass: this.get('cancelClass'),
      separator: this.get('separator'),
      singleDatePicker: this.get('singleDatePicker'),
      drops: this.get('drops'),
      opens: this.get('opens')
    });
    this.$('.daterangepicker-input').on('apply.daterangepicker', function(ev, picker) {
      self.set('start', picker.startDate.format(self.get('serverFormat')));
      self.set('end', picker.endDate.format(self.get('serverFormat')));
    });

    this.$('.daterangepicker-input').on('cancel.daterangepicker', function() {
      self.set('start', undefined);
      self.set('end', undefined);
    });

    this.$('.daterangepicker-input').on('show.daterangepicker', function(ev, picker) {
      picker.setStartDate(moment(self.get('start')));
      picker.setEndDate(moment(self.get('end')));
    });
  },

  //Remove the hidden dropdown when this component is destroyed
  willDestroy: function () {
    $('.daterangepicker').remove();
  }
});
{'fraction_non_alphanumeric': 0.20518625231529122, 'fraction_numerical': 0.004116073266104137, 'mean_word_length': 3.74609375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5918422', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1546, 'n_words': 288}