xuegao | b09e7df | 2019-07-23 14:13:06 +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 Button from 'react-bootstrap/Button'; |
| 25 | import Modal from 'react-bootstrap/Modal'; |
| 26 | import Form from 'react-bootstrap/Form'; |
| 27 | import styled from 'styled-components'; |
| 28 | import LoopService from '../../api/LoopService'; |
| 29 | |
| 30 | const ModalStyled = styled(Modal)` |
| 31 | background-color: transparent; |
| 32 | ` |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 33 | export default class LoopProperties extends React.Component { |
| 34 | |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 35 | state = { |
| 36 | show: true, |
| 37 | loopCache: this.props.loopCache, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 38 | temporaryPropertiesJson: JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())) |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 39 | }; |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 40 | |
| 41 | constructor(props, context) { |
| 42 | super(props, context); |
| 43 | |
| 44 | this.handleClose = this.handleClose.bind(this); |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 45 | this.handleSave = this.handleSave.bind(this); |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 46 | this.handleChange = this.handleChange.bind(this); |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 47 | |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 48 | this.renderDcaeParameters = this.renderDcaeParameters.bind(this); |
| 49 | this.renderAllParameters = this.renderAllParameters.bind(this); |
| 50 | this.getDcaeParameters = this.getDcaeParameters.bind(this); |
| 51 | } |
| 52 | |
| 53 | componentWillReceiveProps(newProps) { |
| 54 | this.setState({ |
| 55 | loopCache: newProps.loopCache, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 56 | temporaryPropertiesJson: JSON.parse(JSON.stringify(newProps.loopCache.getGlobalProperties())) |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 57 | }); |
| 58 | } |
| 59 | |
| 60 | handleClose() { |
| 61 | this.props.history.push('/'); |
| 62 | } |
| 63 | |
| 64 | handleSave(event) { |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 65 | LoopService.updateGlobalProperties(this.state.loopCache.getLoopName(), this.state.temporaryPropertiesJson).then(resp => { |
| 66 | this.setState({ show: false }); |
| 67 | this.props.history.push('/'); |
| 68 | this.props.loadLoopFunction(this.state.loopCache.getLoopName()); |
| 69 | }); |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 70 | } |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 71 | |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 72 | handleChange(event) { |
| 73 | this.setState({temporaryPropertiesJson:{[event.target.name]: JSON.parse(event.target.value)}}); |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 74 | } |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 75 | |
| 76 | renderAllParameters() { |
| 77 | return (<Modal.Body> |
| 78 | <Form> |
| 79 | {this.renderDcaeParameters()} |
| 80 | </Form> |
| 81 | </Modal.Body> |
| 82 | ); |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 83 | } |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 84 | |
| 85 | getDcaeParameters() { |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 86 | if (typeof (this.state.temporaryPropertiesJson) !== "undefined") { |
| 87 | return JSON.stringify(this.state.temporaryPropertiesJson["dcaeDeployParameters"]); |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 88 | } else { |
| 89 | return ""; |
| 90 | } |
xuegao | 691e2b7 | 2019-08-16 11:07:24 +0200 | [diff] [blame] | 91 | |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 92 | } |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 93 | |
| 94 | renderDcaeParameters() { |
| 95 | return ( |
| 96 | <Form.Group > |
| 97 | <Form.Label>Deploy Parameters</Form.Label> |
sebdet | 83ce076 | 2019-08-02 14:53:59 +0200 | [diff] [blame] | 98 | <Form.Control as="textarea" rows="3" name="dcaeDeployParameters" onChange={this.handleChange} defaultValue={this.getDcaeParameters()}></Form.Control> |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 99 | </Form.Group> |
| 100 | ); |
| 101 | } |
| 102 | |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 103 | render() { |
| 104 | return ( |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 105 | <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} > |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 106 | <Modal.Header closeButton> |
| 107 | <Modal.Title>Model Properties</Modal.Title> |
| 108 | </Modal.Header> |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 109 | {this.renderAllParameters()} |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 110 | <Modal.Footer> |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 111 | <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button> |
| 112 | <Button variant="primary" type="submit" onClick={this.handleSave}>Save Changes</Button> |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 113 | </Modal.Footer> |
| 114 | </ModalStyled> |
| 115 | ); |
| 116 | } |
| 117 | } |