{"size": 1867, "ext": "js", "max_stars_repo_path": "src/Components/Settings/index.js", "max_stars_repo_name": "innovativemann/3Dpconnect", "max_stars_repo_stars_event_min_datetime": "2016-11-17T23:47:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-30T09:38:10.000Z", "max_issues_repo_path": "src/Components/Settings/index.js", "max_issues_repo_name": "Autodesk/machine-collaboration-utility", "max_issues_repo_issues_event_min_datetime": "2017-01-30T18:41:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-07T01:19:22.000Z", "max_forks_repo_path": "src/Components/Settings/index.js", "max_forks_repo_name": "innovativemann/3Dpconnect", "max_forks_repo_forks_event_min_datetime": "2016-11-17T22:30:10.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-07T17:33:48.000Z"}
{"max_stars_count": 22, "max_issues_count": 43, "max_forks_count": 17, "avg_line_length": 23.9358974359, "max_line_length": 84, "alphanum_fraction": 0.5506159614}
/* global document, confirm, location, document, prompt */
import React from 'react';
import request from 'superagent';
import autoBind from 'react-autobind';
import Button from 'react-bootstrap/lib/Button';

export default class Settings extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showRestartIcon: false,
    };

    autoBind(this);
  }

  downloadLogs() {
    request.get('/download-logs').end();
  }

  updateHostname() {
    if (!this.props.appSettings || !this.props.appSettings.hostname) {
      return;
    }

    const hostname = prompt('Update hostname', this.props.appSettings.hostname);
    if (hostname == null || hostname === '') {
      return;
    }

    request
      .post('/hostname')
      .send({ hostname })
      .set('Accept', 'application/json')
      .end();
  }

  resetMCU() {
    // eslint-disable-next-line no-restricted-globals
    const reset = confirm('Are you sure you want to restart MCU?');
    if (reset) {
      request.post('/reset').end();
      this.setState({
        showRestartIcon: true,
      });
      setTimeout(() => {
        document.location.href = '/';
      }, 10000);
    }
  }

  render() {
    return (
      <div className="list-area">
        {this.state.showRestartIcon ? (
          <div>
            <i className="fa fa-spinner fa-pulse fa-3x fa-fw" />
            <br />Restarting
          </div>
        ) : null}
        <a href="/download-logs">
          <Button style={{ width: '200px' }}>Download Logs</Button>
        </a>
        <br />
        <br />
        <Button style={{ width: '200px' }} onClick={this.updateHostname}>
          Update Hostname
        </Button>
        <br />
        <br />
        <Button style={{ width: '200px' }} bsStyle="danger" onClick={this.resetMCU}>
          Restart
        </Button>
      </div>
    );
  }
}
