routes.js 5.2 KB

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