<commit_before>angular.module('sasAdapter', ['ngToast', 'ngAnimate', 'ngSanitize', 'alerts'])

.factory('sasAdapter', function($q, $rootScope, ngToast, $timeout, alerts) {
  var _adapter = new h54s({
    isRemoteConfig: true
  });
  return {
    login: function(user, pass) {
      var deferred = $q.defer();
      try {
        _adapter.login(user, pass, function(status) {
          deferred.resolve(status);
        });
      } catch(e) {
        deferred.reject(e);
      }
      return deferred.promise;
    },
    call: function(sasProgram, table) {
      var deferred = $q.defer();
      var loadingToastId = ngToast.create({
        className: 'info',
        content: 'Loading: <b>' + sasProgram + '</b>'
      });

      _adapter.call(sasProgram, table, function(err, res) {
        var toast;
        for(var i = 0; i < ngToast.messages.length; i++) {
          if(loadingToastId === ngToast.messages[i].id) {
            toast = ngToast.messages[i];
            break;
          }
        }

        if(err && (err.type === 'notLoggedinError' || err.type === 'loginError')) {
          ngToast.dismiss();
          $('#login-modal').modal({
            keyboard: false,
            backdrop: 'static'
          });
          return;
        }

        if(err) {
          if(toast) {
            toast.className = 'danger';
            toast.content = 'Error loading <b>' + sasProgram + '</b>';
          } else {
            ngToast.create({
              className: 'danger',
              content: 'Error loading <b>' + sasProgram + '</b>'
            });
          }
          deferred.reject(err);
        } else {
          if(toast) {
            toast.className = 'success';
            toast.content = 'Loaded: <b>' + sasProgram + '</b>';
          } else {
            ngToast.create({
              className: 'success',
              content: 'Loaded: <b>' + sasProgram + '</b>'
            });
          }

          if(res.usermessage !== 'blank') {
            alerts.create(res.usermessage, 'info');
          }

          deferred.resolve(res);
        }

        $timeout(function() {
          if(toast) {
            ngToast.dismiss(toast.id);
          }
        }, 1500);
      });
      return deferred.promise;
    },
    createTable: function(table, macro) {
      return new h54s.Tables(table, macro);
    },
    toggleDebugMode: function() {
      if(!_adapter.debug) {
        _adapter.setDebugMode();
        $rootScope.debugMode = true;
      } else {
        _adapter.unsetDebugMode();
        $rootScope.debugMode = false;
      }
    },
    getDebugData: function() {
      return _adapter.getDebugData();
    },
    getApplicationLogs: function() {
      return _adapter.getApplicationLogs();
    },
    getSasErrors: function() {
      return _adapter.getSasErrors();
    },<commit_msg>Loading message stays open until the request is finished<commit_after>angular.module('sasAdapter', ['ngToast', 'ngAnimate', 'ngSanitize', 'alerts'])

.factory('sasAdapter', function($q, $rootScope, ngToast, $timeout, alerts) {
  var _adapter = new h54s({
    isRemoteConfig: true
  });
  return {
    login: function(user, pass) {
      var deferred = $q.defer();
      try {
        _adapter.login(user, pass, function(status) {
          deferred.resolve(status);
        });
      } catch(e) {
        deferred.reject(e);
      }
      return deferred.promise;
    },
    call: function(sasProgram, table) {
      var deferred = $q.defer();
      var loadingToastId = ngToast.create({
        className: 'info',
        content: 'Loading: <b>' + sasProgram + '</b>',
        timeout: 1e6 //around 16 minutes
      });

      _adapter.call(sasProgram, table, function(err, res) {
        var toast;
        for(var i = 0; i < ngToast.messages.length; i++) {
          if(loadingToastId === ngToast.messages[i].id) {
            toast = ngToast.messages[i];
            break;
          }
        }

        if(err && (err.type === 'notLoggedinError' || err.type === 'loginError')) {
          ngToast.dismiss();
          $('#login-modal').modal({
            keyboard: false,
            backdrop: 'static'
          });
          return;
        }

        if(err) {
          if(toast) {
            toast.className = 'danger';
            toast.content = 'Error loading <b>' + sasProgram + '</b>';
          }

          $timeout(function() {
            if(toast) {
              ngToast.dismiss(toast.id);
            }
          }, 2000);
          
          deferred.reject(err);
        } else {
          if(toast) {
            toast.className = 'success';
            toast.content = 'Loaded: <b>' + sasProgram + '</b>';
          }

          $timeout(function() {
            if(toast) {
              ngToast.dismiss(toast.id);
            }
          }, 2000);

          if(res.usermessage !== 'blank') {
            alerts.create(res.usermessage, 'info');
          }

          deferred.resolve(res);
        }
      });
      return deferred.promise;
    },
    createTable: function(table, macro) {
      return new h54s.Tables(table, macro);
    },
    toggleDebugMode: function() {
      if(!_adapter.debug) {
        _adapter.setDebugMode();
        $rootScope.debugMode = true;
      } else {
        _adapter.unsetDebugMode();
        $rootScope.debugMode = false;
      }
    },
    getDebugData: function() {
      return _adapter.getDebugData();
    },
    getApplicationLogs: function() {
      return _adapter.getApplicationLogs();
    },
    getSasErrors: function() {
      return _adapter.getSasErrors();
    },
{'fraction_non_alphanumeric': 0.14818132951084034, 'fraction_numerical': 0.004658663321985307, 'mean_word_length': 1.7483998030526835, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '2333347', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1679, 'n_words': 312}