2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
23 import React from 'react'
24 import Select from 'react-select';
25 import Button from 'react-bootstrap/Button';
26 import Modal from 'react-bootstrap/Modal';
27 import Form from 'react-bootstrap/Form';
28 import Row from 'react-bootstrap/Row';
29 import Col from 'react-bootstrap/Col';
30 import FormCheck from 'react-bootstrap/FormCheck'
31 import styled from 'styled-components';
32 import LoopService from '../../../api/LoopService';
33 import SvgGenerator from '../../loop_viewer/svg/SvgGenerator';
34 import LoopCache from '../../../api/LoopCache';
36 const ModalStyled = styled(Modal)`
37 background-color: transparent;
39 const CheckBoxStyled = styled(FormCheck.Input)`
43 export default class OpenLoopModal extends React.Component {
44 constructor(props, context) {
45 super(props, context);
47 this.getLoopNames = this.getLoopNames.bind(this);
48 this.handleOpen = this.handleOpen.bind(this);
49 this.handleClose = this.handleClose.bind(this);
50 this.handleDropDownListChange = this.handleDropDownListChange.bind(this);
51 this.renderSvg = this.renderSvg.bind(this);
52 this.showReadOnly = props.showReadOnly !== undefined ? props.showReadOnly : true;
57 loopCacheOpened: new LoopCache({})
61 componentWillMount() {
66 this.setState({ show: false });
67 this.props.history.push('/');
70 handleDropDownListChange(e) {
71 LoopService.getLoop(e.value).then(loop => {
73 chosenLoopName: e.value,
74 loopCacheOpened: new LoopCache(loop)
80 LoopService.getLoopNames().then(loopNames => {
81 if (Object.entries(loopNames).length !== 0) {
82 const loopOptions = loopNames.filter(loopName => loopName!=='undefined').map((loopName) => { return { label: loopName, value: loopName } });
83 this.setState({ loopNames: loopOptions })
89 console.info("Loop " + this.state.chosenLoopName + " is chosen");
91 this.props.loadLoopFunction(this.state.chosenLoopName);
96 <SvgGenerator loopCache={this.state.loopCacheOpened} clickable={false} generatedFrom={SvgGenerator.GENERATED_FROM_INSTANCE}/>
102 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false} >
103 <Modal.Header closeButton>
104 <Modal.Title>Open Model</Modal.Title>
107 <Form.Group as={Row} controlId="formPlaintextEmail">
108 <Form.Label column sm="2">Model Name:</Form.Label>
110 <Select onChange={this.handleDropDownListChange}
111 options={this.state.loopNames} />
114 <Form.Group as={Row} style={{alignItems: 'center'}} controlId="formSvgPreview">
115 <Form.Label column sm="2">Model Preview:</Form.Label>
120 {this.showReadOnly === true ?
121 <Form.Group as={Row} controlId="formBasicCheckbox">
123 <FormCheck.Label>Read Only Mode:</FormCheck.Label>
124 <CheckBoxStyled style={{marginLeft: '3.5em'}} type="checkbox" />
130 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
131 <Button variant="primary" type="submit" onClick={this.handleOpen}>Open</Button>