Blame view
imports/client/app/routes.js
4.84 KB
c42d4eeac
|
1 |
/* eslint-disable max-len */ |
b48d5cb1c
|
2 3 4 5 6 |
import React from 'react'; import { render } from 'react-dom'; import { Router, Route, IndexRoute, browserHistory } from 'react-router'; import { Meteor } from 'meteor/meteor'; |
48c0461d6
|
7 8 9 10 |
/** * General Components */ |
b48d5cb1c
|
11 |
import Index from '/imports/client/views/app/module/Index'; |
8c4a3096b
|
12 |
import NotFound from '/imports/client/views/org/NotFound'; |
48c0461d6
|
13 14 15 16 |
/** * Org Components */ |
c4d3e07d0
|
17 |
import { App } from '/imports/client/layouts/OrgApp'; |
39d8f536d
|
18 |
import { AppModule } from '/imports/client/views/org/app/module/Index'; |
b48d5cb1c
|
19 |
import { Orgs } from '/imports/collections/orgs/index'; |
13ef5ba8c
|
20 |
import { importCsvController } from '/imports/client/views/org/importCsv/index' |
d0099dd88
|
21 22 |
//admin import { StudentDataController } from '/imports/client/views/org/admin/students/index' |
691a06c2f
|
23 24 |
import { staffViewController } from '/imports/client/views/org/admin/staff/index' import { ParentViewController } from '/imports/client/views/org/admin/parents/index' |
8c4a3096b
|
25 26 27 28 29 |
//students //teachers //parents |
d0099dd88
|
30 |
|
13ef5ba8c
|
31 |
|
6be49625f
|
32 |
|
48c0461d6
|
33 34 35 |
/** * NonOrg Components */ |
b48d5cb1c
|
36 |
import Signup from '/imports/client/views/nonOrg/enter/SignupView'; |
8c4a3096b
|
37 |
import { NonOrgApp } from '/imports/client/layouts/NonOrgApp'; |
878ca8a15
|
38 |
import {NonOrgAppModule} from '/imports/client/views/nonOrg/app/module/Index'; |
48c0461d6
|
39 40 41 42 |
/** * Invalid Org Components */ |
cc8fd8a94
|
43 44 45 46 47 48 |
/** There are three types of routes 1)getOrgRoutes: all the routes that should be present for a registered org 2)getInvalidOrgRoute: all the routes where someone tries to enter a subdomain which hasn't been registered yet (404 mostly :D) 3)getNonOrgRoutes: all routes linked to normal site, ie signing up a new org. CHeking out demo and everything internal **/ |
6be49625f
|
49 50 51 |
const getOrgRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> |
39d8f536d
|
52 |
<IndexRoute name="index" component={ AppModule } /> |
13ef5ba8c
|
53 |
<Route name="import" path="/import" component={ importCsvController } /> |
a8c5a7fb6
|
54 |
<Route name="student" path="/students" component={ StudentDataController } /> |
925ffa9d3
|
55 |
<Route name="staff" path="/staff" component={ staffViewController } /> |
691a06c2f
|
56 |
<Route name="parent" path="/parents" component={ ParentViewController } /> |
6be49625f
|
57 58 59 60 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
cc8fd8a94
|
61 |
|
b48d5cb1c
|
62 |
|
cc8fd8a94
|
63 |
const getInvalidOrgRoute = () => ( |
6be49625f
|
64 65 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
cc8fd8a94
|
66 |
<IndexRoute name="index" component={ NotFound } /> |
6be49625f
|
67 68 69 70 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
ff976df49
|
71 |
|
cc8fd8a94
|
72 |
const getNonOrgRoutes = () => ( |
6be49625f
|
73 |
<Router history={ browserHistory }> |
8c4a3096b
|
74 |
<Route path="/" component={ NonOrgApp }> |
878ca8a15
|
75 |
<IndexRoute name="index" component={ NonOrgAppModule } /> |
cc8fd8a94
|
76 |
<Route name="signup" path="/signup" component={ Signup } /> |
6be49625f
|
77 78 79 80 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
2b1ad7917
|
81 |
|
8c4a3096b
|
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
//Authenticate function to give access to users only const authenticate = (nextState, replace) => { if (!Meteor.loggingIn() && !Meteor.userId()) { replace({ pathname: '/login', state: { nextPathname: nextState.location.pathname }, }); } }; /** **/ const detectOrg = () => { orgSlug = ""; var hostnameArray = document.location.hostname.split( "." ); |
ad69864f3
|
99 100 101 102 103 104 105 106 |
if(hostnameArray[0] !== "www"){ if((hostnameArray[1]==='localhost'||hostnameArray[1]==='ydapp')){ orgSlug = hostnameArray[0]; } }else{ if((hostnameArray[2]==='localhost'||hostnameArray[2]==='ydapp')){ orgSlug = hostnameArray[1]; } |
8c4a3096b
|
107 |
} |
925ffa9d3
|
108 |
|
ad69864f3
|
109 110 |
if(orgSlug!==""){ console.log(orgSlug); |
8c4a3096b
|
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) { if(res){ Session.set('orgId', res._id); Session.set('orgSlug', orgSlug); render(getOrgRoutes(),document.getElementById('app')); }else{ render(getInvalidOrgRoute(),document.getElementById('app')); } }); }else{ render(getNonOrgRoutes(),document.getElementById('app')); } } const checkSlug = (nextState, replace) => { orgId = Session.get('orgId'); } |
27ed00b55
|
127 |
|
6be49625f
|
128 129 |
Meteor.startup(() => { detectOrg(); |
2b1ad7917
|
130 |
}); |