<commit_before>(function () {
  'use strict';

  angular
    .module('app')
    .controller('SamplesTabController', SamplesTabController);

  SamplesTabController.$inject = ['$ionicModal', '$ionicPopup', '$log', '$scope', '$state', 'DataModelsFactory',
    'FormFactory', 'HelpersFactory', 'ProjectFactory'];

  function SamplesTabController($ionicModal, $ionicPopup, $log, $scope, $state, DataModelsFactory, FormFactory,
                                HelpersFactory, ProjectFactory) {
    var vm = this;
    var vmParent = $scope.vm;
    vmParent.loadTab($state);     // Need to load current state into parent

    var isDelete;

    vm.addSample = addSample;
    vm.basicFormModal = {};
    vm.deleteSample = deleteSample;
    vm.editSample = editSample;
    vm.modalTitle = '';
    vm.submit = submit;

    activate();

    /**
     * Private Functions
     */

    function activate() {
      $log.log('Samples:', vmParent.spot.properties.samples);
      vmParent.survey = DataModelsFactory.getDataModel('sample').survey;
      vmParent.choices = DataModelsFactory.getDataModel('sample').choices;
      checkProperties();
      createModal();
    }

    function checkProperties() {
      _.each(vmParent.spot.properties.samples, function (sample) {
        if (!sample.label) sample.label = createDefaultLabel(sample);
        if (!sample.id) sample.id = HelpersFactory.getNewId();
      });
    }

    function createDefaultLabel(sampleToLabel) {
      return sampleToLabel.sample_id_name || 'sample';
    }

    function createModal() {
      $ionicModal.fromTemplateUrl('app/spot/basic-form-modal.html', {
        'scope': $scope,
        'animation': 'slide-in-up',
        'focusFirstInput': true,
        'backdropClickToClose': false
      }).then(function (modal) {
        vm.basicFormModal = modal;
      });

      // Cleanup the modal when we're done with it!
      $scope.$on('$destroy', function () {
        vm.basicFormModal.remove();
      });
    }

    function handleSampleNumber() {
      var found = _.find(vmParent.spot.properties.samples, function (sample) {
        return sample.id === vmParent.data.id;
      });
      if (!found) ProjectFactory.incrementSampleNumber();
    }

    /**
     * Public Functions
     */

    function addSample() {
      vmParent.data = {};
      vmParent.data.id = HelpersFactory.getNewId();
      var number = ProjectFactory.getSampleNumber() || '';
      var prefix = ProjectFactory.getSamplePrefix() || '';
      if (number !== '' || prefix !== '') vmParent.data.sample_id_name = prefix + number.toString();
      vm.modalTitle = 'Add a Sample';
      vm.basicFormModal.show();
    }

    function deleteSample(sampleToDelete) {
      isDelete = true;
      var confirmPopup = $ionicPopup.confirm({
        'title': 'Delete Sample',<commit_msg>fixed bug with adding multiple samples and form not displaying<commit_after>(function () {
  'use strict';

  angular
    .module('app')
    .controller('SamplesTabController', SamplesTabController);

  SamplesTabController.$inject = ['$ionicModal', '$ionicPopup', '$log', '$scope', '$state', 'DataModelsFactory',
    'FormFactory', 'HelpersFactory', 'ProjectFactory'];

  function SamplesTabController($ionicModal, $ionicPopup, $log, $scope, $state, DataModelsFactory, FormFactory,
                                HelpersFactory, ProjectFactory) {
    var vm = this;
    var vmParent = $scope.vm;
    vmParent.loadTab($state);     // Need to load current state into parent

    var isDelete;

    vm.addSample = addSample;
    vm.basicFormModal = {};
    vm.deleteSample = deleteSample;
    vm.editSample = editSample;
    vm.modalTitle = '';
    vm.submit = submit;

    activate();

    /**
     * Private Functions
     */

    function activate() {
      $log.log('Samples:', vmParent.spot.properties.samples);
      vmParent.survey = DataModelsFactory.getDataModel('sample').survey;
      vmParent.choices = DataModelsFactory.getDataModel('sample').choices;
      checkProperties();
      createModal();
    }

    function checkProperties() {
      _.each(vmParent.spot.properties.samples, function (sample) {
        if (!sample.label) sample.label = createDefaultLabel(sample);
        if (!sample.id) sample.id = HelpersFactory.getNewId();
      });
    }

    function createDefaultLabel(sampleToLabel) {
      return sampleToLabel.sample_id_name || 'sample';
    }

    function createModal() {
      $ionicModal.fromTemplateUrl('app/spot/basic-form-modal.html', {
        'scope': $scope,
        'animation': 'slide-in-up',
        'focusFirstInput': true,
        'backdropClickToClose': false
      }).then(function (modal) {
        vm.basicFormModal = modal;
      });

      // Cleanup the modal when we're done with it!
      $scope.$on('$destroy', function () {
        vm.basicFormModal.remove();
      });
    }

    function handleSampleNumber() {
      var found = _.find(vmParent.spot.properties.samples, function (sample) {
        return sample.id === vmParent.data.id;
      });
      if (!found) ProjectFactory.incrementSampleNumber();
    }

    /**
     * Public Functions
     */

    function addSample() {
      vmParent.survey = DataModelsFactory.getDataModel('sample').survey;
      vmParent.choices = DataModelsFactory.getDataModel('sample').choices;
      vmParent.data = {};
      vmParent.data.id = HelpersFactory.getNewId();
      var number = ProjectFactory.getSampleNumber() || '';
      var prefix = ProjectFactory.getSamplePrefix() || '';
      if (number !== '' || prefix !== '') vmParent.data.sample_id_name = prefix + number.toString();
      vm.modalTitle = 'Add a Sample';
      vm.basicFormModal.show();
    }

    function deleteSample(sampleToDelete) {
      isDelete = true;
      var confirmPopup = $ionicPopup.confirm({
        'title': 'Delete Sample',
{'fraction_non_alphanumeric': 0.1391035548686244, 'fraction_numerical': 0.0, 'mean_word_length': 2.8826666666666667, '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': '235972', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1627, 'n_words': 326}