{"size": 2224, "ext": "js", "max_stars_repo_path": "src/js/actions/MesosActions.js", "max_stars_repo_name": "Kornel/marathon-ui", "max_stars_repo_stars_event_min_datetime": "2015-06-04T15:53:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T05:57:38.000Z", "max_issues_repo_path": "src/js/actions/MesosActions.js", "max_issues_repo_name": "Kornel/marathon-ui", "max_issues_repo_issues_event_min_datetime": "2015-06-04T13:24:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-20T20:49:27.000Z", "max_forks_repo_path": "src/js/actions/MesosActions.js", "max_forks_repo_name": "Kornel/marathon-ui", "max_forks_repo_forks_event_min_datetime": "2015-06-05T08:05:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-16T12:01:16.000Z"}
{"max_stars_count": 251, "max_issues_count": 683, "max_forks_count": 99, "avg_line_length": 27.8, "max_line_length": 71, "alphanum_fraction": 0.589028777}
import semver from "semver";

import AppDispatcher from "../AppDispatcher";
import JSONPUtil from "../helpers/JSONPUtil";
import MesosEvents from "../events/MesosEvents";

var MesosActions = {
  requestVersionInformation: function (host) {
    this.request(`${host}/version`).then(
      function (data) {
        AppDispatcher.dispatch({
          actionType: MesosEvents.REQUEST_VERSION_INFORMATION_COMPLETE,
          data: data
        });
      },
      function (error) {
        AppDispatcher.dispatch({
          actionType: MesosEvents.REQUEST_VERSION_INFORMATION_ERROR,
          data: {error: error}
        });
      }
    );
  },
  requestState: function (id, host, mesosVersion) {
    var route = "/state.json";
    if (semver.valid(mesosVersion) &&
        semver.satisfies(mesosVersion,">=0.26.0")) {
      route = "/state";
    }

    this.request(`${host}${route}`).then(
      function (state) {
        AppDispatcher.dispatch({
          actionType: MesosEvents.REQUEST_STATE_COMPLETE,
          data: {id: id, state: state}
        });
      },
      function (error) {
        AppDispatcher.dispatch({
          actionType: MesosEvents.REQUEST_STATE_ERROR,
          data: {id: id, error: error}
        });
      }
    );
  },
  requestFiles: function (id, host, filePath, mesosVersion) {
    var route = "/files/browse.json";
    if (semver.valid(mesosVersion) &&
        semver.satisfies(mesosVersion,">=0.26.0")) {
      route = "/files/browse";
    }

    this.request(
      `${host}${route}?path=${encodeURIComponent(filePath)}`)
      .then(
        function (files) {
          AppDispatcher.dispatch({
            actionType: MesosEvents.REQUEST_FILES_COMPLETE,
            data: {id: id, host: host, files: files}
          });
        },
        function (error) {
          AppDispatcher.dispatch({
            actionType: MesosEvents.REQUEST_FILES_ERROR,
            data: {id: id, error: error}
          });
        }
      );
  },
  requestTaskFiles: function (agentId, taskId) {
    AppDispatcher.dispatchNext({
      actionType: MesosEvents.REQUEST_TASK_FILES,
      data: {agentId: agentId, taskId: taskId}
    });
  },
  request: JSONPUtil.request
};

export default MesosActions;
