<commit_before>/** @jsx React.DOM */

define([
  "React",
  "mixins/BackboneMixin",
  "models/AppVersionCollection",
  "jsx!components/AppVersionListComponent",
  "jsx!components/ModalComponent",
  "jsx!components/StackedViewComponent",
  "jsx!components/TabPaneComponent",
  "jsx!components/TaskDetailComponent",
  "jsx!components/TaskViewComponent",
  "jsx!components/TogglableTabsComponent"
], function(React, BackboneMixin, AppVersionCollection, AppVersionListComponent,
    ModalComponent, StackedViewComponent, TabPaneComponent, TaskDetailComponent,
    TaskViewComponent, TogglableTabsComponent) {

  var STATES = {
    STATE_LOADING: 0,
    STATE_ERROR: 1,
    STATE_SUCCESS: 2
  };
  var UPDATE_INTERVAL = 2000;

  return React.createClass({
    displayName: "AppModalComponent",

    mixins: [BackboneMixin],

    componentWillMount: function() {
      this.fetchTasks();
      var appVersions = new AppVersionCollection(null, {appId: this.props.model.id});
      this.setState({appVersions: appVersions});
    },

    componentDidMount: function() {
      this.startPolling();
    },

    componentWillUnmount: function() {
      this.stopPolling();
    },

    fetchAppVersions: function() {
      this.state.appVersions.fetch({
        error: function() {
          this.setState({appVersionsFetchState: STATES.STATE_ERROR});
        }.bind(this),
        success: function() {
          this.setState({appVersionsFetchState: STATES.STATE_SUCCESS});
        }.bind(this)
      });
    },

    getResource: function() {
      return this.props.model;
    },

    getInitialState: function() {
      return {
        activeTask: null,
        activeViewIndex: 0,
        appVersions: null,
        tasksFetchState: STATES.STATE_LOADING,
        appVersionsFetchState: STATES.STATE_LOADING
      };
    },

    fetchTasks: function() {
      this.props.model.tasks.fetch({
        error: function() {
          this.setState({tasksFetchState: STATES.STATE_ERROR});
        }.bind(this),
        success: function() {
          this.setState({tasksFetchState: STATES.STATE_SUCCESS});
        }.bind(this)
      });
    },

    destroy: function() {
      this.refs.modalComponent.destroy();
    },

    destroyApp: function() {
      if (confirm("Destroy app '" + this.props.model.get("id") + "'?\nThis is irreversible.")) {
        this.props.model.destroy();
        this.refs.modalComponent.destroy();
      }
    },

    onTasksKilled: function(options) {
      var instances;
      var _options = options || {};
      if (_options.scale) {
        instances = this.props.model.get("instances");
        this.props.model.set("instances", instances - 1);
        this.setState({appVersionsFetchState: STATES.STATE_LOADING});
        // refresh app versions
        this.fetchAppVersions();
      }

      // Force an update since React doesn't know a key was removed from
      // `selectedTasks`.
      this.forceUpdate();
    },
<commit_msg>Add new “force=true” option to app destroy in UI<commit_after>/** @jsx React.DOM */

define([
  "Underscore",
  "React",
  "mixins/BackboneMixin",
  "models/AppVersionCollection",
  "jsx!components/AppVersionListComponent",
  "jsx!components/ModalComponent",
  "jsx!components/StackedViewComponent",
  "jsx!components/TabPaneComponent",
  "jsx!components/TaskDetailComponent",
  "jsx!components/TaskViewComponent",
  "jsx!components/TogglableTabsComponent"
], function(_, React, BackboneMixin, AppVersionCollection,
    AppVersionListComponent, ModalComponent, StackedViewComponent,
    TabPaneComponent, TaskDetailComponent, TaskViewComponent,
    TogglableTabsComponent) {

  var STATES = {
    STATE_LOADING: 0,
    STATE_ERROR: 1,
    STATE_SUCCESS: 2
  };
  var UPDATE_INTERVAL = 2000;

  return React.createClass({
    displayName: "AppModalComponent",

    mixins: [BackboneMixin],

    componentWillMount: function() {
      this.fetchTasks();
      var appVersions = new AppVersionCollection(null, {appId: this.props.model.id});
      this.setState({appVersions: appVersions});
    },

    componentDidMount: function() {
      this.startPolling();
    },

    componentWillUnmount: function() {
      this.stopPolling();
    },

    fetchAppVersions: function() {
      this.state.appVersions.fetch({
        error: function() {
          this.setState({appVersionsFetchState: STATES.STATE_ERROR});
        }.bind(this),
        success: function() {
          this.setState({appVersionsFetchState: STATES.STATE_SUCCESS});
        }.bind(this)
      });
    },

    getResource: function() {
      return this.props.model;
    },

    getInitialState: function() {
      return {
        activeTask: null,
        activeViewIndex: 0,
        appVersions: null,
        tasksFetchState: STATES.STATE_LOADING,
        appVersionsFetchState: STATES.STATE_LOADING
      };
    },

    fetchTasks: function() {
      this.props.model.tasks.fetch({
        error: function() {
          this.setState({tasksFetchState: STATES.STATE_ERROR});
        }.bind(this),
        success: function() {
          this.setState({tasksFetchState: STATES.STATE_SUCCESS});
        }.bind(this)
      });
    },

    destroy: function() {
      this.refs.modalComponent.destroy();
    },

    destroyApp: function() {
      if (confirm("Destroy app '" + this.props.model.get("id") + "'?\nThis is irreversible.")) {
        // Send force option to ensure the UI is always able to kill apps
        // regardless of deployment state.
        this.props.model.destroy({
          url: _.result(this.props.model, "url") + "?force=true"
        });

        this.refs.modalComponent.destroy();
      }
    },

    onTasksKilled: function(options) {
      var instances;
      var _options = options || {};
      if (_options.scale) {
        instances = this.props.model.get("instances");
        this.props.model.set("instances", instances - 1);
        this.setState({appVersionsFetchState: STATES.STATE_LOADING});
        // refresh app versions
        this.fetchAppVersions();
      }

      // Force an update since React doesn't know a key was removed from
      // `selectedTasks`.
      this.forceUpdate();
    },

{'fraction_non_alphanumeric': 0.12852969814995133, 'fraction_numerical': 0.0029211295034079843, 'mean_word_length': 2.8446662507797877, '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': '2958781', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1792, 'n_words': 329}