-
Notifications
You must be signed in to change notification settings - Fork 18
/
shape-visual.js
105 lines (100 loc) · 3.85 KB
/
shape-visual.js
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
import React,{Component} from 'react';
import GMap from './gmap';
import { uploadFiles, uploadSites} from './requests'
import { withRouter, Redirect} from 'react-router-dom'
import './stylesheets/visual.css'
class ShapeView extends Component{
constructor(props){
super(props);
this.state={
redirect: false
}
this.onError=this.onError.bind(this);
this.onNext=this.onNext.bind(this);
}
async onNext(e){
try{
let files= this.props.fileList.fileList;
let val= [];
Promise.all([
uploadFiles(files.cultivars, "cultivars", ""),
uploadFiles(files.experiments, "experiments", "guestuser"),
uploadFiles(files.treatments, "treatments", "guestuser"),
uploadFiles(files.citations, "citations", "guestuser"),
])
.then((values)=> val.push(values[0],values[1],values[2],values[3]))
.then(()=> Promise.all([
uploadFiles(files.sites_cultivars, "sites_cultivars", ""),
uploadFiles(files.experiments_sites, "experiments_sites", ""),
uploadFiles(files.experiments_treatments, "experiments_treatments", ""),
uploadFiles(files.citations_sites, "citations_sites", "")
]))
.then((values)=>{
val.push(values[0],values[1],values[2],values[3])
let files=['cultivars', 'experiments', 'treatments', 'citations', 'sites_cultivars','experiments_sites', 'experiments_treatments', 'citations_sites'];
return val.map((data,i)=>{
if(!data.hasOwnProperty('Lines Inserted')){
if(data === 410)
return `410 while uploading ${files[i]}`;
else
return `${data['Message']} while uploading ${files[i]}`;
}
return `success`;
}).filter((data)=>{
return data !== 'success';
})
})
.then((err_list)=>{
if(err_list.length>0){
this.setState({
redirect: true,
path: "/error",
message: err_list
});
}
else{
this.setState({
redirect: true,
path: "/success",
message: [""]
});
}
})
}
catch(err){
this.setState({
redirect: true,
path: "/error",
message: [err.message]
});
}
}
onError(e){
return this.props.history.push("/");
}
render(){
if (this.state.redirect){
return <Redirect
to= {{
pathname: this.state.path,
state: { message: this.state.message }
}}/>;
}
return(
<div className="shape-view">
<div className="heading">Confirm the view of your shapefile ?</div>
<div className="map">
<GMap file={this.props.fileList.fileList.shapefile} />
</div>
<div className="choice">
<div>Do you want to continue ?</div>
<div className="options">
<button className="danger ripple-danger" onClick={this.onError}>TRY AGAIN</button>
<button className="primary ripple-primary" onClick={this.onNext}>NEXT</button>
</div>
</div>
</div>
);
}
}
export default withRouter(ShapeView);