blob: 0bf71580a4e3178590c68fa5d9af05567bca48a6 [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';
sebdet493c3832019-07-15 17:26:18 +020032import LoopService from '../../../api/LoopService';
xuegaof248df62019-07-15 15:16:18 +020033
34const ModalStyled = styled(Modal)`
35 background-color: transparent;
36`
37const CheckBoxStyled = styled(FormCheck.Input)`
38 margin-left:3rem;
39`
40
sebdet493c3832019-07-15 17:26:18 +020041export default class OpenLoopModal extends React.Component {
xuegaof248df62019-07-15 15:16:18 +020042 constructor(props, context) {
43 super(props, context);
44
45 this.getLoopNames = this.getLoopNames.bind(this);
sebdet493c3832019-07-15 17:26:18 +020046 this.handleOpen = this.handleOpen.bind(this);
47 this.getModel = this.getModel.bind(this);
xuegaof248df62019-07-15 15:16:18 +020048 this.handleClose = this.handleClose.bind(this);
49 this.handleDropdownListChange = this.handleDropdownListChange.bind(this);
50 this.state = {
51 show: true,
52 chosenLoopName: '',
sebdet493c3832019-07-15 17:26:18 +020053 loopNames: []
xuegaof248df62019-07-15 15:16:18 +020054 };
55 }
sebdet493c3832019-07-15 17:26:18 +020056
sebdet2dacb9b2019-07-17 13:48:44 +020057 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +020058 this.getLoopNames();
59 }
60
xuegaof248df62019-07-15 15:16:18 +020061 handleClose() {
62 this.setState({ show: false });
sebdet493c3832019-07-15 17:26:18 +020063 this.props.history.push('/');
xuegaof248df62019-07-15 15:16:18 +020064 }
sebdet493c3832019-07-15 17:26:18 +020065
xuegaof248df62019-07-15 15:16:18 +020066 handleDropdownListChange(e) {
sebdet493c3832019-07-15 17:26:18 +020067 this.setState({ chosenLoopName: e.value });
xuegaof248df62019-07-15 15:16:18 +020068 }
sebdet493c3832019-07-15 17:26:18 +020069
xuegaof248df62019-07-15 15:16:18 +020070 getLoopNames() {
71 LoopService.getLoopNames().then(loopNames => {
sebdet493c3832019-07-15 17:26:18 +020072 const loopOptions = loopNames.map((loopName) => { return { label: loopName, value: loopName } });
73 this.setState({ loopNames: loopOptions })
xuegaof248df62019-07-15 15:16:18 +020074 });
75 }
sebdet493c3832019-07-15 17:26:18 +020076
77 getModel() {
78 LoopService.getLoop(this.state.chosenLoopName).then(loop => {
79 console.debug("Settingloop cache with json");
80 this.props.updateLoopCacheFunction(loop);
81 });
82 }
83
84 handleOpen() {
85 console.info("Loop " + this.state.chosenLoopName + " is chosen");
xuegaof248df62019-07-15 15:16:18 +020086 this.setState({ show: false });
87 this.props.history.push('/');
sebdet493c3832019-07-15 17:26:18 +020088 this.getModel();
xuegaof248df62019-07-15 15:16:18 +020089 }
sebdet493c3832019-07-15 17:26:18 +020090
xuegaof248df62019-07-15 15:16:18 +020091 render() {
92 return (
93 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
94 <Modal.Header closeButton>
95 <Modal.Title>Open Model</Modal.Title>
96 </Modal.Header>
97 <Modal.Body>
98 <Form.Group as={Row} controlId="formPlaintextEmail">
99 <Form.Label column sm="2">Model Name</Form.Label>
100 <Col sm="10">
sebdet493c3832019-07-15 17:26:18 +0200101 <Select onChange={this.handleDropdownListChange} options={this.state.loopNames} />
xuegaof248df62019-07-15 15:16:18 +0200102 </Col>
103 </Form.Group>
104 <Form.Group controlId="formBasicChecbox">
sebdet493c3832019-07-15 17:26:18 +0200105 <Form.Check>
xuegaof248df62019-07-15 15:16:18 +0200106 <FormCheck.Label>Read Only</FormCheck.Label>
107 <CheckBoxStyled type="checkbox" />
108 </Form.Check>
sebdet493c3832019-07-15 17:26:18 +0200109 </Form.Group>
xuegaof248df62019-07-15 15:16:18 +0200110 </Modal.Body>
111 <Modal.Footer>
sebdet493c3832019-07-15 17:26:18 +0200112 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
sebdet5f6c1782019-07-18 15:23:13 +0200113 <Button variant="primary" type="submit" onClick={this.handleOpen}>Open</Button>
xuegaof248df62019-07-15 15:16:18 +0200114 </Modal.Footer>
115 </ModalStyled>
116
117 );
118 }
119}