Blame view
imports/client/app/routes.js
5.06 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 */ |
8c4a3096b
|
11 |
import NotFound from '/imports/client/views/org/NotFound'; |
48c0461d6
|
12 13 14 15 |
/** * Org Components */ |
c4d3e07d0
|
16 |
import { App } from '/imports/client/layouts/OrgApp'; |
39d8f536d
|
17 |
import { AppModule } from '/imports/client/views/org/app/module/Index'; |
b48d5cb1c
|
18 |
import { Orgs } from '/imports/collections/orgs/index'; |
13ef5ba8c
|
19 |
import { importCsvController } from '/imports/client/views/org/importCsv/index' |
d0099dd88
|
20 21 |
//admin import { StudentDataController } from '/imports/client/views/org/admin/students/index' |
691a06c2f
|
22 23 |
import { staffViewController } from '/imports/client/views/org/admin/staff/index' import { ParentViewController } from '/imports/client/views/org/admin/parents/index' |
bdd4abb61
|
24 |
import { AdminSettingsController } from '/imports/client/views/org/admin/settings/index' |
8c4a3096b
|
25 26 27 28 29 |
//students //teachers //parents |
d0099dd88
|
30 |
|
48c0461d6
|
31 32 33 |
/** * Invalid Org Components */ |
cc8fd8a94
|
34 35 36 37 38 39 |
/** 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
|
40 41 42 |
const getOrgRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> |
39d8f536d
|
43 |
<IndexRoute name="index" component={ AppModule } /> |
13ef5ba8c
|
44 |
<Route name="import" path="/import" component={ importCsvController } /> |
a8c5a7fb6
|
45 |
<Route name="student" path="/students" component={ StudentDataController } /> |
925ffa9d3
|
46 |
<Route name="staff" path="/staff" component={ staffViewController } /> |
bdd4abb61
|
47 48 |
<Route name="parent" path="/parents" component={ ParentViewController } /> <Route name="settings" path="/settings" component={ AdminSettingsController } /> |
6be49625f
|
49 50 51 52 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
cc8fd8a94
|
53 |
|
b48d5cb1c
|
54 |
|
cc8fd8a94
|
55 |
const getInvalidOrgRoute = () => ( |
6be49625f
|
56 57 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
cc8fd8a94
|
58 |
<IndexRoute name="index" component={ NotFound } /> |
6be49625f
|
59 60 61 62 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
ff976df49
|
63 |
|
bdd4abb61
|
64 65 66 67 68 69 70 |
/** * NonOrg Components */ import Signup from '/imports/client/views/nonOrg/enter/SignupView'; import { NonOrgApp } from '/imports/client/layouts/NonOrgApp'; import {NonOrgAppModule} from '/imports/client/views/nonOrg/app/module/Index'; |
cc8fd8a94
|
71 |
const getNonOrgRoutes = () => ( |
6be49625f
|
72 |
<Router history={ browserHistory }> |
8c4a3096b
|
73 |
<Route path="/" component={ NonOrgApp }> |
878ca8a15
|
74 |
<IndexRoute name="index" component={ NonOrgAppModule } /> |
cc8fd8a94
|
75 |
<Route name="signup" path="/signup" component={ Signup } /> |
6be49625f
|
76 77 78 79 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
2b1ad7917
|
80 |
|
8c4a3096b
|
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 = ""; |
bdd4abb61
|
97 98 |
//www.app.ydapp.in // |
8c4a3096b
|
99 |
var hostnameArray = document.location.hostname.split( "." ); |
bdd4abb61
|
100 |
//['www','app', 'ydapp','in']; |
ad69864f3
|
101 102 103 104 105 106 107 108 |
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
|
109 |
} |
925ffa9d3
|
110 |
|
ad69864f3
|
111 112 |
if(orgSlug!==""){ console.log(orgSlug); |
8c4a3096b
|
113 |
Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) { |
bdd4abb61
|
114 115 |
console.log(err); console.log(res); |
8c4a3096b
|
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
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
|
131 |
|
6be49625f
|
132 133 |
Meteor.startup(() => { detectOrg(); |
2b1ad7917
|
134 |
}); |