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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
import React from 'react';
import {hashHistory} from 'react-router'
import './index.css';
import {Link} from 'react-router-dom';
import UserInfoCard from 'component/userinfo-card/index.jsx'
import Record from 'service/record-service.jsx'
import PGUtil from 'util/util.jsx'
import User from 'service/user-service.jsx'
import PGConstant from 'util/constant.jsx'
const _user = new User();
const _util = new PGUtil();
const _record = new Record();
class FarmerApply extends React.Component {
constructor(props) {
super(props);
this.state = {
username: '',
machines:[],
userinfo: {}
}
this.loadUserMachineManageList = this.loadUserMachineManageList.bind(this);
}
componentDidMount(){
let user = _util.getStorage('userInfo')
let _this = this
this.setState({
username: user.username,
},()=>{
_this.loadUserPortalInfo()
_this.loadUserMachineManageList();
});
console.log(user.token)
}
loadUserPortalInfo(){
let username = this.state.username
_user.getUserPortalInfo(username).then(res => {
this.setState({
userinfo: res,
});
}, errMsg => {
_util.errorTips('Please make sure no fields are empty.');
});
}
loadUserMachineManageList(page=1){
let listParam = {};
listParam.page = page;
listParam.machine_owner__username = this.state.username;
_user.getUserMachineManageList(listParam).then(res => {
this.setState({
machines: res.results,
total: res.count,
});
}, errMsg => {
_util.errorTips(errMsg);
});
}
onLogout(){
_util.removeStorage('userInfo');
// this.props.history.push('/login')
// hashHistory.push('/login')
window.location.href = '/';
}
onInputChange(e) {
let inputValue = e.target.value,
inputName = e.target.name;
this.setState({
[inputName]: inputValue
});
}
onInputKeyUp(e) {
if (e.keyCode === 13) {
this.onSubmit();
}
}
onSubmit() {
// alert(1)
let machineInfo = {
os_name: this.state.os_name,
os_version: this.state.os_version,
comp_name: this.state.comp_name,
comp_version: this.state.comp_version,
machine_owner:this.state.username
}
let checkResult = true
// check success
if (checkResult) {
_user.farmerApply(machineInfo).then((res) => {
// console.dir(res)
alert('add machine success!')
//hashHistory.push('/portal')
// window.location.href = this.state.redirect;
}, (err) => {
// console.log(err)
if (PGConstant.AuthorizedErrorCode === err) {
_util.errorTips('username or password is mistake!');
}else{
_util.errorTips('login fail');
}
});
}
// check failure
else {
_util.errorTips(checkResult.msg);
}
}
render() {
let show = this.state.isLoading ? "none" : "block";
let style = {
display: show
};
return (
<div className="container-fluid detail-container">
<div className="col-md-3">
{/*<Segment vertical>Farmer Info</Segment>*/}
<UserInfoCard userinfo={this.state.userinfo}></UserInfoCard>
<div className="panel panel-default panel-blue">
<div className="panel-heading">
<h3 className="panel-title">
<i className="fa fa-bookmark"></i> Shortcuts
</h3>
</div>
<div className="list-group">
<Link target='_blank' to="farmerApply/" className="list-group-item">
<i className="fa fa-globe fa-fw"></i> Add a New Mchine
</Link>
<a onClick={() => {this.onLogout()}} className="list-group-item">
<i className="fa fa-arrow-left fa-fw"></i> Logout
</a>
</div>
</div>
</div>
<div className="col-md-9">
<div className="record-title">
<h2 >Welcome Back, {this.state.username}</h2>
</div>
<div className="panel panel-default">
<div className="panel-heading">
Apply New Machines
</div>
<div className="panel-body">
<div className="row">
{/*<!-- /.col-lg-6 (nested) -->*/}
<div className="col-lg-12">
{/*<h4>Login Form</h4>*/}
<form role="form">
<div className="form-group input-group">
{/*<label className="control-label" for="inputLogin"> login input</label>*/}
<span class="input-group-addon">system name</span>
<input type="text" className="form-control" id="inputOSName"
placeholder="etc.Debian,Ubuntu"
name="os_name"
onKeyUp={e => this.onInputKeyUp(e)}
onChange={e => this.onInputChange(e)}/>
</div>
<div className="form-group input-group">
<span class="input-group-addon">system version</span>
<input type="text" className="form-control" id="inputOSVersion"
name="os_version"
placeholder="etc.9,14.4" onKeyUp={e => this.onInputKeyUp(e)}
onChange={e => this.onInputChange(e)}/>
</div>
<div className="form-group input-group">
<span class="input-group-addon">arch name</span>
<input type="text" className="form-control" id="inputCampName"
name="comp_name"
placeholder="etc.x86" onKeyUp={e => this.onInputKeyUp(e)}
onChange={e => this.onInputChange(e)}/>
</div>
<div className="form-group input-group">
<span class="input-group-addon">arch version</span>
<input type="text" className="form-control" id="inputCampVersion"
name="comp_version"
placeholder="etc.64" onKeyUp={e => this.onInputKeyUp(e)}
onChange={e => this.onInputChange(e)}/>
</div>
<button type="button" className="btn btn-primary" onClick={e => {this.onSubmit(e)}}>Submit</button>
</form>
</div>
{/*<!-- /.col-lg-6 (nested) -->*/}
</div>
{/*<!-- /.row (nested) -->*/}
</div>
{/*<!-- /.panel-body -->*/}
</div>
</div>
</div>
)
}
}
export default FarmerApply;
|