<commit_before>export default function dataFromControls (controls) {

  var data = {};

  // gather and clean data for storage
  controls.filterBy('value').forEach(function (control) {

    Ember.Logger.info('Extracting value from ' + control.get('controlType.widget') + ':' + control.get('name'));

    var value = control.get('value');

    if (control.get('controlType.valueType') === 'object') {

      switch (control.get('controlType.widget')) {
      case 'tabular':
        var convertedValue = Ember.A([]);
        value.forEach(function (row) {
          convertedValue.push(row.map(function (cell) {
            return cell.value || "";
          }));
        });
        value = convertedValue;
        break;

      // Help transition to object type for files.
      // Can remove in future.
      case 'image':
      case 'audio':
      case 'file':
        if (value === 'string') {
          value = {};
        }
        break;

      default:
        Ember.$.each(value, function (key, childValue) {
          if (!childValue) {
            delete value[key];
          }
        });
        break;
      }

    }

    switch (control.get('controlType.widget')) {

    // force numbers to be numbers
    case 'number':
      value = parseFloat(value);
      break;

    // add timezone to datetime values
    case 'datetime':
      value = moment(value).format();
      // add extra data for sorting
      data['_sort_' + control.get('name')] = moment(value).unix();
      break;

    // Make sure we don't try to save `undefined` for checkbox values
    case 'checkbox':
      value.rejectBy('value').setEach('value', false);
      break;

    case 'relation':
      if (control.get('meta.isSingle')) {
        if (value.length) {
          value = value.pop();
        } else {
          value = null;
        }
      }
      break;

    }

    data[control.get('name')] = value;

    switch (control.get('controlType.widget')) {
    case 'checkbox':
      Ember.Logger.info('checkbox:' + control.get('name') + ' value', value.map(function (option) {
        return option.label + ':' + option.value;
      }));
      break;

    default:
      Ember.Logger.info(control.get('controlType.widget') + ':' + control.get('name') + ' value', value);
      break;
    }

  });

  controls.filterBy('controlType.widget', 'select').forEach(function (control) {
    data[control.get('name')] = control.getWithDefault('value', '');
  });

  return data;
}<commit_msg>properly save null for layout widget<commit_after>export default function dataFromControls (controls) {

  var data = {};

  // gather and clean data for storage
  controls.filterBy('value').forEach(function (control) {

    Ember.Logger.info('Extracting value from ' + control.get('controlType.widget') + ':' + control.get('name'));

    var value = control.get('value');

    if (control.get('controlType.valueType') === 'object') {

      switch (control.get('controlType.widget')) {
      case 'tabular':
        var convertedValue = Ember.A([]);
        value.forEach(function (row) {
          convertedValue.push(row.map(function (cell) {
            return cell.value || "";
          }));
        });
        value = convertedValue;
        break;

      // Help transition to object type for files.
      // Can remove in future.
      case 'image':
      case 'audio':
      case 'file':
        if (value === 'string') {
          value = {};
        }
        break;

      default:
        Ember.$.each(value, function (key, childValue) {
          if (!childValue) {
            delete value[key];
          }
        });
        break;
      }

    }

    switch (control.get('controlType.widget')) {

    // force numbers to be numbers
    case 'number':
      value = parseFloat(value);
      break;

    // add timezone to datetime values
    case 'datetime':
      value = moment(value).format();
      // add extra data for sorting
      data['_sort_' + control.get('name')] = moment(value).unix();
      break;

    // Make sure we don't try to save `undefined` for checkbox values
    case 'checkbox':
      value.rejectBy('value').setEach('value', false);
      break;

    case 'relation':
      if (control.get('meta.isSingle')) {
        if (value.length) {
          value = value.pop();
        } else {
          value = null;
        }
      }
      break;

    }

    data[control.get('name')] = value;

    switch (control.get('controlType.widget')) {
    case 'checkbox':
      Ember.Logger.info('checkbox:' + control.get('name') + ' value', value.map(function (option) {
        return option.label + ':' + option.value;
      }));
      break;

    default:
      Ember.Logger.info(control.get('controlType.widget') + ':' + control.get('name') + ' value', value);
      break;
    }

  });

  controls.filterBy('controlType.widget', 'select').forEach(function (control) {
    data[control.get('name')] = control.getWithDefault('value', '');
  });

  controls.filterBy('controlType.widget', 'layout').forEach(function (control) {
    data[control.get('name')] = control.getWithDefault('value', null);
  });

  return data;
}
{'fraction_non_alphanumeric': 0.15809968847352024, 'fraction_numerical': 0.0, 'mean_word_length': 2.257450856055802, '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': '6398098', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1466, 'n_words': 331}