{"size": 1329, "ext": "js", "max_stars_repo_path": "varOne-web/src/main/webapp/app/actions/node-action.js", "max_stars_repo_name": "SparkMonitor/varOne", "max_stars_repo_stars_event_min_datetime": "2016-01-07T19:30:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T02:32:22.000Z", "max_issues_repo_path": "varOne-web/src/main/webapp/app/actions/node-action.js", "max_issues_repo_name": "SparkMonitor/varOne", "max_issues_repo_issues_event_min_datetime": "2015-11-24T07:12:14.000Z", "max_issues_repo_issues_event_max_datetime": "2016-08-25T09:23:23.000Z", "max_forks_repo_path": "varOne-web/src/main/webapp/app/actions/node-action.js", "max_forks_repo_name": "SparkMonitor/varOne", "max_forks_repo_forks_event_min_datetime": "2015-11-24T07:15:48.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-15T15:54:03.000Z"}
{"max_stars_count": 44, "max_issues_count": 30, "max_forks_count": 17, "avg_line_length": 31.6428571429, "max_line_length": 81, "alphanum_fraction": 0.6215199398}
import alt from '../alt';
import VarOneAction from '../actions/varOne-action';
import MenuAction from '../actions/menu-action';
import request from 'superagent';

class NodeAction {

  constructor() {
    this.generateActions('changeTimePeriod');
  }

  async fetchNodes() {
    try {
      const response = await request.get('/varOne-web/rest/nodes')
                                    .set('Accept', 'application/json');
      const result = JSON.parse(response.text);
      this.dispatch(result);
    } catch (e) {
      VarOneAction.showFailMessage(e.response.text);
      MenuAction.changErrorMessageIcon(true);
    }
  }

  async fetchNodeDashBoard(node, selectMetrics, period) {
    try {
      if (selectMetrics && selectMetrics.length === 0) selectMetrics = undefined;
      else selectMetrics = selectMetrics.join(',');
      const response = await request.get(`/varOne-web/rest/nodes/${node}`)
                                    .query({ metrics: selectMetrics, period })
                                    .set('Accept', 'application/json');
      const result = JSON.parse(response.text);
      this.dispatch({ node, result, period });
    } catch (e) {
      VarOneAction.showFailMessage(e.response.text);
      MenuAction.changErrorMessageIcon(true);
    }
  }

}

export default alt.createActions(NodeAction);
