<commit_before>'use strict';

var plugins = global.plugins || {};

module.exports = function($http, $timeout) {
  this.idle = true
  this.status = 'idle'

  this.loadPlugin = function(id) {
    this.id = id
    this.plugin = plugins[id]
    for (var key in this.plugin) {
      this[key] = this.plugin[key]
    }
    this.pluginLoaded = true;
  }

  this.upgrade = function(cb) {
    this.perform('upgrade', function() {
      this.installed = true;
      this.outdated = false;
      this.installedVersion = this.latestVersion;
      cb();
    }.bind(this))
  }

  this.install = function(cb) {
    this.perform('install', function() {
      this.installed = true;
      this.installedVersion = this.latestVersion;
      cb();
    }.bind(this))
  }

  this.uninstall = function(cb) {
    this.perform('uninstall', function(err) {
      if (err) return cb(err)
      this.installed = false;
      this.installedVersion = 'no';
      cb();
    }.bind(this))
  }

  this.perform = function(action, cb) {
    this.status = 'requesting '+action
    this.idle = false;
    return $http.put('/admin/plugins', {
      action: action,
      id: this.id
    }).success(function(data, status, headers, config) {
      this.status = action+' in progress';
      $timeout(function() {
        waitForRestart(function() {
          this.status = 'done'
          this.idle = true
          cb()
        }.bind(this))
      }.bind(this), 2000)
    }.bind(this)).error(function(data, status, headers, config) {
      this.idle = true;
      cb(new Error(data))
    }.bind(this))
  }

  var waitForRestart = function(cb) {
    $http.head('/').success(function() {
      cb()
    }).error(function() {
      waitForRestart(cb)
    })
  }
}<commit_msg>improve wording on admin plugin manager actions<commit_after>'use strict';

var plugins = global.plugins || {};

module.exports = function($http, $timeout) {
  this.idle = true
  this.status = 'idle'

  this.loadPlugin = function(id) {
    this.id = id
    this.plugin = plugins[id]
    for (var key in this.plugin) {
      this[key] = this.plugin[key]
    }
    this.pluginLoaded = true;
  }

  this.upgrade = function(cb) {
    this.perform('upgrade', function() {
      this.installed = true;
      this.outdated = false;
      this.installedVersion = this.latestVersion;
      cb();
    }.bind(this))
  }

  this.install = function(cb) {
    this.perform('install', function() {
      this.installed = true;
      this.installedVersion = this.latestVersion;
      cb();
    }.bind(this))
  }

  this.uninstall = function(cb) {
    this.perform('uninstall', function(err) {
      if (err) return cb(err)
      this.installed = false;
      this.installedVersion = 'no';
      cb();
    }.bind(this))
  }

  this.perform = function(action, cb) {
    this.status = "Installing "+this.id;
    this.idle = false;
    return $http.put('/admin/plugins', {
      action: action,
      id: this.id
    }).success(function(data, status, headers, config) {
      this.status = 'Restarting';
      $timeout(function() {
        waitForRestart(function() {
          this.status = 'Done'
          this.idle = true
          cb()
        }.bind(this))
      }.bind(this), 2000)
    }.bind(this)).error(function(data, status, headers, config) {
      this.idle = true;
      cb(new Error(data))
    }.bind(this))
  }

  var waitForRestart = function(cb) {
    $http.head('/').success(function() {
      cb()
    }).error(function() {
      waitForRestart(cb)
    })
  }
}
{'fraction_non_alphanumeric': 0.1582260371959943, 'fraction_numerical': 0.0022889842632331904, 'mean_word_length': 2.4545454545454546, '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': '7309753', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1121, 'n_words': 226}