<commit_before>/* jshint browser: true, jquery: true */
/* global DataSource:false, console:false, server:false, viewDataSourceWizard:false */

function addDataSource(dataSource) {
  // TODO: determine the correct row (row of last element for column + 1)
  sendAddDataSource(dataSource);
}

function updateDataSource(dataSource) {
  // TODO: determine the correct row (row of last element for column + 1)
  sendUpdateDataSource(dataSource);
}

function processDataSourceMessages(server, id, content) {
  var processed = false;

  switch (id) {
    case DataSource.MESSAGE_DATA_SOURCES:
      receivedDataSources(server, content);
      processed = true;
      break;

    case DataSource.MESSAGE_ADD_DATA_SOURCE:
      receivedAddDataSource(server, new DataSource(content));
      processed = true;
      break;

    case DataSource.MESSAGE_DELETE_DATA_SOURCE:
      receivedDeleteDataSource(server, content);
      processed = true;
      break;

    case DataSource.MESSAGE_UPDATE_DATA_SOURCE:
      receivedUpdateDataSource(server, new DataSource(content));
      processed = true;
      break;
  }

  return processed;
}

function receivedAddDataSource(server, d) {
  addDataSourceToDom(d);
}

function receivedDeleteDataSource(server, id) {
  deleteDataSource(id);
}

function receivedUpdateDataSource(server, dataSource) {
  // get current data
  var currentDataSourceElement = $('#dataSource' + dataSource.id);
  
  var currentDataSource = new DataSource(currentDataSourceElement.data());
  
  console.log("current data for " + dataSource.id + " is: " + JSON.stringify(currentDataSource, null, " "));
  
  // apply changes to DOM
  if(currentDataSource.name !== dataSource.name) {
    
  }
  
  if(currentDataSource.iconName !== dataSource.iconName) {
    
  }
  
  // update data attributes for id
  
}

function receivedDataSources(server, d) {
  // TODO: logic to handle resend of dataSources
  // $(".dataSourceRow").remove();

  var dataSourcesArray = [];
  
  for (var item in d) {
   dataSourcesArray.push(new DataSource(d[item]));
  }

  dataSourcesArray.sort(function (a, b) {
      if (a.row < b.row) {
          return -1;
      } else if (a.row > b.row) {
          return 1;
      }
      return 0;
  });

  dataSourcesArray.forEach(function (p) {
    addDataSourceToDom(p);
  });
}

function sendAddDataSource(dataSource) {
  server.sendMessage(DataSource.MESSAGE_ADD_DATA_SOURCE, dataSource);
}

function sendDeleteDataSource(id) {
  server.sendMessage(DataSource.MESSAGE_DELETE_DATA_SOURCE, id);
}

function sendUpdateDataSource(dataSource) {
  server.sendMessage(DataSource.MESSAGE_UPDATE_DATA_SOURCE, dataSource);
}

function addDataSourceToDom(dataSource) {
  $("#dataSourcesGrid").append(
    '<tr id="dataSourceRow' + dataSource.id + '">' +
    '  <td><a class="dataSourceRow" href="#inputmask">' + dataSource.type + '</a></td>' +
    '  <td>' + dataSource.name + '</td>' +
    '  <td class="rowlink-skip">' + 
    '    <div class="btn-group pull-right">' +
    '      <button id="dataSourceBtnDelete' + dataSource.id + '" type="button" class="gridRowButtons btn btn-default ">' +
    '        <i class="fa fa-trash"></i>' +
    '      </button>' +
    '    </div>' +
    '  </td>' +
    '</tr>'
  );
  
  $('#dataSource' + dataSource.id).hide().fadeIn('fast');
    
  $('#dataSourceBtnDelete' + dataSource.id).on('click', function() {
    sendDeleteDataSource(dataSource.id);
  });
}

function deleteDataSource(id) {
  $('#dataSourceRow' + id)
    .animate({height: 0, padding: 0, margin: 0}, {easing: "linear", duration: "slow", queue: false})
    .fadeOut('slow', function() {
    this.remove();
  });
}


