EndpointList.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. showValidationModal: false,
  60. connections: null
  61. }
  62. this.renderItem = this.renderItem.bind(this)
  63. }
  64. static contextTypes = {
  65. onSetTitle: PropTypes.func.isRequired,
  66. };
  67. componentWillMount() {
  68. super.componentWillMount.call(this)
  69. this.context.onSetTitle(title);
  70. if (this.state.connections == null) {
  71. ConnectionsActions.loadConnections()
  72. }
  73. }
  74. connectionDetail(e, item) {
  75. Location.push('/cloud-endpoints/' + item.id + "/")
  76. }
  77. refresh() {
  78. ConnectionsActions.loadConnections()
  79. }
  80. showNewConnectionModal() {
  81. this.setState({ showModal: true })
  82. }
  83. closeModal() {
  84. this.setState({ showModal: false })
  85. }
  86. validateConnection() {
  87. this.setState({ showValidationModal: true })
  88. }
  89. closeValidationModal() {
  90. this.setState({ showValidationModal: false })
  91. }
  92. addHandle() {
  93. }
  94. renderItem(item) {
  95. let createdAt = Helper.getTimeObject(item.created_at)
  96. return (
  97. <div className={"item " + (item.selected ? " selected" : "")} key={"vm_" + item.id}>
  98. <span className="cell cell-icon" onClick={(e) => this.connectionDetail(e, item)}>
  99. <div className={"icon endpoint"}></div>
  100. <span className="details">
  101. <TextTruncate line={1} truncateText="..." text={item.name} />
  102. <span className={s.description}>{item.description == "" ? "N/A" : item.description}</span>
  103. </span>
  104. </span>
  105. <span className="cell">
  106. <div className={s.cloudImage + " icon small-cloud " + item.type}></div>
  107. </span>
  108. <span className={"cell " + s.composite}>
  109. <span className={s.label}>Created</span>
  110. <span className={s.value}>
  111. <Moment fromNow ago date={createdAt} /> ago
  112. </span>
  113. </span>
  114. <span className={"cell " + s.composite}>
  115. <span className={s.label}>Usage</span>
  116. <span className={s.value}>
  117. <EndpointUsage connectionId={item.id} />
  118. </span>
  119. </span>
  120. </div>
  121. )
  122. }
  123. render() {
  124. let modalStyle = {
  125. overlay: {
  126. position: "fixed",
  127. top: 0,
  128. left: 0,
  129. right: 0,
  130. bottom: 0,
  131. backgroundColor: "rgba(164, 170, 181, 0.69)"
  132. },
  133. content: {
  134. padding: "0px",
  135. borderRadius: "4px",
  136. border: "none",
  137. bottom: "auto",
  138. width: "576px",
  139. height: "auto",
  140. left: "50%",
  141. top: "120px",
  142. marginLeft: "-288px"
  143. }
  144. }
  145. return (
  146. <div className={s.root}>
  147. <div className={s.container}>
  148. <div className={s.pageHeader}>
  149. <div className={s.top}>
  150. <h1>{title}</h1>
  151. <div className={s.topActions}>
  152. <ProjectsDropdown />
  153. <button onClick={(e) => this.showNewConnectionModal(e)}>New</button>
  154. <UserIcon />
  155. <NotificationIcon />
  156. </div>
  157. </div>
  158. </div>
  159. <MainList
  160. items={this.state.connections}
  161. actions={connectionActions}
  162. itemName="connection"
  163. renderItem={this.renderItem}
  164. filters={filters}
  165. refresh={this.refresh}
  166. />
  167. </div>
  168. <Modal
  169. isOpen={this.state.showModal}
  170. contentLabel="Add new cloud connection"
  171. style={modalStyle}
  172. >
  173. <AddCloudConnection
  174. closeHandle={(e) => this.closeModal(e)}
  175. addHandle={(e) => this.addHandle(e)}
  176. />
  177. </Modal>
  178. </div>
  179. );
  180. }
  181. }
  182. export default withStyles(EndpointList, s);