blob: dac77655f9c13671f11b85d27ebbc2782395615d [file] [log] [blame]
xuegaob09e7df2019-07-23 14:13:06 +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 Button from 'react-bootstrap/Button';
25import Modal from 'react-bootstrap/Modal';
26import Form from 'react-bootstrap/Form';
27import styled from 'styled-components';
28import LoopService from '../../api/LoopService';
29
30const ModalStyled = styled(Modal)`
31 background-color: transparent;
32`
33
34export default class LoopProperties extends React.Component {
35
sebdet8a02dd72019-07-31 17:11:11 +020036 state = {
37 show: true,
38 loopCache: this.props.loopCache,
sebdet83ce0762019-08-02 14:53:59 +020039 temporaryPropertiesJson: JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())),
sebdet8a02dd72019-07-31 17:11:11 +020040 };
xuegaob09e7df2019-07-23 14:13:06 +020041
42 constructor(props, context) {
43 super(props, context);
44
45 this.handleClose = this.handleClose.bind(this);
sebdet8a02dd72019-07-31 17:11:11 +020046 this.handleSave = this.handleSave.bind(this);
sebdet83ce0762019-08-02 14:53:59 +020047 this.handleChange = this.handleChange.bind(this);
48
sebdet8a02dd72019-07-31 17:11:11 +020049 this.renderDcaeParameters = this.renderDcaeParameters.bind(this);
50 this.renderAllParameters = this.renderAllParameters.bind(this);
51 this.getDcaeParameters = this.getDcaeParameters.bind(this);
52 }
53
54 componentWillReceiveProps(newProps) {
55 this.setState({
56 loopCache: newProps.loopCache,
sebdet83ce0762019-08-02 14:53:59 +020057 temporaryPropertiesJson: JSON.parse(JSON.stringify(newProps.loopCache.getGlobalProperties())),
58
sebdet8a02dd72019-07-31 17:11:11 +020059 });
60 }
61
62 handleClose() {
63 this.props.history.push('/');
64 }
65
66 handleSave(event) {
sebdet83ce0762019-08-02 14:53:59 +020067 LoopService.updateGlobalProperties(this.state.loopCache.getLoopName(), this.state.temporaryPropertiesJson).then(resp => {
68 this.setState({ show: false });
69 this.props.history.push('/');
70 this.props.loadLoopFunction(this.state.loopCache.getLoopName());
71 });
xuegaob09e7df2019-07-23 14:13:06 +020072 }
sebdet8a02dd72019-07-31 17:11:11 +020073
sebdet83ce0762019-08-02 14:53:59 +020074 handleChange(event) {
75 this.setState({temporaryPropertiesJson:{[event.target.name]: JSON.parse(event.target.value)}});
xuegaob09e7df2019-07-23 14:13:06 +020076 }
sebdet8a02dd72019-07-31 17:11:11 +020077
78 renderAllParameters() {
79 return (<Modal.Body>
80 <Form>
81 {this.renderDcaeParameters()}
82 </Form>
83 </Modal.Body>
84 );
xuegaob09e7df2019-07-23 14:13:06 +020085 }
sebdet8a02dd72019-07-31 17:11:11 +020086
87 getDcaeParameters() {
sebdet83ce0762019-08-02 14:53:59 +020088 if (typeof (this.state.temporaryPropertiesJson) !== "undefined") {
89 return JSON.stringify(this.state.temporaryPropertiesJson["dcaeDeployParameters"]);
sebdet8a02dd72019-07-31 17:11:11 +020090 } else {
91 return "";
92 }
93
xuegaob09e7df2019-07-23 14:13:06 +020094 }
sebdet8a02dd72019-07-31 17:11:11 +020095
96 renderDcaeParameters() {
97 return (
98 <Form.Group >
99 <Form.Label>Deploy Parameters</Form.Label>
sebdet83ce0762019-08-02 14:53:59 +0200100 <Form.Control as="textarea" rows="3" name="dcaeDeployParameters" onChange={this.handleChange} defaultValue={this.getDcaeParameters()}></Form.Control>
sebdet8a02dd72019-07-31 17:11:11 +0200101 </Form.Group>
102 );
103 }
104
xuegaob09e7df2019-07-23 14:13:06 +0200105 render() {
106 return (
sebdet8a02dd72019-07-31 17:11:11 +0200107 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} >
xuegaob09e7df2019-07-23 14:13:06 +0200108 <Modal.Header closeButton>
109 <Modal.Title>Model Properties</Modal.Title>
110 </Modal.Header>
sebdet8a02dd72019-07-31 17:11:11 +0200111 {this.renderAllParameters()}
xuegaob09e7df2019-07-23 14:13:06 +0200112 <Modal.Footer>
sebdet8a02dd72019-07-31 17:11:11 +0200113 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
114 <Button variant="primary" type="submit" onClick={this.handleSave}>Save Changes</Button>
xuegaob09e7df2019-07-23 14:13:06 +0200115 </Modal.Footer>
116 </ModalStyled>
117 );
118 }
119}