xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 1 | /*- |
| 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 | |
| 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'; |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 32 | import LoopService from '../../../api/LoopService'; |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 33 | |
| 34 | const ModalStyled = styled(Modal)` |
| 35 | background-color: transparent; |
| 36 | ` |
| 37 | const CheckBoxStyled = styled(FormCheck.Input)` |
| 38 | margin-left:3rem; |
| 39 | ` |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 40 | const 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 | ` |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 48 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 49 | export default class OpenLoopModal extends React.Component { |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 50 | constructor(props, context) { |
| 51 | super(props, context); |
| 52 | |
| 53 | this.getLoopNames = this.getLoopNames.bind(this); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 54 | this.handleOpen = this.handleOpen.bind(this); |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 55 | this.handleClose = this.handleClose.bind(this); |
| 56 | this.handleDropdownListChange = this.handleDropdownListChange.bind(this); |
| 57 | this.state = { |
| 58 | show: true, |
| 59 | chosenLoopName: '', |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 60 | loopNames: [], |
| 61 | content:'' |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 62 | }; |
| 63 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 64 | |
sebdet | 2dacb9b | 2019-07-17 13:48:44 +0200 | [diff] [blame] | 65 | componentWillMount() { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 66 | this.getLoopNames(); |
| 67 | } |
| 68 | |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 69 | handleClose() { |
| 70 | this.setState({ show: false }); |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 71 | this.props.history.push('/'); |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 72 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 73 | |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 74 | handleDropdownListChange(e) { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 75 | this.setState({ chosenLoopName: e.value }); |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 76 | 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 | }); |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 83 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 84 | |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 85 | getLoopNames() { |
| 86 | LoopService.getLoopNames().then(loopNames => { |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 87 | 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 }) |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 90 | |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 91 | } |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 92 | |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 93 | }); |
| 94 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 95 | |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 96 | handleOpen() { |
| 97 | console.info("Loop " + this.state.chosenLoopName + " is chosen"); |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 98 | this.handleClose(); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 99 | this.props.loadLoopFunction(this.state.chosenLoopName); |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 100 | } |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 101 | |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 102 | render() { |
| 103 | return ( |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 104 | <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}> |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 105 | <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"> |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 112 | <Select onChange={this.handleDropdownListChange} |
| 113 | options={this.state.loopNames} /> |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 114 | </Col> |
| 115 | </Form.Group> |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 116 | <Form.Group controlId="formPlaintextEmail"> |
| 117 | <LoopViewSvgDivStyled dangerouslySetInnerHTML={{ __html: this.state.content }} value={this.state.content} > |
| 118 | </LoopViewSvgDivStyled> |
| 119 | </Form.Group> |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 120 | <Form.Group controlId="formBasicChecbox"> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 121 | <Form.Check> |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 122 | <FormCheck.Label>Read Only</FormCheck.Label> |
| 123 | <CheckBoxStyled type="checkbox" /> |
| 124 | </Form.Check> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 125 | </Form.Group> |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 126 | </Modal.Body> |
| 127 | <Modal.Footer> |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 128 | <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button> |
sebdet | 5f6c178 | 2019-07-18 15:23:13 +0200 | [diff] [blame] | 129 | <Button variant="primary" type="submit" onClick={this.handleOpen}>Open</Button> |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 130 | </Modal.Footer> |
| 131 | </ModalStyled> |
| 132 | |
| 133 | ); |
| 134 | } |
| 135 | } |