<commit_before>var qajaxWrapper = require("../helpers/qajaxWrapper");

var config = require("../config/config");
var AppDispatcher = require("../AppDispatcher");
var AppsEvents = require("../events/AppsEvents");

var AppsActions = {
  requestApps: function () {
    this.request({
      url: `${config.apiURL}v2/apps`
    })
      .success(function (apps) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APPS,
          data: apps
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APPS_ERROR,
          data: error
        });
      });
  },
  requestApp: function (appId) {
    this.request({
      url: `${config.apiURL}v2/apps/${appId}?embed=app.taskStats`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APP,
          data: app
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APP_ERROR,
          data: error
        });
      });
  },
  createApp: function (newAppAttributes) {
    this.request({
      method: "POST",
      data: newAppAttributes,
      url: `${config.apiURL}v2/apps`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.CREATE_APP,
          data: app
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.CREATE_APP_ERROR,
          data: error
        });
      });
  },
  deleteApp: function (appId) {
    this.request({
      method: "DELETE",
      headers: {
        "Content-Type": "application/json"
      },
      url: `${config.apiURL}v2/apps/${appId}`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.DELETE_APP,
          data: app,
          appId: appId
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.DELETE_APP_ERROR,
          data: error
        });
      });
  },
  restartApp: function (appId) {
    this.request({
      method: "POST",
      data: {
        force: false
      },
      url: `${config.apiURL}v2/apps/${appId}/restart`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.RESTART_APP,
          data: app,
          appId: appId
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.RESTART_APP_ERROR,
          data: error
        });
      });
  },
  scaleApp: function (appId, instances, force) {
    var url = `${config.apiURL}v2/apps/${appId}`;
    if (force) {
      url = url + "?force=true";
    }
    this.request({
      method: "PUT",
      data: {
        instances: instances
      },
      headers: {
        "Content-Type": "application/json"
      },
      url: url
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.SCALE_APP,
          data: app,
          appId: appId
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.SCALE_APP_ERROR,
          data: error,
          instances: instances
        });
      });
  },
  applySettingsOnApp: function (appId, settings, isEditing = false) {
    // Version key is not allowed and not needed on settings object
    var clonedSettings = Object.assign({}, settings);
    delete clonedSettings.version;

    // Used to mark current app config as stale
    AppDispatcher.dispatch({
      actionType: AppsEvents.APPLY_APP_REQUEST,<commit_msg>Modified url in scaleApp function as commented in PR<commit_after>var qajaxWrapper = require("../helpers/qajaxWrapper");

var config = require("../config/config");
var AppDispatcher = require("../AppDispatcher");
var AppsEvents = require("../events/AppsEvents");

var AppsActions = {
  requestApps: function () {
    this.request({
      url: `${config.apiURL}v2/apps`
    })
      .success(function (apps) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APPS,
          data: apps
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APPS_ERROR,
          data: error
        });
      });
  },
  requestApp: function (appId) {
    this.request({
      url: `${config.apiURL}v2/apps/${appId}?embed=app.taskStats`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APP,
          data: app
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.REQUEST_APP_ERROR,
          data: error
        });
      });
  },
  createApp: function (newAppAttributes) {
    this.request({
      method: "POST",
      data: newAppAttributes,
      url: `${config.apiURL}v2/apps`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.CREATE_APP,
          data: app
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.CREATE_APP_ERROR,
          data: error
        });
      });
  },
  deleteApp: function (appId) {
    this.request({
      method: "DELETE",
      headers: {
        "Content-Type": "application/json"
      },
      url: `${config.apiURL}v2/apps/${appId}`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.DELETE_APP,
          data: app,
          appId: appId
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.DELETE_APP_ERROR,
          data: error
        });
      });
  },
  restartApp: function (appId) {
    this.request({
      method: "POST",
      data: {
        force: false
      },
      url: `${config.apiURL}v2/apps/${appId}/restart`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.RESTART_APP,
          data: app,
          appId: appId
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.RESTART_APP_ERROR,
          data: error
        });
      });
  },
  scaleApp: function (appId, instances, force = false) {
    this.request({
      method: "PUT",
      data: {
        instances: instances
      },
      headers: {
        "Content-Type": "application/json"
      },
      url: `${config.apiURL}v2/apps/${appId}?force=${force}`
    })
      .success(function (app) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.SCALE_APP,
          data: app,
          appId: appId
        });
      })
      .error(function (error) {
        AppDispatcher.dispatch({
          actionType: AppsEvents.SCALE_APP_ERROR,
          data: error,
          instances: instances
        });
      });
  },
  applySettingsOnApp: function (appId, settings, isEditing = false) {
    // Version key is not allowed and not needed on settings object
    var clonedSettings = Object.assign({}, settings);
    delete clonedSettings.version;

    // Used to mark current app config as stale
    AppDispatcher.dispatch({
      actionType: AppsEvents.APPLY_APP_REQUEST,
{'fraction_non_alphanumeric': 0.13138983050847458, 'fraction_numerical': 0.0016271186440677966, 'mean_word_length': 1.9622489959839358, 'pattern_counts': {'":': 4, '<': 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': '6693365', 'n_tokens_mistral': 2192, 'n_tokens_neox': 2154, 'n_words': 414}