<commit_before>var subSocket = null;

var mPendingUnits = [];

var mLoadModal = {
    pendingUnit: {},
    cert: null,
    certs: [
        { name: "a.cert" },
        { name: "b.cert" }
    ],
    passphrase: null,
    decrypting: false,
    nextEnabled: true,
    destinations: [
        "Holding",
        "Pre-Ingest",
        "Holding + Sandbox"
    ]
};

//Controller for displaying Pending Units grid
function PendingUnitsCtrl($scope) {
    $scope.pendingUnits = mPendingUnits;

    $scope.loadDialog = function(pendingUnit) {
        //update the model
        mLoadModal.pendingUnit = pendingUnit;

        //show the load modal
        $('#loadModal').modal('show');
    };
}

//Controller for the Load modal dialog
function LoadModalCtrl($scope, $http) {
    $scope.loadModal = mLoadModal;

   updateCertsModel($http);

    $scope.uploadCertDialog = function() {
        //show the uploadCert modal
        $('#uploadCertModal').modal('show');
    };

    $scope.next = function() {
      var selected = $('#LoadWizard').wizard('selectedItem').step;

      if(selected == 1) {
        //changed "Decrypt" -> "Review Unit"

        //instruct the server to decrypt the unit
        decrypt(mLoadModal.pendingUnit, mLoadModal.cert, mLoadModal.passphrase);

        //show waiting for decrypt
        mLoadModal.decrypting = true;
      }

      if(selected == 2) {
        mLoadModal.nextEnabled = false;
      }

      //$('#LoadWizard').wizard('selectItem', { step: selectedIdx + 1 });
      $('#LoadWizard').wizard('next');
    };

    $scope.startLoad = function () {

        //disable the load button on the main dialog for the unit
        //TODO

        //send message to initiate load
        doStartLoad(mLoadModal.pendingUnit, mLoadModal.cert, mLoadModal.passphrase);

        //hide the load button for this unit and show the progress bar for the load
        updatePending(function(model) {
            $.each(model, function(i, v) {
                if(v.src == mLoadModal.pendingUnit.src) {
                    v.showComplete = true;
                }
            });
        });

        //close modal dialog
        $('#loadModal').modal('hide');

        //reset dialog
        mLoadModal.nextEnabled = true; //re-enable for next time
    };
    
    /*$scope.safeApply = function(fn) {
        var phase = this.$root.$$phase;
        if(phase == '$apply' || phase == '$digest') {
            if(fn && (typeof(fn) === 'function')) {
                fn();
            }
        } else {
            this.$apply(fn);
        }
    }; */
}

function expandPendingUnitParts(pendingUnit) {
  var parts = [];
  var unitName = pendingUnit.label;
  $.each(pendingUnit.parts, function(i, v) {
    parts.push({
      unit: unitName,
      series: v,
      destination: ''
    });
  });
  return parts;<commit_msg>[ignore] added comment about safeApply method<commit_after>var subSocket = null;

var mPendingUnits = [];

var mLoadModal = {
    pendingUnit: {},
    cert: null,
    certs: [
        { name: "a.cert" },
        { name: "b.cert" }
    ],
    passphrase: <PASSWORD>,
    decrypting: false,
    nextEnabled: true,
    destinations: [
        "Holding",
        "Pre-Ingest",
        "Holding + Sandbox"
    ]
};

//Controller for displaying Pending Units grid
function PendingUnitsCtrl($scope) {
    $scope.pendingUnits = mPendingUnits;

    $scope.loadDialog = function(pendingUnit) {
        //update the model
        mLoadModal.pendingUnit = pendingUnit;

        //show the load modal
        $('#loadModal').modal('show');
    };
}

//Controller for the Load modal dialog
function LoadModalCtrl($scope, $http) {
    $scope.loadModal = mLoadModal;

   updateCertsModel($http);

    $scope.uploadCertDialog = function() {
        //show the uploadCert modal
        $('#uploadCertModal').modal('show');
    };

    $scope.next = function() {
      var selected = $('#LoadWizard').wizard('selectedItem').step;

      if(selected == 1) {
        //changed "Decrypt" -> "Review Unit"

        //instruct the server to decrypt the unit
        decrypt(mLoadModal.pendingUnit, mLoadModal.cert, mLoadModal.passphrase);

        //show waiting for decrypt
        mLoadModal.decrypting = true;
      }

      if(selected == 2) {
        mLoadModal.nextEnabled = false;
      }

      //$('#LoadWizard').wizard('selectItem', { step: selectedIdx + 1 });
      $('#LoadWizard').wizard('next');
    };

    $scope.startLoad = function () {

        //disable the load button on the main dialog for the unit
        //TODO

        //send message to initiate load
        doStartLoad(mLoadModal.pendingUnit, mLoadModal.cert, mLoadModal.passphrase);

        //hide the load button for this unit and show the progress bar for the load
        updatePending(function(model) {
            $.each(model, function(i, v) {
                if(v.src == mLoadModal.pendingUnit.src) {
                    v.showComplete = true;
                }
            });
        });

        //close modal dialog
        $('#loadModal').modal('hide');

        //reset dialog
        mLoadModal.nextEnabled = true; //re-enable for next time
    };
    
    // Taken from https://coderwall.com/p/ngisma - but disabled as seems to cause other problems!
    /*$scope.safeApply = function(fn) {
        var phase = this.$root.$$phase;
        if(phase == '$apply' || phase == '$digest') {
            if(fn && (typeof(fn) === 'function')) {
                fn();
            }
        } else {
            this.$apply(fn);
        }
    }; */
}

function expandPendingUnitParts(pendingUnit) {
  var parts = [];
  var unitName = pendingUnit.label;
  $.each(pendingUnit.parts, function(i, v) {
    parts.push({
      unit: unitName,
      series: v,
      destination: ''
    });
  });
  return parts;
{'fraction_non_alphanumeric': 0.13871635610766045, 'fraction_numerical': 0.0010351966873706005, 'mean_word_length': 2.0851516764236298, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 1, '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': '3278496', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1689, 'n_words': 401}