<commit_before>'use strict';
/* global jQuery:false */

angular.module('openhimWebui2App')
  .controller('TransactionsCtrl', function ($scope, $modal, $location, Api, Alerting) {

    // get the channels for the transactions filter dropdown
    $scope.channels = Api.Channels.query(function(){
      $scope.channelsMap = {};
      angular.forEach($scope.channels, function(channel){
        $scope.channelsMap[channel._id] = channel.name;
      });
    },
    function(){
      // server error - could not connect to API to get channels
    });

    $scope.transactionsSelected = [];

    //return results for the first page (20 results)
    $scope.showpage = 0;
    $scope.showlimit = 10;
    $scope.filterStatus = '';
    $scope.filterChannel = '';
    $scope.filterDateStart = '';
    $scope.filterDateEnd = '';

    /*------------------------Transactions List and Detail view functions----------------------------*/
    //setup filter options
    $scope.returnFilterObject = function(){
      var filtersObject = {};
      var startDate, endDate;

      var filterStatus = $scope.filterStatus;
      var filterChannel = $scope.filterChannel;
      var filterDateStart = $scope.filterDateStart;
      var filterDateEnd = $scope.filterDateEnd;

      if(filterStatus){ filtersObject.status = filterStatus; }
      if(filterChannel){ filtersObject.channelID = filterChannel; }
      if(filterDateStart && filterDateEnd){
        startDate = new Date( filterDateStart ).toISOString();
        endDate = new Date( filterDateEnd );
        endDate.setDate(endDate.getDate() + 1);
        endDate = endDate.toISOString();

        filtersObject.startDate = startDate;
        filtersObject.endDate = endDate;
      }
      filtersObject.filterPage = $scope.showpage;
      filtersObject.filterLimit = $scope.showlimit;
      
      return filtersObject;
    };

    var refreshSuccess = function (transactions){
      // on success
      $scope.transactions = transactions;

      if( transactions.length < $scope.showlimit ){
        jQuery('#loadMoreTransactions').hide();

        if( transactions.length === 0 ){
          Alerting.AlertAddMsg('bottom', 'warning', 'There are no transactions for the current filters');
        }

      }else{
        //Show the load more button
        jQuery('#loadMoreTransactions').show();
      }

      //make sure newly added transactions are checked as well
      $scope.resetCheckedItems();
    };

    var refreshError = function(err){
      // on error - Hide load more button and show error message
        jQuery('#loadMoreTransactions').hide();
        Alerting.AlertAddServerMsg(err.status);
    };

    //Refresh transactions list
    $scope.refreshTransactionsList = function () {
      $scope.transactions = null;
      Alerting.AlertReset();

      //reset the showpage filter to start at 0
      $scope.showpage = 0;

      Api.Transactions.query( $scope.returnFilterObject(), refreshSuccess, refreshError);

    };
    //run the transaction list view for the first time<commit_msg>Fixed JSHint error<commit_after>'use strict';
/* global jQuery:false */

angular.module('openhimWebui2App')
  .controller('TransactionsCtrl', function ($scope, $modal, $location, Api, Alerting) {

    // get the channels for the transactions filter dropdown
    $scope.channels = Api.Channels.query(function(){
      $scope.channelsMap = {};
      angular.forEach($scope.channels, function(channel){
        $scope.channelsMap[channel._id] = channel.name;
      });
    },
    function(){
      // server error - could not connect to API to get channels
    });

    $scope.transactionsSelected = [];

    //return results for the first page (20 results)
    $scope.showpage = 0;
    $scope.showlimit = 10;
    $scope.filterStatus = '';
    $scope.filterChannel = '';
    $scope.filterDateStart = '';
    $scope.filterDateEnd = '';

    /*------------------------Transactions List and Detail view functions----------------------------*/
    //setup filter options
    $scope.returnFilterObject = function(){
      var filtersObject = {};
      var startDate, endDate;

      var filterStatus = $scope.filterStatus;
      var filterChannel = $scope.filterChannel;
      var filterDateStart = $scope.filterDateStart;
      var filterDateEnd = $scope.filterDateEnd;

      if(filterStatus){ filtersObject.status = filterStatus; }
      if(filterChannel){ filtersObject.channelID = filterChannel; }
      if(filterDateStart && filterDateEnd){
        startDate = new Date( filterDateStart ).toISOString();
        endDate = new Date( filterDateEnd );
        endDate.setDate(endDate.getDate() + 1);
        endDate = endDate.toISOString();

        filtersObject.startDate = startDate;
        filtersObject.endDate = endDate;
      }
      filtersObject.filterPage = $scope.showpage;
      filtersObject.filterLimit = $scope.showlimit;
      
      return filtersObject;
    };

    var refreshSuccess = function (transactions){
      // on success
      $scope.transactions = transactions;

      if( transactions.length < $scope.showlimit ){
        jQuery('#loadMoreTransactions').hide();

        if( transactions.length === 0 ){
          Alerting.AlertAddMsg('bottom', 'warning', 'There are no transactions for the current filters');
        }

      }else{
        //Show the load more button
        jQuery('#loadMoreTransactions').show();
      }

      //make sure newly added transactions are checked as well
      $scope.resetCheckedItems();
    };

    var refreshError = function(err){
      // on error - Hide load more button and show error message
      jQuery('#loadMoreTransactions').hide();
      Alerting.AlertAddServerMsg(err.status);
    };

    //Refresh transactions list
    $scope.refreshTransactionsList = function () {
      $scope.transactions = null;
      Alerting.AlertReset();

      //reset the showpage filter to start at 0
      $scope.showpage = 0;

      Api.Transactions.query( $scope.returnFilterObject(), refreshSuccess, refreshError);

    };
    //run the transaction list view for the first time
{'fraction_non_alphanumeric': 0.1310719578462045, 'fraction_numerical': 0.003293265272517701, 'mean_word_length': 2.6568332329921733, 'pattern_counts': {'":': 0, '<': 5, '<?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': '397069', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1574, 'n_words': 405}