-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admin.jsx
165 lines (159 loc) · 4.38 KB
/
Admin.jsx
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import React, { Component } from "react";
import { Route, Switch } from "react-router-dom";
import NotificationSystem from "react-notification-system";
import AdminNavbar from "components/Navbars/AdminNavbar";
import Footer from "components/Footer/Footer";
import Sidebar from "components/Sidebar/Sidebar";
import FixedPlugin from "components/FixedPlugin/FixedPlugin.jsx";
import { style } from "variables/Variables.jsx";
import routes from "routes.js";
import image from "assets/img/sidebar-3.jpg";
import sidebar from "assets/img/sidebar-3.jpg";
class Admin extends Component {
constructor(props) {
super(props);
this.state = {
_notificationSystem: null,
image: image,
color: "black",
hasImage: true,
fixedClasses: "dropdown show-dropdown open"
};
}
handleNotificationClick = position => {
var color = Math.floor(Math.random() * 4 + 1);
var level;
switch (color) {
case 1:
level = "success";
break;
case 2:
level = "warning";
break;
case 3:
level = "error";
break;
case 4:
level = "info";
break;
default:
break;
}
};
getRoutes = routes => {
return routes.map((prop, key) => {
if (prop.layout === "/admin") {
return (
<Route
path={prop.layout + prop.path}
render={props => (
<prop.component
{...props}
handleClick={this.handleNotificationClick}
/>
)}
key={key}
/>
);
} else {
return null;
}
});
};
getBrandText = path => {
for (let i = 0; i < routes.length; i++) {
if (
this.props.location.pathname.indexOf(
routes[i].layout + routes[i].path
) !== -1
) {
return routes[i].name;
}
}
return "Brand";
};
handleImageClick = image => {
this.setState({ image: image });
};
handleColorClick = color => {
this.setState({ color: color });
};
handleHasImage = hasImage => {
this.setState({ hasImage: hasImage });
};
handleFixedClick = () => {
if (this.state.fixedClasses === "dropdown") {
this.setState({ fixedClasses: "dropdown show-dropdown open" });
} else {
this.setState({ fixedClasses: "dropdown" });
}
};
componentDidMount() {
this.setState({ _notificationSystem: this.refs.notificationSystem });
var _notificationSystem = this.refs.notificationSystem;
var color = Math.floor(Math.random() * 4 + 1);
var level;
switch (color) {
case 1:
level = "success";
break;
case 2:
level = "warning";
break;
case 3:
level = "error";
break;
case 4:
level = "info";
break;
default:
break;
}
}
componentDidUpdate(e) {
if (
window.innerWidth < 993 &&
e.history.location.pathname !== e.location.pathname &&
document.documentElement.className.indexOf("nav-open") !== -1
) {
document.documentElement.classList.toggle("nav-open");
}
if (e.history.action === "PUSH") {
document.documentElement.scrollTop = 0;
document.scrollingElement.scrollTop = 0;
this.refs.mainPanel.scrollTop = 0;
}
}
render() {
const sidebarBackground = {
backgroundImage: "url(" + this.props.image + ")"
};
return (
<div className="wrapper">
<NotificationSystem ref="notificationSystem" style={style} />
<Sidebar {...this.props} routes={routes} image={this.state.image}
color={this.state.color}
hasImage={this.state.hasImage}/>
<div id="main-panel" className="main-panel" ref="mainPanel">
<AdminNavbar
{...this.props}
brandText={this.getBrandText(this.props.location.pathname)}
/>
<Switch>{this.getRoutes(routes)}</Switch>
<Footer />
<FixedPlugin
handleImageClick={this.handleImageClick}
handleColorClick={this.handleColorClick}
handleHasImage={this.handleHasImage}
bgColor={this.state["color"]}
bgImage={this.state["image"]}
mini={this.state["mini"]}
handleFixedClick={this.handleFixedClick}
fixedClasses={this.state.fixedClasses}
/>
</div>
</div>
);
}
}
export default Admin;