Home Reference Source

application/components/admin.js

import React from 'react';
import Paper from 'material-ui/Paper';
import {Card, CardActions, CardHeader, CardText} from 'material-ui/Card';
import {browserHistory} from 'react-router';

import {Row, Col} from './flexbox';
import Config from './../config';
import CurrentUser from './../current-user';

import UserCard from './admin/user';
import GroupCard from './admin/group';
import ConnectCard from './admin/connect';
import CronCard from './admin/cron';
import WorkflowCard from './admin/workflow';
import WorkflowSectionCard from './admin/workflow-section';
import SettingsCard from './admin/settings';
import PluginsCard from './admin/plugins';
import SstsCard from './admin/ssts';

class Admin extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            openCard: false
        };

        if (!CurrentUser.hasRole('Administrator')) {
            browserHistory.push('/ceo');
            return;
        }
    }

    componentDidMount() {
        if (this.props.router.location && this.props.router.location.query._s) {
            switch(this.props.router.location.query._s) {
                case 'user':
                case 'group':
                case 'workflow':
                case 'workflowSection':
                case 'settings':
                case 'plugins':
                case 'ssts':
                    this.setState({'openCard': this.props.router.location.query._s});
                    break;
            }
        }
    }

    handleExpand(card, toggle) {
        if (toggle) {
            this.setState({'openCard': card});
        } else {
            this.setState({'openCard': false});
        }
    }

    render() {
        return (
            <div className="admin-root">
                <UserCard location={this.props.location} onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <GroupCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <WorkflowCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <WorkflowSectionCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <SettingsCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <SstsCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <PluginsCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <CronCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
                <ConnectCard onToggle={this.handleExpand.bind(this)} openCard={this.state.openCard} />
            </div>
        );
    }
}

export default Admin;