]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/components/SentimentAnalysis.js
Map port for website service in docker-compose file
[pub/jan/aic18.git] / service-website / src / components / SentimentAnalysis.js
1 import React, {Component} from "react";
2 import {Map} from "immutable";
3 import PdfReport from "./PdfReport";
4 import SearchTermsInput from "./SearchTermsInput";
5 import CamundaService from "../services/CamundaService";
6
7 class SentimentAnalysis extends Component {
8     constructor(props, context) {
9         super(props, context);
10         this.state = {
11             terms: new Map().set(0, ''),
12             nextTermId: 1,
13             pdfLink: null,
14         };
15         this.camundaService = new CamundaService();
16         this.handleSubmit = this.handleSubmit.bind(this);
17         this.handleTermChange = this.handleTermChange.bind(this);
18         this.handleAddTerm = this.handleAddTerm.bind(this);
19         this.handleRemoveTerm = this.handleRemoveTerm.bind(this);
20         this.addEmptyTerm = this.addEmptyTerm.bind(this);
21         this.emptyTerms = this.emptyTerms.bind(this);
22         this.createPdf = this.createPdf.bind(this);
23     }
24
25     handleSubmit(event) {
26         event.preventDefault();
27         const target = event.target;
28         console.log(target);
29         const terms = this.state.terms;
30         terms.forEach((term) => {
31             console.log(term);
32         });
33         this.createPdf();
34         this.emptyTerms();
35     }
36
37     handleTermChange(id, value) {
38         const terms = this.state.terms;
39         this.setState({
40             terms: terms.set(id, value),
41         });
42     }
43
44     handleAddTerm(event) {
45         this.addEmptyTerm();
46     }
47
48     handleRemoveTerm(id) {
49         const terms = this.state.terms;
50         this.setState({
51             terms: terms.delete(id),
52         });
53     }
54
55     addEmptyTerm() {
56         const terms = this.state.terms;
57         const termId = this.state.nextTermId;
58         this.setState({
59             terms: terms.set(termId, ''),
60             nextTermId: termId + 1,
61         });
62     }
63
64     emptyTerms() {
65         this.setState({
66             terms: new Map().set(0, ''),
67             nextTermId: 1,
68         });
69     }
70
71     createPdf() {
72         this.camundaService.submitPdfForm(null);
73     }
74
75     render() {
76         return (
77             <div className="sentiment-analysis">
78                 <form onSubmit={this.handleSubmit}>
79                     <label>Search Terms</label>
80                     <SearchTermsInput terms={this.state.terms}
81                                       onTermChange={this.handleTermChange}
82                                       onAddTerm={this.handleAddTerm}
83                                       onRemoveTerm={this.handleRemoveTerm}/>
84                     <input type="submit" value="Submit"/>
85                 </form>
86                 <PdfReport pdfLink={this.state.pdfLink}/>
87             </div>
88         );
89     }
90 }
91
92 SentimentAnalysis.propTypes = {};
93
94 export default SentimentAnalysis;