blob: 7c98fab4d6ebd66d0f7654540e94ee8687eb37fb [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`
jingjincs3173d552020-03-04 09:11:10 +010040const LoopViewSvgDivStyled = styled.div`
41 overflow: hidden;
42 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
43 border-color: ${props => (props.theme.loopViewerHeaderColor)};
44 margin-left: auto;
45 margin-right:auto;
46 text-align: center;
47`
xuegaof248df62019-07-15 15:16:18 +020048
sebdet493c3832019-07-15 17:26:18 +020049export default class OpenLoopModal extends React.Component {
xuegaof248df62019-07-15 15:16:18 +020050 constructor(props, context) {
51 super(props, context);
52
53 this.getLoopNames = this.getLoopNames.bind(this);
sebdet493c3832019-07-15 17:26:18 +020054 this.handleOpen = this.handleOpen.bind(this);
xuegaof248df62019-07-15 15:16:18 +020055 this.handleClose = this.handleClose.bind(this);
56 this.handleDropdownListChange = this.handleDropdownListChange.bind(this);
57 this.state = {
58 show: true,
59 chosenLoopName: '',
jingjincs3173d552020-03-04 09:11:10 +010060 loopNames: [],
61 content:''
xuegaof248df62019-07-15 15:16:18 +020062 };
63 }
sebdet493c3832019-07-15 17:26:18 +020064
sebdet2dacb9b2019-07-17 13:48:44 +020065 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +020066 this.getLoopNames();
67 }
68
xuegaof248df62019-07-15 15:16:18 +020069 handleClose() {
70 this.setState({ show: false });
sebdet493c3832019-07-15 17:26:18 +020071 this.props.history.push('/');
xuegaof248df62019-07-15 15:16:18 +020072 }
sebdet493c3832019-07-15 17:26:18 +020073
xuegaof248df62019-07-15 15:16:18 +020074 handleDropdownListChange(e) {
sebdet493c3832019-07-15 17:26:18 +020075 this.setState({ chosenLoopName: e.value });
jingjincs3173d552020-03-04 09:11:10 +010076 LoopService.getSvg(e.value).then(svgXml => {
77 if (svgXml.length !== 0) {
78 this.setState({ content: svgXml })
79 } else {
80 this.setState({ content: 'Error1' })
81 }
82 });
xuegaof248df62019-07-15 15:16:18 +020083 }
sebdet493c3832019-07-15 17:26:18 +020084
xuegaof248df62019-07-15 15:16:18 +020085 getLoopNames() {
86 LoopService.getLoopNames().then(loopNames => {
sebdetaa486be2020-02-18 02:00:11 -080087 if (Object.entries(loopNames).length !== 0) {
88 const loopOptions = loopNames.filter(loopName => loopName!=='undefined').map((loopName) => { return { label: loopName, value: loopName } });
89 this.setState({ loopNames: loopOptions })
jingjincs3173d552020-03-04 09:11:10 +010090
sebdetaa486be2020-02-18 02:00:11 -080091 }
jingjincs3173d552020-03-04 09:11:10 +010092
xuegaof248df62019-07-15 15:16:18 +020093 });
94 }
sebdet493c3832019-07-15 17:26:18 +020095
sebdet493c3832019-07-15 17:26:18 +020096 handleOpen() {
97 console.info("Loop " + this.state.chosenLoopName + " is chosen");
sebdetaa486be2020-02-18 02:00:11 -080098 this.handleClose();
sebdet83ce0762019-08-02 14:53:59 +020099 this.props.loadLoopFunction(this.state.chosenLoopName);
xuegaof248df62019-07-15 15:16:18 +0200100 }
sebdet493c3832019-07-15 17:26:18 +0200101
xuegaof248df62019-07-15 15:16:18 +0200102 render() {
103 return (
jingjincs3173d552020-03-04 09:11:10 +0100104 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}>
xuegaof248df62019-07-15 15:16:18 +0200105 <Modal.Header closeButton>
106 <Modal.Title>Open Model</Modal.Title>
107 </Modal.Header>
108 <Modal.Body>
109 <Form.Group as={Row} controlId="formPlaintextEmail">
110 <Form.Label column sm="2">Model Name</Form.Label>
111 <Col sm="10">
jingjincs3173d552020-03-04 09:11:10 +0100112 <Select onChange={this.handleDropdownListChange}
113 options={this.state.loopNames} />
xuegaof248df62019-07-15 15:16:18 +0200114 </Col>
115 </Form.Group>
jingjincs3173d552020-03-04 09:11:10 +0100116 <Form.Group controlId="formPlaintextEmail">
117 <LoopViewSvgDivStyled dangerouslySetInnerHTML={{ __html: this.state.content }} value={this.state.content} >
118 </LoopViewSvgDivStyled>
119 </Form.Group>
xuegaof248df62019-07-15 15:16:18 +0200120 <Form.Group controlId="formBasicChecbox">
sebdet493c3832019-07-15 17:26:18 +0200121 <Form.Check>
xuegaof248df62019-07-15 15:16:18 +0200122 <FormCheck.Label>Read Only</FormCheck.Label>
123 <CheckBoxStyled type="checkbox" />
124 </Form.Check>
sebdet493c3832019-07-15 17:26:18 +0200125 </Form.Group>
xuegaof248df62019-07-15 15:16:18 +0200126 </Modal.Body>
127 <Modal.Footer>
sebdet493c3832019-07-15 17:26:18 +0200128 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
sebdet5f6c1782019-07-18 15:23:13 +0200129 <Button variant="primary" type="submit" onClick={this.handleOpen}>Open</Button>
xuegaof248df62019-07-15 15:16:18 +0200130 </Modal.Footer>
131 </ModalStyled>
132
133 );
134 }
135}