1
1
import React from 'react' ;
2
2
import './App.css' ;
3
- import { Modal , Button , CardDeck , Card , Form } from 'react-bootstrap' ;
3
+ import { Modal , Button , CardDeck , Card , Form , Alert } from 'react-bootstrap' ;
4
4
import axios from 'axios' ;
5
5
6
6
const backColor = {
@@ -15,46 +15,80 @@ class App extends React.Component {
15
15
model : - 1 ,
16
16
data : 'No hay informacion' ,
17
17
dznfile : null ,
18
+ escenas : [ ] ,
18
19
}
19
20
this . dznfile = this . dznfile . bind ( this ) ;
20
21
this . execute = this . execute . bind ( this ) ;
22
+ this . formatdata = this . formatdata . bind ( this ) ;
23
+ }
24
+ formatdata = ( text ) => {
25
+ this . setState ( { data : "" } ) ;
26
+ var result = "" ;
27
+ var all = text . split ( "\n" ) ;
28
+ if ( all [ 0 ] . includes ( "ACTORES =" ) ) {
29
+ const actores = all [ 0 ] . split ( "," ) . length ;
30
+ result += "Actores: " + actores + ", " ;
31
+ /*var index = all.indexOf(all.find(res => res.includes("Escenas =")));
32
+ for (var i=index; i<index+actores; i++ ){
33
+ result += all[i] + "\n";
34
+ } */
35
+ var disponibilidad = all . find ( res => res . includes ( "Disponibilidad =" ) ) ;
36
+ var evitar = all . find ( res => res . includes ( "Evitar =" ) ) ;
37
+ if ( ( typeof disponibilidad !== "undefined" ) && ( typeof evitar !== "undefined" ) ) {
38
+ result += "Deberias usar el Modelo 2\n" ;
39
+ } else {
40
+ result += "Deberias usar el Modelo 1\n" ;
41
+ }
42
+ } else {
43
+ result = "No hay información" ;
44
+ }
45
+ console . log ( result ) ;
46
+ return result ;
21
47
}
22
48
dznfile = ( event ) => {
23
49
event . preventDefault ( ) ;
24
50
let file = event . target . files [ 0 ] ;
25
51
this . setState ( { 'dznfile' : file } )
52
+ const reader = new FileReader ( ) ;
53
+ reader . onload = async ( e ) => {
54
+ const text = reader . result ;
55
+ const inf = this . formatdata ( text ) ;
56
+ console . log ( inf ) ;
57
+ this . setState ( { data : inf } ) ;
58
+ } ;
59
+ reader . readAsText ( event . target . files [ 0 ] ) ;
26
60
27
61
}
28
62
execute = ( ) => {
29
- if ( this . state . model === - 1 ) {
30
- alert ( "No se ha escogido un modelo" )
63
+ if ( this . state . model === - 1 || this . state . dznfile === null ) {
64
+ alert ( "No se ha escogido un modelo o un archivo " )
31
65
} else {
32
66
const data = new FormData ( ) ;
33
67
data . append ( 'dznfile' , this . state . dznfile ) ;
34
68
axios ( {
35
69
url : 'http://localhost:5000/dzn' ,
36
70
method : 'POST' ,
37
71
data : data ,
38
- params : { model : this . state . model } ,
72
+ params : { model : this . state . model } ,
39
73
config : { headers : { 'Content-Type' : 'multipart/form-data' } }
40
74
} ) . then ( ( response ) => {
41
- if ( response . data === "" ) {
75
+ if ( response . data === "" ) {
42
76
alert ( "Se ha producido un error. Es posible que la causa sea la selección de un modelo incorrecto" ) ;
43
- } else {
44
- this . setState ( { r : response . data } )
45
- } }
77
+ } else {
78
+ const result = response . data ;
79
+ this . setState ( { r : result . substring ( 0 , result . length - 22 ) } ) ;
80
+ }
81
+ }
46
82
) . catch ( ( error ) => alert ( "Se ha producido un error. Es posible que la causa sea la selección de un modelo incorrecto" ) )
47
83
}
48
84
49
85
}
50
86
clean = ( event ) => {
51
87
event . preventDefault ( ) ;
52
- this . setState ( { r : '' , dznfile : null } ) ;
88
+ this . setState ( { r : '' , dznfile : null , model : - 1 , data : "No hay información" } ) ;
53
89
}
54
90
setModel = ( data ) => {
55
- console . log ( data )
56
91
this . setState ( { model : data } ) ;
57
- console . log ( this . state . model )
58
92
}
59
93
render ( ) {
60
94
return (
@@ -71,9 +105,8 @@ class App extends React.Component {
71
105
< Modal . Body >
72
106
< CardDeck >
73
107
< Card >
74
- < h5 > Carga tu archivo de dzn</ h5 >
108
+ < h5 > Carga tu archivo dzn</ h5 >
75
109
< input name = "dzn" type = "file" onChange = { this . dznfile } />
76
- { /*<p>{this.state.data}</p>*/ }
77
110
< Form . Check
78
111
type = "radio"
79
112
label = "Modelo 1"
@@ -88,9 +121,14 @@ class App extends React.Component {
88
121
id = "Modelo2"
89
122
onClick = { ( ) => this . setModel ( 1 ) }
90
123
/>
124
+ < br > </ br >
91
125
< Button onClick = { this . execute } variant = "primary" >
92
126
Enviar
93
- </ Button >
127
+ </ Button >
128
+
129
+ < Alert variant = { "info" } >
130
+ { this . state . data }
131
+ </ Alert >
94
132
</ Card >
95
133
< Card >
96
134
{ this . state . r }
0 commit comments