]> git.somenet.org - pub/jan/aic18.git/blob - service-website/src/components/SentimentAnalysis.js
Generate new yarn.lock
[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.createPdf = this.createPdf.bind(this);
24     }
25
26     handleSubmit(event) {
27         event.preventDefault();
28         const target = event.target;
29         console.log(target);
30         const terms = this.state.terms;
31         terms.forEach((term) => {
32             console.log(term);
33         });
34         this.createPdf();
35         this.emptyTerms();
36     }
37
38     handleTermChange(id, value) {
39         const terms = this.state.terms;
40         this.setState({
41             terms: terms.set(id, value),
42         });
43     }
44
45     handleAddTerm(event) {
46         this.addEmptyTerm();
47     }
48
49     handleRemoveTerm(id) {
50         const terms = this.state.terms;
51         this.setState({
52             terms: terms.delete(id),
53         });
54     }
55
56     addEmptyTerm() {
57         const terms = this.state.terms;
58         const termId = this.state.nextTermId;
59         this.setState({
60             terms: terms.set(termId, ''),
61             nextTermId: termId + 1,
62         });
63     }
64
65     emptyTerms() {
66         this.setState({
67             terms: new Map().set(0, ''),
68             nextTermId: 1,
69         });
70     }
71
72     createPdf() {
73         this.camundaService.submitPdfForm(null);
74     }
75
76     render() {
77         return (
78             <div className="sentiment-analysis">
79                 <form onSubmit={this.handleSubmit}>
80                     <Heading size={3} Style="margin-top:1em">Search Terms: </Heading>
81                     <SearchTermsInput terms={this.state.terms}
82                                       onTermChange={this.handleTermChange}
83                                       onAddTerm={this.handleAddTerm}
84                                       onRemoveTerm={this.handleRemoveTerm}/>
85                     <Form.Field kind="group">
86                         <p className="control">
87                             <Button color="info" type="submit" value="Submit">Submit</Button>
88                         </p>
89                         <p className="control">
90                             <Button value="Reset" onClick={this.emptyTerms}>Reset</Button>
91                         </p>
92                     </Form.Field>
93                 </form>
94                 <PdfReport pdfLink={this.state.pdfLink}/>
95             </div>
96         );
97     }
98 }
99
100 SentimentAnalysis.propTypes = {};
101
102 export default SentimentAnalysis;