]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/components/SentimentAnalysis.js
Remove headers
[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 import {Button, Heading, Form} from "react-bulma-components/full";
7
8 class SentimentAnalysis extends Component {
9     constructor(props, context) {
10         super(props, context);
11         this.state = {
12             terms: new Map().set(0, ''),
13             nextTermId: 1,
14             pdfLink: null,
15         };
16         this.camundaService = new CamundaService();
17         this.handleSubmit = this.handleSubmit.bind(this);
18         this.handleTermChange = this.handleTermChange.bind(this);
19         this.handleAddTerm = this.handleAddTerm.bind(this);
20         this.handleRemoveTerm = this.handleRemoveTerm.bind(this);
21         this.addEmptyTerm = this.addEmptyTerm.bind(this);
22         this.emptyTerms = this.emptyTerms.bind(this);
23         this.getNonEmptyTerms = this.getNonEmptyTerms.bind(this);
24         this.createPdf = this.createPdf.bind(this);
25     }
26
27     handleSubmit(event) {
28         event.preventDefault();
29         const target = event.target;
30         console.log(target);
31         const terms = this.state.terms;
32         terms.forEach((term) => {
33             console.log(term);
34         });
35         this.createPdf();
36         this.emptyTerms();
37     }
38
39     handleTermChange(id, value) {
40         const terms = this.state.terms;
41         this.setState({
42             terms: terms.set(id, value),
43         });
44     }
45
46     handleAddTerm(event) {
47         this.addEmptyTerm();
48     }
49
50     handleRemoveTerm(id) {
51         const terms = this.state.terms;
52         this.setState({
53             terms: terms.delete(id),
54         });
55     }
56
57     addEmptyTerm() {
58         const terms = this.state.terms;
59         const termId = this.state.nextTermId;
60         this.setState({
61             terms: terms.set(termId, ''),
62             nextTermId: termId + 1,
63         });
64     }
65
66     emptyTerms() {
67         this.setState({
68             terms: new Map().set(0, ''),
69             nextTermId: 1,
70         });
71     }
72
73     getNonEmptyTerms() {
74         const terms = this.state.terms;
75         return terms.filter((value, key) => value.trim() !== '');
76     }
77
78     createPdf() {
79         const terms = this.getNonEmptyTerms();
80         if (terms.size > 0) {
81             this.camundaService.submitPdfForm(terms);
82         }
83     }
84
85     render() {
86         return (
87             <div className="sentiment-analysis">
88                 <form onSubmit={this.handleSubmit}>
89                     <Heading size={3} Style="margin-top:1em">Search Terms: </Heading>
90                     <SearchTermsInput terms={this.state.terms}
91                                       onTermChange={this.handleTermChange}
92                                       onAddTerm={this.handleAddTerm}
93                                       onRemoveTerm={this.handleRemoveTerm}/>
94                     <Form.Field kind="group">
95                         <p className="control">
96                             <Button color="info" type="submit" value="Submit">Submit</Button>
97                         </p>
98                         <p className="control">
99                             <Button value="Reset" onClick={this.emptyTerms}>Reset</Button>
100                         </p>
101                     </Form.Field>
102                 </form>
103                 <PdfReport pdfLink={this.state.pdfLink}/>
104             </div>
105         );
106     }
107 }
108
109 SentimentAnalysis.propTypes = {};
110
111 export default SentimentAnalysis;