Blame view
imports/client/app/routes.js
4.63 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' |
925ffa9d3
|
23 |
import { staffViewController } from '/imports/client/views/org/admin/staff/index' |
8c4a3096b
|
24 25 26 27 28 |
//students //teachers //parents |
d0099dd88
|
29 |
|
13ef5ba8c
|
30 |
|
6be49625f
|
31 |
|
48c0461d6
|
32 33 34 |
/** * NonOrg Components */ |
b48d5cb1c
|
35 |
import Signup from '/imports/client/views/nonOrg/enter/SignupView'; |
8c4a3096b
|
36 |
import { NonOrgApp } from '/imports/client/layouts/NonOrgApp'; |
878ca8a15
|
37 |
import {NonOrgAppModule} from '/imports/client/views/nonOrg/app/module/Index'; |
48c0461d6
|
38 39 40 41 |
/** * Invalid Org Components */ |
cc8fd8a94
|
42 43 44 45 46 47 |
/** 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
|
48 49 50 |
const getOrgRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> |
39d8f536d
|
51 |
<IndexRoute name="index" component={ AppModule } /> |
13ef5ba8c
|
52 |
<Route name="import" path="/import" component={ importCsvController } /> |
a8c5a7fb6
|
53 |
<Route name="student" path="/students" component={ StudentDataController } /> |
925ffa9d3
|
54 |
<Route name="staff" path="/staff" component={ staffViewController } /> |
6be49625f
|
55 56 57 58 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
cc8fd8a94
|
59 |
|
b48d5cb1c
|
60 |
|
cc8fd8a94
|
61 |
const getInvalidOrgRoute = () => ( |
6be49625f
|
62 63 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
cc8fd8a94
|
64 |
<IndexRoute name="index" component={ NotFound } /> |
6be49625f
|
65 66 67 68 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
ff976df49
|
69 |
|
cc8fd8a94
|
70 |
const getNonOrgRoutes = () => ( |
6be49625f
|
71 |
<Router history={ browserHistory }> |
8c4a3096b
|
72 |
<Route path="/" component={ NonOrgApp }> |
878ca8a15
|
73 |
<IndexRoute name="index" component={ NonOrgAppModule } /> |
cc8fd8a94
|
74 |
<Route name="signup" path="/signup" component={ Signup } /> |
6be49625f
|
75 76 77 78 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
2b1ad7917
|
79 |
|
8c4a3096b
|
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
//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
|
97 98 99 100 101 102 103 104 |
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
|
105 |
} |
925ffa9d3
|
106 |
|
ad69864f3
|
107 108 |
if(orgSlug!==""){ console.log(orgSlug); |
8c4a3096b
|
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
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
|
125 |
|
6be49625f
|
126 127 |
Meteor.startup(() => { detectOrg(); |
2b1ad7917
|
128 |
}); |