Blame view
imports/client/app/routes.js
8.67 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'; |
d532f2f02
|
7 |
import { Users } from '/imports/collections/users/index'; |
48c0461d6
|
8 9 10 11 |
/** * General Components */ |
8c4a3096b
|
12 |
import NotFound from '/imports/client/views/org/NotFound'; |
48c0461d6
|
13 14 15 16 |
/** * Org Components */ |
d532f2f02
|
17 |
import { EnterModule } from '/imports/client/views/org/enter/module/index'; |
48c0461d6
|
18 |
|
d532f2f02
|
19 20 21 |
import { AdminAppModule } from '/imports/client/views/org/admin/app/module/Index'; import { DashboardController } from '/imports/client/views/org/admin/dashboard/index'; |
b48d5cb1c
|
22 |
import { Orgs } from '/imports/collections/orgs/index'; |
13ef5ba8c
|
23 |
import { importCsvController } from '/imports/client/views/org/importCsv/index' |
5a9f270de
|
24 25 26 |
/** Admin **/ |
ddc029ad3
|
27 28 29 30 31 |
//settings import { AdminSettingsModule } from '/imports/client/views/org/admin/settings/module/index' import { AdminSettingsController } from '/imports/client/views/org/admin/settings/basic/index' import { UserRolesController } from '/imports/client/views/org/admin/settings/userroles/index' import { ClassInfoController } from '/imports/client/views/org/admin/settings/classinfo/index' |
e277faafa
|
32 33 34 35 36 |
import { AdminUsersModule } from '/imports/client/views/org/admin/users/module/index' import { AdminUsersListController } from '/imports/client/views/org/admin/users/list/index' import { StudentDataController } from '/imports/client/views/org/admin/users/students/index' import { staffViewController } from '/imports/client/views/org/admin/users/staff/index' import { ParentViewController } from '/imports/client/views/org/admin/users/parents/index' |
5a9f270de
|
37 38 39 40 41 42 |
//Admin mail import { AdminMailModule } from '/imports/client/views/org/admin/mailbox/module/index' import { AdminInboxController } from '/imports/client/views/org/admin/mailbox/inbox/index' import { AdminComposeMailController } from '/imports/client/views/org/admin/mailbox/compose/index' import { AdminSentMailController } from '/imports/client/views/org/admin/mailbox/sent/index' import { AdminImportantMailController } from '/imports/client/views/org/admin/mailbox/important/index' |
6adcdac35
|
43 |
import { FeeInfoController } from '/imports/client/views/org/admin/finance/feestrucure/index' |
5a9f270de
|
44 |
|
8c4a3096b
|
45 46 47 48 49 |
//students //teachers //parents |
d0099dd88
|
50 |
|
48c0461d6
|
51 52 53 |
/** * Invalid Org Components */ |
cc8fd8a94
|
54 55 56 57 58 59 |
/** 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 **/ |
d532f2f02
|
60 |
const getOrgAdminRoutes = () => ( |
6be49625f
|
61 |
<Router history={ browserHistory }> |
e277faafa
|
62 63 64 65 |
<Route path="/" component = { AdminAppModule } > <IndexRoute name="index" component = { DashboardController } /> <Route name="import" path="/import" component = { importCsvController } /> <Route name="settings" path="/settings" component = { AdminSettingsController } /> |
ddc029ad3
|
66 67 68 69 70 71 |
<Route name="settings" exact={true} path = "/settings" component = { AdminSettingsModule}> <IndexRoute component = { AdminSettingsController} /> <Route name="userroles" path = "/settings/userroles" component = { UserRolesController} /> <Route name="classinfo" path = "/settings/classinfo" component = { ClassInfoController} /> </Route> <Route name="users" exact={true} path = "/users" component = {AdminUsersModule}> |
e277faafa
|
72 73 74 75 76 |
<IndexRoute component = {AdminUsersListController} /> <Route name="students" path = "/users/students" component = {StudentDataController} /> <Route name="staff" path = "/users/staff" component = {staffViewController} /> <Route name="parents" path = "/users/parents" component = {ParentViewController} /> </Route> |
5a9f270de
|
77 78 79 80 81 82 |
<Route name="mail" path = "/mail" component = {AdminMailModule}> <IndexRoute component = {AdminInboxController} /> <Route name="mail-compose" path = "/mail/compose" component = {AdminComposeMailController} /> <Route name="mail-sent" path = "/mail/sent" component = {AdminSentMailController} /> <Route name="mail-important" path = "/mail/important" component = {AdminImportantMailController} /> </Route> |
6adcdac35
|
83 84 85 86 |
<Route> <IndexRoute component = {AdminUsersListController} /> <Route name="feestructure" path = "/fee/feestructure" component = {FeeInfoController} /> </Route> |
e277faafa
|
87 |
<Route path="*" component = { NotFound } /> |
6be49625f
|
88 89 90 |
</Route> </Router> ) |
d532f2f02
|
91 92 93 94 95 96 97 |
const getOrgNonLoggedInRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ EnterModule }> <Route path="*" component={ NotFound } /> </Route> </Router> ) |
b48d5cb1c
|
98 |
|
cc8fd8a94
|
99 |
const getInvalidOrgRoute = () => ( |
6be49625f
|
100 101 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
cc8fd8a94
|
102 |
<IndexRoute name="index" component={ NotFound } /> |
6be49625f
|
103 104 105 106 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
ff976df49
|
107 |
|
bdd4abb61
|
108 109 110 111 112 113 114 |
/** * 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
|
115 |
const getNonOrgRoutes = () => ( |
6be49625f
|
116 |
<Router history={ browserHistory }> |
8c4a3096b
|
117 |
<Route path="/" component={ NonOrgApp }> |
878ca8a15
|
118 |
<IndexRoute name="index" component={ NonOrgAppModule } /> |
cc8fd8a94
|
119 |
<Route name="signup" path="/signup" component={ Signup } /> |
6be49625f
|
120 121 122 123 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
2b1ad7917
|
124 |
|
8c4a3096b
|
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
//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
|
141 142 |
//www.app.ydapp.in // |
8c4a3096b
|
143 |
var hostnameArray = document.location.hostname.split( "." ); |
bdd4abb61
|
144 |
//['www','app', 'ydapp','in']; |
ad69864f3
|
145 146 147 148 149 150 151 152 |
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
|
153 |
} |
925ffa9d3
|
154 |
|
ad69864f3
|
155 156 |
if(orgSlug!==""){ console.log(orgSlug); |
8c4a3096b
|
157 |
Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) { |
bdd4abb61
|
158 159 |
console.log(err); console.log(res); |
d532f2f02
|
160 |
|
8c4a3096b
|
161 162 163 |
if(res){ Session.set('orgId', res._id); Session.set('orgSlug', orgSlug); |
d532f2f02
|
164 165 166 167 168 169 170 171 172 173 174 |
if(Meteor.loggingIn() || Meteor.userId()){ userRole = _.find(res.users, {userId: Meteor.user()._id}).role; Session.set('userRole', userRole); if(userRole=='ADMIN'){ render(getOrgAdminRoutes(),document.getElementById('app')); }else{ } }else{ render(getOrgNonLoggedInRoutes(),document.getElementById('app')); } |
8c4a3096b
|
175 176 177 178 179 180 181 182 183 184 185 |
}else{ render(getInvalidOrgRoute(),document.getElementById('app')); } }); }else{ render(getNonOrgRoutes(),document.getElementById('app')); } } const checkSlug = (nextState, replace) => { orgId = Session.get('orgId'); } |
27ed00b55
|
186 |
|
6be49625f
|
187 188 |
Meteor.startup(() => { detectOrg(); |
2b1ad7917
|
189 |
}); |