This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
GeonodeDebug.jsx
69 lines (68 loc) · 1.87 KB
/
GeonodeDebug.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
import React from 'react';
import ReactDOM from 'react-dom';
import GeoNodeViewer from './geonode.jsx';
import enMessages from 'boundless-sdk/locale/en.js';
import {IntlProvider} from 'react-intl';
import 'whatwg-fetch';
class GeoNodeViewerDebug extends React.Component {
constructor(props) {
super(props);
this.state = { config: this.props.config };
this.config = JSON.stringify(this.props.config);
const qry = this.uriVars();
if(qry.config) {
this.fetchConfigFromUrl(this.proxyUrl(qry.config));
this.configUrl = qry.config;
} else {
this.configUrl = '';
}
}
proxyUrl(url) {
return ('https://cors-anywhere.herokuapp.com/'+url);
}
uriVars(str) {
let vars = {};
str = str || window.location.href;
var hashes = str.slice(str.indexOf('?') + 1).split('&');
for(var i=0,len=hashes.length;i<len;i++){
var hash = hashes[i].split('=');
vars[hash[0]] = decodeURIComponent(hash[1]);
}
return vars;
}
fetchConfigFromUrl(url) {
fetch(url).then((response) => {
if(response.status == 200) {
return response.json();
}
}).then((json) => {
if(json) {
this.setState( { config: json});
}
});
}
configUrlChange(config) {
this.configUrl = config;
this.fetchConfigFromUrl(this.proxyUrl(config));
window.location.search = '?config='+config;
}
render() {
return (
<div>
<div id="debug">
<label htmlFor="debug">Debug URL</label>
<input
type="text"
value={this.configUrl}
onChange={(event) => { this.configUrlChange(event.target.value)}}
/>
</div>
<GeoNodeViewer config={this.state.config} proxy='http://cors-anywhere.cfapps.io/'/>
</div>
)
}
}
GeoNodeViewer.props = {
config: React.PropTypes.object.isRequired
};
export default GeoNodeViewerDebug;