routes.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 from 'react';
  15. import Router from 'react-routing/src/Router';
  16. import App from './components/App';
  17. import MigrationWizard from './components/MigrationWizard';
  18. import WithSidebar from './components/WithSidebar';
  19. import MigrationList from './components/MigrationList';
  20. import MigrationView from './components/MigrationView';
  21. import ReplicaList from './components/ReplicaList';
  22. import ReplicaView from './components/ReplicaView';
  23. import ReplicaDetail from './components/ReplicaDetail';
  24. import MigrationDetail from './components/MigrationDetail';
  25. import MigrationTasks from './components/MigrationTasks';
  26. import ReplicaSchedule from './components/ReplicaSchedule';
  27. import CloudConnection from './components/CloudConnection';
  28. import CloudConnectionsView from './components/CloudConnectionsView';
  29. import CloudConnectionDetail from './components/CloudConnectionDetail';
  30. import CloudConnectionAuth from './components/CloudConnectionAuth';
  31. import ConnectionsList from './components/EndpointList';
  32. import Project from './components/Project';
  33. import ProjectDetail from './components/ProjectDetail';
  34. import ProjectList from './components/ProjectList';
  35. import ReplicaExecutions from './components/ReplicaExecutions';
  36. import UserView from './components/UserView';
  37. import UserOverview from './components/UserOverview';
  38. import ContactPage from './components/ContactPage';
  39. import LoginPage from './components/LoginPage';
  40. import RegisterPage from './components/RegisterPage';
  41. import NotFoundPage from './components/NotFoundPage';
  42. import ErrorPage from './components/ErrorPage';
  43. import Federate from './components/Federate';
  44. const router = new Router(on => {
  45. on('*', async (state, next) => {
  46. const component = await next();
  47. return component && <App context={state.context}>{component}</App>;
  48. });
  49. on('/', async () => <LoginPage />)
  50. on('/login', async () => <LoginPage />)
  51. on('/federate/:token', async (params) => <Federate token={params.params.token} />)
  52. on('/migrations', async () => <WithSidebar route="/migrations"><MigrationList /></WithSidebar>)
  53. on('/migrations/new', async () => <MigrationWizard wizard_type="migration" />)
  54. on('/migration/:migrationId/', async (params) =>
  55. <MigrationView migrationId={params.params.migrationId} type="detail"><MigrationDetail /></MigrationView>
  56. )
  57. on('/migration/tasks/:migrationId/', async (params) =>
  58. <MigrationView migrationId={params.params.migrationId} type="tasks"><MigrationTasks /></MigrationView>
  59. )
  60. on('/migration/schedule/:migrationId/', async (params) =>
  61. <MigrationView migrationId={params.params.migrationId} type="schedule"><ReplicaSchedule /></MigrationView>
  62. )
  63. on('/replicas', async () => <WithSidebar route="/replicas"><ReplicaList /></WithSidebar>)
  64. on('/replicas/new', async () => <MigrationWizard wizard_type="replica" />)
  65. on('/replica/:replicaId/', async (params) =>
  66. <ReplicaView replicaId={params.params.replicaId} type="detail"><ReplicaDetail /></ReplicaView>
  67. )
  68. on('/replica/executions/:replicaId/', async (params) =>
  69. <ReplicaView replicaId={params.params.replicaId} type="tasks"><ReplicaExecutions /></ReplicaView>
  70. )
  71. on('/replica/schedule/:replicaId/', async (params) =>
  72. <ReplicaView replicaId={params.params.replicaId} type="schedule"><ReplicaSchedule /></ReplicaView>
  73. )
  74. on('/cloud-endpoints', async () =>
  75. <WithSidebar route="/cloud-endpoints"><ConnectionsList /></WithSidebar>
  76. )
  77. on('/cloud-endpoints/:connectionId/', async (params) =>
  78. <CloudConnection connectionId={params.params.connectionId}>
  79. <CloudConnectionsView type="detail">
  80. <CloudConnectionDetail />
  81. </CloudConnectionsView>
  82. </CloudConnection>
  83. )
  84. on('/cloud-endpoints/auth/:connectionId/', async (params) =>
  85. <CloudConnection connectionId={params.params.connectionId}>
  86. <CloudConnectionsView type="auth">
  87. <CloudConnectionAuth />
  88. </CloudConnectionsView>
  89. </CloudConnection>
  90. )
  91. on('/projects', async () =>
  92. <WithSidebar route="/projects"><ProjectList /></WithSidebar>
  93. )
  94. on('/project/details/:projectId/', async (params) =>
  95. <Project projectId={params.params.projectId}>
  96. <ProjectDetail />
  97. </Project>
  98. )
  99. on('/user/profile/', async () => <UserView type="profile"><UserOverview /></UserView>)
  100. on('/user/billing/', async () =>
  101. <UserView type="billing"><div className="no-result">Nothing here yet</div></UserView>
  102. )
  103. on('/contact', async () => <ContactPage />);
  104. on('/login', async () => <LoginPage />);
  105. on('/register', async () => <RegisterPage />);
  106. on('error', (state, error) => state.statusCode === 404 ?
  107. <App context={state.context} error={error}><NotFoundPage /></App> :
  108. <App context={state.context} error={error}><ErrorPage /></App>
  109. );
  110. });
  111. export default router;