Home Reference Source

application/routes.js

import React from 'react';
import {Route, IndexRoute, withRouter} from 'react-router';

import App from './components/app';
import Dashboard from './components/dashboard';
import About from './components/about';

import Home from './components/home';

import Content from './components/content';
import ContentItem from './components/content/content-item';
import ContentDiff from './components/content/content-diff';

import Assignment from './components/assignment';
import AssignmentItem from './components/assignment/assignment-item';
import IssueView from './components/assignment/issue-view';

import Container from './components/container';
import Gallery from './components/container-gallery';
import Blog from './components/container-blog';
import ContainerItem from './components/container/container-item';
import Bounce from './components/bounce';
import Oops from './components/oops';
import Developer from './components/developer';
import Site from './components/site';
import SiteRoutes from './components/site/route';
import SiteSsl from './components/site/ssl';
import Author from './components/author';
import AuthorItem from './components/author/author-item';
import Tag from './components/tag';
import TagItem from './components/tag/tag-item';
import Issue from './components/issue';
import Support from './components/support';
import Admin from './components/admin';
import Search, {buildQuery} from './components/search';
import CurrentUser from './current-user';
import MyContent from './components/me/content';

import Plugin from './components/plugins';

import CustomContent from './components/custom-content';
import CustomContentChannel from './components/custom-content/channel';
import CustomContentEntry from './components/custom-content/entry';

import {
    globalSearchFetch,
    globalSearchRemember
} from './redux/actions/global-search-actions';

/**
 * Handle current app routes
 */
export function buildRoutes(store) {
    return (
        <Route
            path="/ceo"
            component={withRouter(App)}>
            <IndexRoute component={withRouter(Home)}/>
            <Route path="dashboard" component={Dashboard} />
            <Route path="oops" component={Oops} />

            <Route
                path="content/new"
                component={withRouter(ContentItem)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Content', 'create')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route path="content/(:id)/diff(/:version)" component={ContentDiff} />
            <Route path="content/(:id)" component={withRouter(ContentItem)} />
            <Route path="content" component={withRouter(Content)} />
            <Route path="all" component={withRouter(Content)} />
            <Route path="page" component={withRouter(Content)} />
            <Route path="media" component={withRouter(Content)} />
            <Route path="post" component={withRouter(Content)} />
            <Route path="locate/(:id)" component={withRouter(Bounce)} />
            <Route path="redirect" component={withRouter(Bounce)} />

            <Route
                path="assignment/issue/(:id)"
                component={withRouter(IssueView)}
                />
            <Route
                path="assignment/new"
                component={withRouter(AssignmentItem)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Assignment', 'create')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route path="assignment/(:id)" component={withRouter(AssignmentItem)} />
            <Route path="assignment" component={Assignment} />

            <Route
                path="container/new"
                component={withRouter(ContainerItem)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Container', 'create')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route path="container/(:id)" component={withRouter(ContainerItem)} />
            <Route path="container" component={Container} />
            <Route path="gallery" component={Gallery} />
            <Route path="blog" component={Blog} />

            <Route path="me/content" component={withRouter(MyContent)} />

            <Route
                path="settings/author"
                component={withRouter(Author)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Author', 'update')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route
                path="settings/author/:id"
                component={withRouter(AuthorItem)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Author', 'update')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route
                path="settings/tag"
                component={withRouter(Tag)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Tag', 'update')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route
                path="settings/tag/:id"
                component={withRouter(TagItem)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Tag', 'update')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route
                path="settings/issue(/:id)"
                component={Issue}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Issue', 'update')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route path="settings/about" component={About} />

            <Route path="support" component={Support} />
            <Route path="developer" component={Developer} />
            <Route path="site" component={Site} />
            <Route
                path="site/route(/:id)"
                component={SiteRoutes}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.hasRole('Administrator')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route
                path="site/ssl"
                component={SiteSsl}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.hasRole('Administrator')) {
                        replace("/ceo/oops");
                    }
                }}
                />

            <Route
                path="custom"
                component={withRouter(CustomContent)}
                />
            <Route
                path="custom/channel(/:id)"
                component={withRouter(CustomContentChannel)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Channel', 'update')) {
                        replace("/ceo/oops");
                    }
                }}
                />
            <Route
                path="custom/entry(/:id)"
                component={withRouter(CustomContentEntry)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.isAllowed('Entry', 'update')) {
                        replace("/ceo/oops");
                    }
                }}
                />

            <Route
                path="search"
                component={withRouter(Search)}
                onEnter={function (nextState, replace) {
                    store.dispatch(globalSearchRemember(nextState.location.query));
                }}
                onChange={function (prevState, nextState, replace) {
                    const query = buildQuery(nextState.location.query);
                    store.dispatch(globalSearchRemember(nextState.location.query));
                    store.dispatch(globalSearchFetch(query));
                }}
                />

            <Route
                path="admin"
                component={withRouter(Admin)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.hasRole('Administrator')) {
                        replace("/ceo/oops");
                    }
                }}
                />

            <Route
                path="plugins/:plugin(/:action)(/:uuid)"
                component={withRouter(Plugin)}
                onEnter={function (nextState, replace) {
                    if (!CurrentUser.hasRole('Administrator')) {
                        replace("/ceo/oops");
                    }
                }}
                />

        </Route>
    );
}