blob: fa82a7e48ee02588cceda7a833cd0b0611a29ac1 [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`
xuegaob09e7df2019-07-23 14:13:06 +020033export default class LoopProperties extends React.Component {
34
sebdet8a02dd72019-07-31 17:11:11 +020035 state = {
36 show: true,
37 loopCache: this.props.loopCache,
sebdet83ce0762019-08-02 14:53:59 +020038 temporaryPropertiesJson: JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())),
sebdet8a02dd72019-07-31 17:11:11 +020039 };
xuegaob09e7df2019-07-23 14:13:06 +020040
41 constructor(props, context) {
42 super(props, context);
43
44 this.handleClose = this.handleClose.bind(this);
sebdet8a02dd72019-07-31 17:11:11 +020045 this.handleSave = this.handleSave.bind(this);
sebdet83ce0762019-08-02 14:53:59 +020046 this.handleChange = this.handleChange.bind(this);
xuegao691e2b72019-08-16 11:07:24 +020047
sebdet8a02dd72019-07-31 17:11:11 +020048 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,
sebdet83ce0762019-08-02 14:53:59 +020056 temporaryPropertiesJson: JSON.parse(JSON.stringify(newProps.loopCache.getGlobalProperties())),
xuegao691e2b72019-08-16 11:07:24 +020057
sebdet8a02dd72019-07-31 17:11:11 +020058 });
59 }
60
61 handleClose() {
62 this.props.history.push('/');
63 }
64
65 handleSave(event) {
sebdet83ce0762019-08-02 14:53:59 +020066 LoopService.updateGlobalProperties(this.state.loopCache.getLoopName(), this.state.temporaryPropertiesJson).then(resp => {
67 this.setState({ show: false });
68 this.props.history.push('/');
69 this.props.loadLoopFunction(this.state.loopCache.getLoopName());
70 });
xuegaob09e7df2019-07-23 14:13:06 +020071 }
sebdet8a02dd72019-07-31 17:11:11 +020072
sebdet83ce0762019-08-02 14:53:59 +020073 handleChange(event) {
74 this.setState({temporaryPropertiesJson:{[event.target.name]: JSON.parse(event.target.value)}});
xuegaob09e7df2019-07-23 14:13:06 +020075 }
sebdet8a02dd72019-07-31 17:11:11 +020076
77 renderAllParameters() {
78 return (<Modal.Body>
79 <Form>
80 {this.renderDcaeParameters()}
81 </Form>
82 </Modal.Body>
83 );
xuegaob09e7df2019-07-23 14:13:06 +020084 }
sebdet8a02dd72019-07-31 17:11:11 +020085
86 getDcaeParameters() {
sebdet83ce0762019-08-02 14:53:59 +020087 if (typeof (this.state.temporaryPropertiesJson) !== "undefined") {
88 return JSON.stringify(this.state.temporaryPropertiesJson["dcaeDeployParameters"]);
sebdet8a02dd72019-07-31 17:11:11 +020089 } else {
90 return "";
91 }
xuegao691e2b72019-08-16 11:07:24 +020092
xuegaob09e7df2019-07-23 14:13:06 +020093 }
sebdet8a02dd72019-07-31 17:11:11 +020094
95 renderDcaeParameters() {
96 return (
97 <Form.Group >
98 <Form.Label>Deploy Parameters</Form.Label>
sebdet83ce0762019-08-02 14:53:59 +020099 <Form.Control as="textarea" rows="3" name="dcaeDeployParameters" onChange={this.handleChange} defaultValue={this.getDcaeParameters()}></Form.Control>
sebdet8a02dd72019-07-31 17:11:11 +0200100 </Form.Group>
101 );
102 }
103
xuegaob09e7df2019-07-23 14:13:06 +0200104 render() {
105 return (
sebdet8a02dd72019-07-31 17:11:11 +0200106 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} >
xuegaob09e7df2019-07-23 14:13:06 +0200107 <Modal.Header closeButton>
108 <Modal.Title>Model Properties</Modal.Title>
109 </Modal.Header>
sebdet8a02dd72019-07-31 17:11:11 +0200110 {this.renderAllParameters()}
xuegaob09e7df2019-07-23 14:13:06 +0200111 <Modal.Footer>
sebdet8a02dd72019-07-31 17:11:11 +0200112 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
113 <Button variant="primary" type="submit" onClick={this.handleSave}>Save Changes</Button>
xuegaob09e7df2019-07-23 14:13:06 +0200114 </Modal.Footer>
115 </ModalStyled>
116 );
117 }
118}