index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React from 'react'
  21. import { connect } from 'react-redux'
  22. import { Route, Switch, Redirect } from 'react-router-dom'
  23. import AuthorizedRoute from './AuthorizedRoute'
  24. import { RouteComponentWithParams } from 'utils/types'
  25. import { createStructuredSelector } from 'reselect'
  26. import Navigator from 'components/Navigator'
  27. import { logged, logout, loadDownloadList } from '../App/actions'
  28. import {
  29. makeSelectLogged,
  30. makeSelectNavigator,
  31. makeSelectOauth2Enabled
  32. } from '../App/selectors'
  33. import {
  34. DOWNLOAD_LIST_POLLING_FREQUENCY,
  35. EXTERNAL_LOG_OUT_URL
  36. } from 'app/globalConstants'
  37. import { Project, ProjectList } from 'containers/Projects/Loadable'
  38. import { Sidebar } from './Loadable'
  39. import Viz from 'containers/Viz/Loadable'
  40. import { Widget, Workbench } from 'containers/Widget/Loadable'
  41. import { View, ViewEditor } from 'containers/View/Loadable'
  42. import { Source } from 'containers/Source/Loadable'
  43. import { Schedule, ScheduleEditor } from 'containers/Schedule/Loadable'
  44. import { Dashboard } from 'containers/Dashboard/Loadable'
  45. import { Account } from 'containers/Account/Loadable'
  46. import { Profile, UserProfile } from 'containers/Profile/Loadable'
  47. import { ResetPassword } from 'containers/ResetPassword/Loadable'
  48. import {
  49. OrganizationList,
  50. Organization
  51. } from 'containers/Organizations/Loadable'
  52. import { NoAuthorization } from 'containers/NoAuthorization/Loadable'
  53. import { DataManager } from 'containers/DataManager/Loadable'
  54. import { DataShareService } from 'containers/DataShareService/Loadable'
  55. import { DataGovernance } from 'containers/DataGovernance/Loadable'
  56. const styles = require('./Main.less')
  57. type MappedStates = ReturnType<typeof mapStateToProps>
  58. type MappedDispatches = ReturnType<typeof mapDispatchToProps>
  59. type IMainProps = MappedStates & MappedDispatches & RouteComponentWithParams
  60. export class Main extends React.Component<IMainProps, {}> {
  61. private downloadListPollingTimer: number
  62. constructor(props: IMainProps & RouteComponentWithParams) {
  63. super(props)
  64. this.initPolling()
  65. }
  66. public componentWillUnmount() {
  67. if (this.downloadListPollingTimer) {
  68. clearInterval(this.downloadListPollingTimer)
  69. }
  70. }
  71. private initPolling = () => {
  72. this.props.onLoadDownloadList()
  73. this.downloadListPollingTimer = window.setInterval(() => {
  74. this.props.onLoadDownloadList()
  75. }, DOWNLOAD_LIST_POLLING_FREQUENCY)
  76. }
  77. private logout = () => {
  78. const { history, oauth2Enabled, onLogout } = this.props
  79. onLogout()
  80. window.location.href = 'http://taihu.xt.wenhq.top:8083'
  81. if (oauth2Enabled) {
  82. history.replace(EXTERNAL_LOG_OUT_URL)
  83. } else {
  84. // history.replace('/login')
  85. }
  86. }
  87. private renderAccount = () => (
  88. <Account>
  89. <Switch>
  90. <Redirect from='/account' exact to='/account/profile' />
  91. <Route path='/account/profile' component={Profile} />
  92. <Route path='/account/profile/:userId' component={UserProfile} />
  93. <Route path='/account/resetPassword' component={ResetPassword} />
  94. <Route path='/account/organizations' component={OrganizationList} />
  95. <Route
  96. path='/account/organization/:organizationId'
  97. component={Organization}
  98. />
  99. </Switch>
  100. </Account>
  101. )
  102. public render() {
  103. const { logged, navigator } = this.props
  104. return logged ? (
  105. <div className={styles.container}>
  106. <Navigator show={navigator} onLogout={this.logout} />
  107. <Switch>
  108. <Route path='/project(s?)'>
  109. <Switch>
  110. <Route path='/projects' exact component={ProjectList} />
  111. <Route path='/project/:projectId'>
  112. <Project>
  113. <Switch>
  114. <Route
  115. path='/project/:projectId/portal/:portalId'
  116. component={Dashboard}
  117. />
  118. <Route
  119. path='/project/:projectId/display/:displayId'
  120. component={Viz}
  121. />
  122. <Route
  123. exact
  124. path='/project/:projectId/widget/:widgetId?'
  125. component={Workbench}
  126. />
  127. <Route
  128. exact
  129. path='/project/:projectId/view/:viewId?'
  130. component={ViewEditor}
  131. />
  132. <Route
  133. exact
  134. path='/project/:projectId/schedule/:scheduleId?'
  135. component={ScheduleEditor}
  136. />
  137. <Sidebar>
  138. <Switch>
  139. <AuthorizedRoute
  140. permission='vizPermission'
  141. path='/project/:projectId/vizs'
  142. component={Viz}
  143. />
  144. <AuthorizedRoute
  145. permission='widgetPermission'
  146. path='/project/:projectId/widgets'
  147. component={Widget}
  148. />
  149. <AuthorizedRoute
  150. exact
  151. permission='viewPermission'
  152. path='/project/:projectId/views'
  153. component={View}
  154. />
  155. <AuthorizedRoute
  156. permission='sourcePermission'
  157. path='/project/:projectId/sources'
  158. component={Source}
  159. />
  160. <AuthorizedRoute
  161. permission='schedulePermission'
  162. path='/project/:projectId/schedules'
  163. component={Schedule}
  164. />
  165. </Switch>
  166. </Sidebar>
  167. </Switch>
  168. </Project>
  169. {/*<Switch> */}
  170. <Route
  171. path='/project/:projectId/dataManager'
  172. component={DataManager}
  173. />
  174. <Route
  175. path='/project/:projectId/dataShareService'
  176. component={DataShareService}
  177. />
  178. <Route
  179. path='/project/:projectId/dataGovernance'
  180. component={DataGovernance}
  181. />
  182. {/* </Switch> */}
  183. </Route>
  184. </Switch>
  185. </Route>
  186. <Route path='/account' render={this.renderAccount} />
  187. <Route path='/noAuthorization' component={NoAuthorization} />
  188. {/*<Redirect to='/projects' />*/}
  189. <Redirect to='/project/1/dataManager' />
  190. </Switch>
  191. </div>
  192. ) : (
  193. <div />
  194. )
  195. }
  196. }
  197. const mapStateToProps = createStructuredSelector({
  198. logged: makeSelectLogged(),
  199. oauth2Enabled: makeSelectOauth2Enabled(),
  200. navigator: makeSelectNavigator()
  201. })
  202. export function mapDispatchToProps(dispatch) {
  203. return {
  204. onLogged: (user) => dispatch(logged(user)),
  205. onLogout: () => dispatch(logout()),
  206. onLoadDownloadList: () => dispatch(loadDownloadList())
  207. }
  208. }
  209. export default connect(mapStateToProps, mapDispatchToProps)(Main)