blob: 6dc04d19c34652cedf61e2c5fd085c622b504dc4 [file] [log] [blame]
xuegaof248df62019-07-15 15:16:18 +02001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END============================================
19 * ===================================================================
20 *
21 */
22
23import React from 'react'
24import Select from 'react-select';
25import Button from 'react-bootstrap/Button';
26import Modal from 'react-bootstrap/Modal';
27import Form from 'react-bootstrap/Form';
28import Row from 'react-bootstrap/Row';
29import Col from 'react-bootstrap/Col';
30import FormCheck from 'react-bootstrap/FormCheck'
31import styled from 'styled-components';
32import LoopService from '../../api/LoopService';
33import LoopCache from '../../api/LoopCache';
34
35const ModalStyled = styled(Modal)`
36 background-color: transparent;
37`
38const CheckBoxStyled = styled(FormCheck.Input)`
39 margin-left:3rem;
40`
41
42export default class LoopModal extends React.Component {
43 constructor(props, context) {
44 super(props, context);
45
46 this.getLoopNames = this.getLoopNames.bind(this);
47 this.openModel = this.openModel.bind(this);
48 this.handleClose = this.handleClose.bind(this);
49 this.handleDropdownListChange = this.handleDropdownListChange.bind(this);
50 this.state = {
51 show: true,
52 chosenLoopName: '',
53 loopNames:[]
54 };
55 }
56 componentDidMount() {
57 this.getLoopNames();
58 }
59 handleClose() {
60 this.setState({ show: false });
61 this.props.history.push('/');
62 }
63 handleDropdownListChange(e) {
64 this.setState({ chosenLoopName: e.value});
65 }
66 getLoopNames() {
67 LoopService.getLoopNames().then(loopNames => {
68 const loopOptions = loopNames.map((loopName) => { return {label: loopName, value: loopName}});
69 this.setState({loopNames:loopOptions})
70 });
71 }
72 openModel() {
73 this.setState({ show: false });
74 this.props.history.push('/');
75 // Open selected model
76 console.log("Loop " + this.state.chosenLoopName + " is chosen");
77 LoopService.getLoop(this.state.chosenLoopName).then(loop => {
78 console.log("Initialize the loop cache");
79 new LoopCache(loop);
80 });
81 }
82 render() {
83 return (
84 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
85 <Modal.Header closeButton>
86 <Modal.Title>Open Model</Modal.Title>
87 </Modal.Header>
88 <Modal.Body>
89 <Form.Group as={Row} controlId="formPlaintextEmail">
90 <Form.Label column sm="2">Model Name</Form.Label>
91 <Col sm="10">
92 <Select onChange={this.handleDropdownListChange} options={ this.state.loopNames } />
93 </Col>
94 </Form.Group>
95 <Form.Group controlId="formBasicChecbox">
96 <Form.Check>
97 <FormCheck.Label>Read Only</FormCheck.Label>
98 <CheckBoxStyled type="checkbox" />
99 </Form.Check>
100 </Form.Group>
101 </Modal.Body>
102 <Modal.Footer>
103 <Button variant="secondary" type="null" onClick={this.handleClose}>Cacel</Button>
104 <Button variant="primary" type="submit" onClick={this.openModel}>OK</Button>
105 </Modal.Footer>
106 </ModalStyled>
107
108 );
109 }
110}