EndpointList.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React, { PropTypes } from 'react';
  15. import Reflux from 'reflux';
  16. import withStyles from 'isomorphic-style-loader/lib/withStyles';
  17. import Location from '../../core/Location';
  18. import Moment from 'react-moment';
  19. import s from './EndpointList.scss';
  20. import AddCloudConnection from '../AddCloudConnection';
  21. import Modal from 'react-modal';
  22. import ConnectionsStore from '../../stores/ConnectionsStore';
  23. import ConnectionsActions from '../../actions/ConnectionsActions';
  24. import TextTruncate from 'react-text-truncate';
  25. import UserIcon from '../UserIcon';
  26. import EndpointUsage from '../EndpointUsage';
  27. import NotificationIcon from '../NotificationIcon';
  28. import ProjectsDropdown from '../ProjectsDropdown';
  29. import MainList from '../MainList';
  30. import Helper from '../Helper';
  31. const title = 'Cloud Endpoints';
  32. const connectionActions = {
  33. delete_action: {
  34. label: "Delete",
  35. action: (item) => {
  36. ConnectionsActions.deleteConnection(item)
  37. },
  38. confirm: true
  39. }
  40. }
  41. const filters = [
  42. {
  43. field: "type",
  44. options: [
  45. { value: null, label: "All" },
  46. { value: "opc", label: "Oracle Cloud" },
  47. { value: "oracle_vm", label: "Oracle VM Server" },
  48. { value: "openstack", label: "Openstack" },
  49. { value: "vmware_vsphere", label: "VMware" }
  50. ]
  51. }
  52. ]
  53. class EndpointList extends Reflux.Component {
  54. constructor(props) {
  55. super(props)
  56. this.store = ConnectionsStore
  57. this.state = {
  58. showModal: false,
  59. connections: null
  60. }
  61. this.renderItem = this.renderItem.bind(this)
  62. }
  63. static contextTypes = {
  64. onSetTitle: PropTypes.func.isRequired,
  65. };
  66. componentWillMount() {
  67. super.componentWillMount.call(this)
  68. this.context.onSetTitle(title);
  69. if (this.state.connections == null) {
  70. ConnectionsActions.loadConnections()
  71. }
  72. }
  73. connectionDetail(e, item) {
  74. Location.push('/cloud-endpoints/' + item.id + "/")
  75. }
  76. refresh() {
  77. ConnectionsActions.loadConnections()
  78. }
  79. showNewConnectionModal() {
  80. this.setState({ showModal: true })
  81. }
  82. closeModal() {
  83. this.setState({ showModal: false })
  84. }
  85. addHandle() {
  86. }
  87. renderItem(item) {
  88. let createdAt = Helper.getTimeObject(item.created_at)
  89. return (
  90. <div className={"item " + (item.selected ? " selected" : "")} key={"vm_" + item.id}>
  91. <span className="cell cell-icon" onClick={(e) => this.connectionDetail(e, item)}>
  92. <div className={"icon endpoint"}></div>
  93. <span className="details">
  94. <TextTruncate line={1} truncateText="..." text={item.name} />
  95. <span className={s.description}>{item.description == "" ? "N/A" : item.description}</span>
  96. </span>
  97. </span>
  98. <span className="cell">
  99. <div className={s.cloudImage + " icon small-cloud " + item.type}></div>
  100. </span>
  101. <span className={"cell " + s.composite}>
  102. <span className={s.label}>Created</span>
  103. <span className={s.value}>
  104. <Moment fromNow ago date={createdAt} /> ago
  105. </span>
  106. </span>
  107. <span className={"cell " + s.composite}>
  108. <span className={s.label}>Usage</span>
  109. <span className={s.value}>
  110. <EndpointUsage connectionId={item.id} />
  111. </span>
  112. </span>
  113. </div>
  114. )
  115. }
  116. render() {
  117. let modalStyle = {
  118. overlay: {
  119. position: "fixed",
  120. top: 0,
  121. left: 0,
  122. right: 0,
  123. bottom: 0,
  124. backgroundColor: "rgba(164, 170, 181, 0.69)"
  125. },
  126. content: {
  127. padding: "0px",
  128. borderRadius: "4px",
  129. border: "none",
  130. bottom: "auto",
  131. width: "576px",
  132. height: "auto",
  133. left: "50%",
  134. top: "120px",
  135. marginLeft: "-288px"
  136. }
  137. }
  138. return (
  139. <div className={s.root}>
  140. <div className={s.container}>
  141. <div className={s.pageHeader}>
  142. <div className={s.top}>
  143. <h1>{title}</h1>
  144. <div className={s.topActions}>
  145. <ProjectsDropdown />
  146. <button onClick={(e) => this.showNewConnectionModal(e)}>New</button>
  147. <UserIcon />
  148. <NotificationIcon />
  149. </div>
  150. </div>
  151. </div>
  152. <MainList
  153. items={this.state.connections}
  154. actions={connectionActions}
  155. itemName="connection"
  156. renderItem={this.renderItem}
  157. filters={filters}
  158. refresh={this.refresh}
  159. />
  160. </div>
  161. <Modal
  162. isOpen={this.state.showModal}
  163. contentLabel="Add new cloud connection"
  164. style={modalStyle}
  165. >
  166. <AddCloudConnection
  167. closeHandle={(e) => this.closeModal(e)}
  168. addHandle={(e) => this.addHandle(e)}
  169. />
  170. </Modal>
  171. </div>
  172. );
  173. }
  174. }
  175. export default withStyles(EndpointList, s);