ProjectList.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 s from './ProjectList.scss';
  19. import UserStore from '../../stores/UserStore';
  20. import UserActions from '../../actions/UserActions';
  21. import TextTruncate from 'react-text-truncate';
  22. import UserIcon from '../UserIcon';
  23. import NotificationIcon from '../NotificationIcon';
  24. import ProjectsDropdown from '../ProjectsDropdown';
  25. import MainList from '../MainList';
  26. const title = 'Projects';
  27. const projectActions = null
  28. class ProjectList extends Reflux.Component {
  29. filters = [
  30. {
  31. field: "enabled",
  32. options: [
  33. { value: null, label: "All" },
  34. { value: true, label: "Enabled" },
  35. { value: false, label: "Disabled" }
  36. ]
  37. },
  38. {
  39. field: "is_domain",
  40. options: [
  41. { value: null, label: "All" },
  42. { value: true, label: "Is Domain" },
  43. { value: false, label: "Is Not Domain" }
  44. ]
  45. }
  46. ]
  47. constructor(props) {
  48. super(props)
  49. this.store = UserStore
  50. this.state = {
  51. currentUser: {
  52. projects: null
  53. }
  54. }
  55. this.renderItem = this.renderItem.bind(this)
  56. }
  57. static contextTypes = {
  58. onSetTitle: PropTypes.func.isRequired,
  59. };
  60. componentWillMount() {
  61. super.componentWillMount.call(this)
  62. this.context.onSetTitle(title);
  63. UserActions.getScopedProjects()
  64. }
  65. projectDetail(item) {
  66. Location.push('/project/details/' + item.id + "/")
  67. }
  68. switchProject(project) {
  69. UserActions.switchProject(project.id)
  70. }
  71. renderItem(item) {
  72. let projectId = Reflux.GlobalState.userStore.currentUser.project.id
  73. return (
  74. <div className={"item"} key={"project_" + item.id}>
  75. <span className="cell cell-icon" onClick={() => this.projectDetail(item)}>
  76. <div className={"icon project"}></div>
  77. <span className="details">
  78. <TextTruncate line={1} truncateText="..." text={item.name} />
  79. <span className={s.description}>{item.description == "" ? "N/A" : item.description}</span>
  80. </span>
  81. </span>
  82. <span className={"cell " + s.composite}>
  83. <span className={s.label}>Is Domain</span>
  84. <span className={s.value}>
  85. {item.is_domain ? "Yes" : "No"}
  86. </span>
  87. </span>
  88. <span className={"cell " + s.composite}>
  89. <span className={s.label}>Enabled</span>
  90. <span className={s.value}>
  91. {item.enabled ? "Yes" : "No"}
  92. </span>
  93. </span>
  94. <span className={"cell "}>
  95. <button
  96. className="wire gray"
  97. disabled={item.id == projectId}
  98. onClick={() => this.switchProject(item)}
  99. >{item.id == projectId ? "Current" : "Switch"}</button>
  100. </span>
  101. </div>
  102. )
  103. }
  104. render() {
  105. return (
  106. <div className={s.root}>
  107. <div className={s.container}>
  108. <div className={s.pageHeader}>
  109. <div className={s.top}>
  110. <h1>{title}</h1>
  111. <div className={s.topActions}>
  112. <ProjectsDropdown />
  113. <button disabled onClick={(e) => this.showNewConnectionModal(e)}>New</button>
  114. <UserIcon />
  115. <NotificationIcon />
  116. </div>
  117. </div>
  118. </div>
  119. <MainList
  120. items={this.state.currentUser.projects}
  121. actions={projectActions}
  122. itemName="project"
  123. renderItem={this.renderItem}
  124. filters={this.filters}
  125. />
  126. </div>
  127. </div>
  128. );
  129. }
  130. }
  131. export default withStyles(ProjectList, s);