1- import React from ' react' ;
2- import _ from ' lodash' ;
3- import Select from ' react-select' ;
1+ import React from " react" ;
2+ import _ from " lodash" ;
3+ import Select from " react-select" ;
44
5- import { pyWpsUrl , version } from '../../config' ;
6- import ProcessForm from '../ProcessForm/ProcessForm' ;
5+ import { wpsServerUrl , version } from "../../config" ;
6+ import ProcessForm from "../ProcessForm" ;
7+ import { GetInputGenerator , CreateClientInstance , GetOutputGenerator } from "../../utils/wpsjs" ;
78
89export default class ToolsScreen extends React . Component {
9- constructor ( ) {
10+ constructor ( ) {
1011 super ( ) ;
1112
1213 this . state = {
1314 processes : [ ] ,
14- processInputs : [ ] ,
15+ processInputs : [ ]
1516 } ;
1617
1718 this . getCapabilitiesCallback = this . getCapabilitiesCallback . bind ( this ) ;
@@ -21,66 +22,79 @@ export default class ToolsScreen extends React.Component {
2122 this . handleExecuteResponse = this . handleExecuteResponse . bind ( this ) ;
2223 }
2324
24- componentDidMount ( ) {
25- this . wps = new window . WpsService ( {
26- url : pyWpsUrl ,
27- version : version ,
28- } ) ;
25+ componentDidMount ( ) {
26+ this . wps = CreateClientInstance ( wpsServerUrl , version ) ;
2927
3028 this . wps . getCapabilities_GET ( this . getCapabilitiesCallback ) ;
3129 }
3230
33- getCapabilitiesCallback ( response ) {
31+ getCapabilitiesCallback ( response ) {
3432 const capabilities = response . capabilities ;
35- this . setState ( { processes : capabilities . processes } ) ;
33+ this . setState ( { processes : capabilities . processes } ) ;
3634 }
3735
38- handleProcessChange ( selected ) {
36+ handleProcessChange ( selected ) {
3937 this . wps . describeProcess_GET ( this . getDescribeCallback , selected . value ) ;
4038 }
4139
42- getDescribeCallback ( response ) {
43- this . setState ( { selectedProcess : response . processOffering . process } ) ;
40+ getDescribeCallback ( response ) {
41+ this . setState ( { selectedProcess : response . processOffering . process } ) ;
4442 }
4543
46- handleExecuteProcess ( inputs ) {
47- const outputGenerator = new window . OutputGenerator ( ) ;
44+ handleExecuteProcess ( inputs ) {
45+ const outputGenerator = GetOutputGenerator ( ) ;
4846 const outputs = [ ] ;
4947 const output = this . state . selectedProcess . outputs [ 0 ] ;
50- if ( output . hasOwnProperty ( 'complexData' ) ) {
51- const geoJsonOutputIndex = _ . findIndex ( output . complexData . formats ,
52- [ 'mimeType' , 'application/vnd.geo+json' ] ) ;
48+ if ( output . hasOwnProperty ( "complexData" ) ) {
49+ const geoJsonOutputIndex = _ . findIndex ( output . complexData . formats , [
50+ "mimeType" ,
51+ "application/vnd.geo+json"
52+ ] ) ;
5353 const geoJsonOutput = output . complexData . formats [ geoJsonOutputIndex ] ;
5454 outputs . push (
55- outputGenerator . createComplexOutput_WPS_2_0 ( output . identifier ,
56- geoJsonOutput . mimeType , geoJsonOutput . schema , geoJsonOutput . encoding ,
57- 'value' ) ) ;
58- } else if ( output . hasOwnProperty ( 'literalData' ) ) {
59-
55+ outputGenerator . createComplexOutput_WPS_1_0 (
56+ output . identifier ,
57+ geoJsonOutput . mimeType ,
58+ geoJsonOutput . schema ,
59+ geoJsonOutput . encoding ,
60+ "value"
61+ )
62+ ) ;
63+ } else if ( output . hasOwnProperty ( "literalData" ) ) {
6064 }
61- this . wps . execute ( this . handleExecuteResponse ,
62- this . state . selectedProcess . identifier , 'document' , 'sync' , false , inputs ,
63- outputs ) ;
65+ this . wps . execute (
66+ this . handleExecuteResponse ,
67+ this . state . selectedProcess . identifier ,
68+ "document" ,
69+ "sync" ,
70+ false ,
71+ inputs ,
72+ outputs
73+ ) ;
6474 }
6575
66- handleExecuteResponse ( value ) {
76+ handleExecuteResponse ( value ) {
6777 console . log ( value ) ;
6878 }
6979
70- render ( ) {
71- const { processes, selectedProcess} = this . state ;
80+ render ( ) {
81+ const { processes, selectedProcess } = this . state ;
7282 return (
73- < div style = { { margin : '2.5%' } } >
74- < Select onChange = { this . handleProcessChange }
75- options = { processes . map ( process => ( {
76- value : process . identifier ,
77- label : process . identifier ,
78- } ) ) } />
79- { selectedProcess
80- ? < ProcessForm inputs = { selectedProcess . inputs }
81- handleOnSubmit = { this . handleExecuteProcess } />
82- : null }
83+ < div style = { { margin : "2.5%" } } >
84+ < Select
85+ onChange = { this . handleProcessChange }
86+ options = { processes . map ( process => ( {
87+ value : process . identifier ,
88+ label : process . identifier
89+ } ) ) }
90+ />
91+ { selectedProcess ? (
92+ < ProcessForm
93+ inputs = { selectedProcess . inputs }
94+ handleOnSubmit = { this . handleExecuteProcess }
95+ />
96+ ) : null }
8397 </ div >
8498 ) ;
8599 }
86- }
100+ }
0 commit comments