summaryrefslogtreecommitdiff
path: root/ui/app/components/main_panel/section_layout.js
blob: 1c06ab28482c8da7f1a2454767365fbd25c85f3e (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// This is the layout for a service section in the main window.
// It does not do anything except for arrange items using css and html.
//

import React from 'react'
import { Button, Glyphicon } from 'react-bootstrap'

export default class SectionLayout extends React.Component {

  static get defaultProps() {return{
    icon: null,       // icon name
    buttons: null,    // button content
    status: null,     // must be one of: on, off, unknown, wait, disabled,
                      // starting, stopping, failed
    header: null,     // the first line content
    body: null,       // expanded content
    message: null,    // alert content
    error: null,      // error content
    onExpand: null,   // callback
    className: "",
    style: {}
  }}

  constructor(props) {
    super(props)
  }

  render() {
    let className = ["service-section", this.props.className].join(' ')
    let statusIcon = null
    let icon = null
    let buttons = null
    let expander = null
    let body = null
    let status = this.props.status

    if (status == "starting") {
      status = "wait"
    } else if (status == "stopping") {
      status = "wait"
    } else if (status == "failed") {
      status = "error"
    }

    if (this.props.onExpand) {
      let glyph = this.props.body ? 'triangle-bottom' : 'triangle-right'
      expander = (
        <div className="expander clickable" onClick={this.props.onExpand}>
          <Glyphicon glyph={glyph} />
        </div>
      )
    } else {
      expander = (
        <div className="expander" />
      )
    }
    if (status) {
      let className = 'status'
      if (status == 'wait') {
        className = 'status spin'
      }
      statusIcon = (
        <div className={className}>
          <img width="24px" height="24px" src={'img/' + status + '.svg' } />
        </div>
      )
    }
    if (this.props.icon) {
      icon = (
        <div className="icon">
          <img src={'img/' + this.props.icon + '.svg'} />
        </div>
      )
    }
    if (this.props.buttons) {
      buttons = (
        <div className="buttons">
          {this.props.buttons}
        </div>
      )
    }
    if (this.props.body || this.props.message) {
      body = (
        <div className="body-row">
          {this.props.message}
          {this.props.error}
          {this.props.body}
        </div>
      )
    }

    return(
      <div className={className} style={this.props.style}>
        {expander}
        <div className="shade">
          {icon}
          <div className="inner">
            <div className="header-row">
              <div className="header">
                {this.props.header}
              </div>
              {buttons}
            </div>
            {body}
          </div>
          {statusIcon}
        </div>
      </div>
    )
  }
}