HTTPResponseView.jsx 2.49 KB
Newer Older
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import React, { PureComponent } from 'react'
import {Table, Navbar, Nav, NavItem, NavDropdown, MenuItem, Glyphicon, Jumbotron, Button} from 'react-bootstrap'
import {Alert, Row, Col, Collapse, FormControl, FormGroup, ControlLabel, HelpBlock, PanelGroup, Panel} from 'react-bootstrap'
import FontAwesome from 'react-fontawesome'

import HostnameController from '../containers/HostnameController'
import ServerConfigController from '../containers/ServerConfigController'
import WhiteBox from './WhiteBox'
import LoadingIndicator from '../components/LoadingIndicator'

import moment from 'moment'
import 'moment/locale/nb';
// import 'moment/locale/en';

moment.locale("en");


export function expiresText(expires) {
  var expiresM = moment.unix(expires)
  return expiresM.fromNow()
}

class Component extends PureComponent {

  updateAPIendpoint() {




  }

  fetchUserinfo() {
    let endpoint = this.props.serverConfig.userinfo_endpoint;
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
34
    // console.error("Get userinfo from ", endpoint)
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    this.props.httpRequestStart(endpoint)
  }

  fetchCustom() {

  }

  handleAlertDismiss() {

  }

  getErrorMessage() {
    if (this.props.http.error) {
      return (
        <Alert bsStyle="danger" onDismiss={this.handleAlertDismiss}>
          <h4>Error performing HTTP request</h4>
          <p>{this.props.http.error}</p>
        </Alert>
      )
    }
    return null
  }
  render() {
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
58
    // console.error("Component", this.props)
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

    if (!this.props.http) {
      return (
        <p></p>
      )
    }

    let headers = []
    if (this.props.http.response && this.props.http.response.headers) {
      this.props.http.response.headers.forEach((item) => {
        headers.push((
          <tr key={item.key}>
            <td>{item.key}</td>
            <td>{item.value}</td>
          </tr>
        ))
      })
    }

    let bodystr = this.props.http.response ? JSON.stringify(this.props.http.response.body, undefined, 2) : ''
    let loading = null
    if (this.props.http.isLoading) {
      loading = (
        <LoadingIndicator />
      )
    }


    return (
88
      <Panel header="HTTP Response" eventKey="1" collapsible={true} defaultExpanded={true}>
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
        <div>
          <p><code>GET</code> request to <code>{this.props.http.url}</code></p>
          { loading }
          {this.getErrorMessage()}
          <Table striped bordered condensed hover>
            <tbody>
              {headers}
            </tbody>
          </Table>
          <pre>{ bodystr }</pre>
        </div>
      </Panel>
    )
  }


}

export default Component