function dataSourceDialogSourceLogic(fields) {
  var paymentType = ((fields.paymentType !== null && fields.paymentType !== undefined) ? fields.paymentType : 'Version One');

  switch(paymentType) {
    case "Version One":
      return 0;
      
    case "Jenkins":
      return 1;
      
    case "Hudson":
      return 2;
      
    case "Salesforce.com":
      return 3;
      
    case "Internal":
      return 4;
  }

  return 0;<commit_msg>Added dataSources<commit_after>/* jshint browser: true, jquery: true */
/* global DataSource:false, console:false, server:false, viewDataSourceWizard:false */

function addDataSource(dataSource) {
  // TODO: determine the correct row (row of last element for column + 1)
  sendAddDataSource(dataSource);
}

function updateDataSource(dataSource) {
  // TODO: determine the correct row (row of last element for column + 1)
  sendUpdateDataSource(dataSource);
}

function processDataSourceMessages(server, id, content) {
  var processed = false;

  switch (id) {
    case DataSource.MESSAGE_DATA_SOURCES:
      receivedDataSources(server, content);
      processed = true;
      break;

    case DataSource.MESSAGE_ADD_DATA_SOURCE:
      receivedAddDataSource(server, new DataSource(content));
      processed = true;
      break;

    case DataSource.MESSAGE_DELETE_DATA_SOURCE:
      receivedDeleteDataSource(server, content);
      processed = true;
      break;

    case DataSource.MESSAGE_UPDATE_DATA_SOURCE:
      receivedUpdateDataSource(server, new DataSource(content));
      processed = true;
      break;
  }

  return processed;
}

function receivedAddDataSource(server, d) {
  addDataSourceToDom(d);
}

function receivedDeleteDataSource(server, id) {
  deleteDataSource(id);
}

function receivedUpdateDataSource(server, dataSource) {
  // get current data
  var currentDataSourceElement = $('#dataSource' + dataSource.id);
  
  var currentDataSource = new DataSource(currentDataSourceElement.data());
  
  console.log("current data for " + dataSource.id + " is: " + JSON.stringify(currentDataSource, null, " "));
  
  // apply changes to DOM
  if(currentDataSource.name !== dataSource.name) {
    
  }
  
  if(currentDataSource.iconName !== dataSource.iconName) {
    
  }
  
  // update data attributes for id
  
}

function receivedDataSources(server, d) {
  // TODO: logic to handle resend of dataSources
  // $(".dataSourceRow").remove();

  var dataSourcesArray = [];
  
  for (var item in d) {
   dataSourcesArray.push(new DataSource(d[item]));
  }

  dataSourcesArray.sort(function (a, b) {
      if (a.row < b.row) {
          return -1;
      } else if (a.row > b.row) {
          return 1;
      }
      return 0;
  });

  dataSourcesArray.forEach(function (p) {
    addDataSourceToDom(p);
  });
}

function sendAddDataSource(dataSource) {
  server.sendMessage(DataSource.MESSAGE_ADD_DATA_SOURCE, dataSource);
}

function sendDeleteDataSource(id) {
  server.sendMessage(DataSource.MESSAGE_DELETE_DATA_SOURCE, id);
}

function sendUpdateDataSource(dataSource) {
  server.sendMessage(DataSource.MESSAGE_UPDATE_DATA_SOURCE, dataSource);
}

function addDataSourceToDom(dataSource) {
  $("#dataSourcesGrid").append(
    '<tr id="dataSourceRow' + dataSource.id + '">' +
    '  <td><a class="dataSourceRow" href="#inputmask">' + dataSource.type + '</a></td>' +
    '  <td>' + dataSource.name + '</td>' +
    '  <td class="rowlink-skip">' + 
    '    <div class="btn-group pull-right">' +
    '      <button id="dataSourceBtnDelete' + dataSource.id + '" type="button" class="gridRowButtons btn btn-default ">' +
    '        <i class="fa fa-trash"></i>' +
    '      </button>' +
    '    </div>' +
    '  </td>' +
    '</tr>'
  );
  
  $('#dataSource' + dataSource.id).hide().fadeIn('fast');
    
  $('#dataSourceBtnDelete' + dataSource.id).on('click', function() {
    sendDeleteDataSource(dataSource.id);
  });
  
  dataSources.push(dataSource);
}

// TODO: sort out this global
var dataSources = [];

function deleteDataSource(id) {
  $('#dataSourceRow' + id)
    .animate({height: 0, padding: 0, margin: 0}, {easing: "linear", duration: "slow", queue: false})
    .fadeOut('slow', function() {
    this.remove();
  });
}


function dataSourceDialogSourceLogic(fields) {
  var paymentType = ((fields.paymentType !== null && fields.paymentType !== undefined) ? fields.paymentType : 'Version One');

  switch(paymentType) {
    case "Version One":
      return 0;
      
    case "Jenkins":
      return 1;
      
    case "Hudson":
      return 2;
      
    case "Salesforce.com":
      return 3;
      
    case "Internal":
      return 4;
  }

  return 0;
{'fraction_non_alphanumeric': 0.13771802325581395, 'fraction_numerical': 0.003391472868217054, 'mean_word_length': 3.4344790547798065, 'pattern_counts': {'":': 10, '<': 37, '<?xml version=': 0, '>': 37, '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': '768236', 'n_tokens_mistral': 2578, 'n_tokens_neox': 2518, 'n_words': 544}