<commit_before>import Ember from "ember";

var get = Ember.get;
var run = Ember.run;

/**
 * Ember select-2 component wrapping the jQuery select2 plugin while
 * respecting Ember data bindings and getter/setter methods on the content.
 *
 * Terminology:
 *  - Value: The currently selected value(s). Propagated to controllers etc.
 *    through the "value=..."" binding. Types:
 *    - Object: when using select-2 without any further configuration
 *    - Array of Objects: when using select-2 with "multiple=true"
 *    - Mixed: when using select-2 with "optionValuePath=..."
 *    - Array of Mixed: when using select-2 with "multiple=true" and
 *      "optionValuePath=..."
 *
 *  - Content: Array of Objects used to present to the user for choosing the
 *    selected values. "content" cannot be an Array of Strings, the Objects are
 *    expected to have an "id" and a property to be used as the label (by default,
 *    it is "text", but it can be overwritten via "optionLabelPath"). These
 *    properties can be computed properties or just plain JavaScript values.
 */
var Select2Component = Ember.Component.extend({
  tagName: "input",
  classNames: ["form-control"],
  classNameBindings: ["inputSize"],
  attributeBindings: ["style"],
  style: "display: hidden;",

  // Bindings that may be overwritten in the template
  inputSize: "input-md",
  cssClass: null,
  optionIdPath: "id",
  optionValuePath: null,
  optionLabelPath: 'text',
  optionSelectedPath: null,
  optionHeadlinePath: 'text',
  optionDescriptionPath: 'description',
  placeholder: null,
  multiple: false,
  allowClear: false,
  enabled: true,
  query: null,
  typeaheadSearchingText: 'Searching…',
  typeaheadNoMatchesText: 'No matches found',
  typeaheadErrorText: 'Loading failed',
  searchEnabled: true,
  minimumInputLength: null,
  maximumInputLength: null,

  // internal state
  _hasSelectedMissingItems: false,
  _hasPendingContentPromise: Ember.computed.alias('content.isPending'),
  _hasFailedContentPromise: Ember.computed.alias('content.isRejected'),
  _hasPendingValuePromise: Ember.computed.alias('value.isPending'),
  _hasFailedValuePromise: Ember.computed.alias('value.isRejected'),
  _typeaheadMode: Ember.computed.bool('query'),

  didInsertElement: function() {
    var self = this,
        options = {},
        optionIdPath = this.get('optionIdPath'),
        optionLabelPath = this.get('optionLabelPath'),
        optionSelectedPath = this.get('optionSelectedPath'),
        optionHeadlinePath = this.get('optionHeadlinePath'),
        optionDescriptionPath = this.get('optionDescriptionPath'),
        content = this.get('content');


    // ensure select2 is loaded
    Ember.assert("select2 has to exist on Ember.$.fn.select2", typeof Ember.$.fn.select2 === "function");

    // setup
    options.placeholder = this.get('placeholder');
    options.multiple = this.get('multiple');
    options.allowClear = this.get('allowClear');
    options.minimumResultsForSearch = this.get('searchEnabled') ? 0 : -1 ;

<<<<<<< HEAD
=======
    options.minimumInputLength = this.get('minimumInputLength');
    options.maximumInputLength = this.get('maximumInputLength');

>>>>>>> 272fdbcbcc9af517c8c91365ca0be77f0620bf15
    // override select2's default id fetching behavior
    options.id = (function(e) {
      return (e === undefined) ? null : get(e, optionIdPath);<commit_msg>Fix conflict<commit_after>import Ember from "ember";

var get = Ember.get;
var run = Ember.run;

/**
 * Ember select-2 component wrapping the jQuery select2 plugin while
 * respecting Ember data bindings and getter/setter methods on the content.
 *
 * Terminology:
 *  - Value: The currently selected value(s). Propagated to controllers etc.
 *    through the "value=..."" binding. Types:
 *    - Object: when using select-2 without any further configuration
 *    - Array of Objects: when using select-2 with "multiple=true"
 *    - Mixed: when using select-2 with "optionValuePath=..."
 *    - Array of Mixed: when using select-2 with "multiple=true" and
 *      "optionValuePath=..."
 *
 *  - Content: Array of Objects used to present to the user for choosing the
 *    selected values. "content" cannot be an Array of Strings, the Objects are
 *    expected to have an "id" and a property to be used as the label (by default,
 *    it is "text", but it can be overwritten via "optionLabelPath"). These
 *    properties can be computed properties or just plain JavaScript values.
 */
var Select2Component = Ember.Component.extend({
  tagName: "input",
  classNames: ["form-control"],
  classNameBindings: ["inputSize"],
  attributeBindings: ["style"],
  style: "display: hidden;",

  // Bindings that may be overwritten in the template
  inputSize: "input-md",
  cssClass: null,
  optionIdPath: "id",
  optionValuePath: null,
  optionLabelPath: 'text',
  optionSelectedPath: null,
  optionHeadlinePath: 'text',
  optionDescriptionPath: 'description',
  placeholder: null,
  multiple: false,
  allowClear: false,
  enabled: true,
  query: null,
  typeaheadSearchingText: 'Searching…',
  typeaheadNoMatchesText: 'No matches found',
  typeaheadErrorText: 'Loading failed',
  searchEnabled: true,
  minimumInputLength: null,
  maximumInputLength: null,

  // internal state
  _hasSelectedMissingItems: false,
  _hasPendingContentPromise: Ember.computed.alias('content.isPending'),
  _hasFailedContentPromise: Ember.computed.alias('content.isRejected'),
  _hasPendingValuePromise: Ember.computed.alias('value.isPending'),
  _hasFailedValuePromise: Ember.computed.alias('value.isRejected'),
  _typeaheadMode: Ember.computed.bool('query'),

  didInsertElement: function() {
    var self = this,
        options = {},
        optionIdPath = this.get('optionIdPath'),
        optionLabelPath = this.get('optionLabelPath'),
        optionSelectedPath = this.get('optionSelectedPath'),
        optionHeadlinePath = this.get('optionHeadlinePath'),
        optionDescriptionPath = this.get('optionDescriptionPath'),
        content = this.get('content');


    // ensure select2 is loaded
    Ember.assert("select2 has to exist on Ember.$.fn.select2", typeof Ember.$.fn.select2 === "function");

    // setup
    options.placeholder = this.get('placeholder');
    options.multiple = this.get('multiple');
    options.allowClear = this.get('allowClear');
    options.minimumResultsForSearch = this.get('searchEnabled') ? 0 : -1 ;
    options.minimumInputLength = this.get('minimumInputLength');
    options.maximumInputLength = this.get('maximumInputLength');

    // override select2's default id fetching behavior
    options.id = (function(e) {
      return (e === undefined) ? null : get(e, optionIdPath);
{'fraction_non_alphanumeric': 0.11952609478104378, 'fraction_numerical': 0.007498500299940012, 'mean_word_length': 4.052272727272728, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '4983216', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1909, 'n_words': 554}