summaryrefslogtreecommitdiff
path: root/front-end/src/component/nav-top/index.jsx
blob: f6a9bfb54311f94cc8ecd0c8849af69e7e90ddfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React        from 'react';
import {Link}     from 'react-router-dom';

import './index.css';
import slonik from 'image/slonik.png'
import PGUtil    from 'util/util.jsx'
const _util = new PGUtil();
import User         from 'service/user-service.jsx'
const _user = new User();

class NavTop extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            // username: _util.getStorage('userInfo').username || '',
            userinfo: _util.getStorage('userInfo')|| {},
            isLoggedIn: true
        }
    }

    // logout
    onLogout() {
        _util.removeStorage('userInfo');
        window.location.href = '/login';
    }

    componentWillMount(){
        this.setState({
            isLoggedIn: this.isLoggedIn(),
        });
    }

    isLoggedIn() {
        if(this.state.userinfo.token){
            return true;
        }
        return false;
    }

    render() {
        let isLoggedIn = this.state.isLoggedIn;

        let button = null;
        if (isLoggedIn) {
            button = <li className="dropdown loggedin">
                <a className="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                    <img className="img-circle img-thumbnail user-head-pic" src={require('image/slonik.png')}
                         alt="headPic"/>
                </a>
                <ul className="dropdown-menu dropdown-alerts loggedin-ul">
                    <li>
                        <Link to="/portal">
                            <div>
                                <i className="fa fa-tasks fa-fw"></i> My machines
                            </div>
                        </Link>
                    </li>
                    <li className="divider"></li>
                    <li>
                        <a onClick={() => {this.onLogout()}}>
                            <div>
                                <i className="fa fa-upload fa-fw"></i> Log out
                            </div>
                        </a>
                    </li>
                    <li className="divider"></li>
                </ul>
            </li>;
        } else {
            button = <li className="dropdown sign-in">
                <Link to="/login" aria-expanded="false">
                    Log in
                </Link>
            </li>;
        }

        return (
            <div className="navbar navbar-default top-navbar" role="navigation">
                <div className="navbar-header">

                    <a className="navbar-brand" href="index.html"><img src={require('image/slonik.png')}/><b>PG Perf
                        Farm</b></a>
                </div>
                <ul className="nav navbar-top-links navbar-left">
                    <li><Link to="/home"> <span className="glyphicon glyphicon-home" aria-hidden="true"></span>
                        Home</Link>
                    </li>
                    <li><Link to="/status"><span className="glyphicon glyphicon-tasks" aria-hidden="true"></span>Status</Link>
                    </li>

                    <li><Link to="/machine"> <span className="glyphicon glyphicon-blackboard" aria-hidden="true"></span>Machine</Link>
                    </li>

                    <li className="dropdown">
                        <a className="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                            <span className="glyphicon glyphicon-th-large" aria-hidden="true"></span> Help
                            <span className="glyphicon glyphicon-menu-down" aria-hidden="true"></span>
                        </a>
                        <ul className="dropdown-menu dropdown-alerts">
                            <li className="divider"></li>
                            <li>
                                <a href="#">
                                    <div>
                                        <i className="fa fa-envelope fa-fw"></i> Contact
                                        {/*<span className="pull-right text-muted small">4 min</span>*/}
                                    </div>
                                </a>
                            </li>
                            <li className="divider"></li>
                            <li>
                                <a href="#">
                                    <div>
                                        <i className="fa fa-tasks fa-fw"></i> License
                                        {/*<span className="pull-right text-muted small">4 min</span>*/}
                                    </div>
                                </a>
                            </li>
                            <li className="divider"></li>
                            <li>
                                <a href="/ppolicy">
                                    <div>
                                        <i className="fa fa-upload fa-fw"></i> Privacy Policy
                                        {/*<span className="pull-right text-muted small">4 min</span>*/}
                                    </div>
                                </a>
                            </li>
                            <li className="divider"></li>
                            {/*<li>*/}
                            {/*<a className="text-center" href="#">*/}
                            {/*<strong>See All Alerts</strong>*/}
                            {/*<i className="fa fa-angle-right"></i>*/}
                            {/*</a>*/}
                            {/*</li>*/}
                        </ul>

                    </li>

                </ul>


                <ul className="nav navbar-top-links navbar-right">
                    {button}
                </ul>
            </div>
        );
    }
}


export default NavTop;