blob: 990fe775437801ebce4b67a8bdb36d5cc078d801 [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,
sebdet337f3662019-09-06 18:11:51 +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,
sebdet337f3662019-09-06 18:11:51 +020056 temporaryPropertiesJson: JSON.parse(JSON.stringify(newProps.loopCache.getGlobalProperties()))
sebdet8a02dd72019-07-31 17:11:11 +020057 });
58 }
59
60 handleClose() {
61 this.props.history.push('/');
62 }
63
64 handleSave(event) {
sebdet83ce0762019-08-02 14:53:59 +020065 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 });
xuegaob09e7df2019-07-23 14:13:06 +020070 }
sebdet8a02dd72019-07-31 17:11:11 +020071
sebdet83ce0762019-08-02 14:53:59 +020072 handleChange(event) {
73 this.setState({temporaryPropertiesJson:{[event.target.name]: JSON.parse(event.target.value)}});
xuegaob09e7df2019-07-23 14:13:06 +020074 }
sebdet8a02dd72019-07-31 17:11:11 +020075
76 renderAllParameters() {
77 return (<Modal.Body>
78 <Form>
79 {this.renderDcaeParameters()}
80 </Form>
81 </Modal.Body>
82 );
xuegaob09e7df2019-07-23 14:13:06 +020083 }
sebdet8a02dd72019-07-31 17:11:11 +020084
85 getDcaeParameters() {
sebdet83ce0762019-08-02 14:53:59 +020086 if (typeof (this.state.temporaryPropertiesJson) !== "undefined") {
87 return JSON.stringify(this.state.temporaryPropertiesJson["dcaeDeployParameters"]);
sebdet8a02dd72019-07-31 17:11:11 +020088 } else {
89 return "";
90 }
xuegao691e2b72019-08-16 11:07:24 +020091
xuegaob09e7df2019-07-23 14:13:06 +020092 }
sebdet8a02dd72019-07-31 17:11:11 +020093
94 renderDcaeParameters() {
95 return (
96 <Form.Group >
97 <Form.Label>Deploy Parameters</Form.Label>
sebdet83ce0762019-08-02 14:53:59 +020098 <Form.Control as="textarea" rows="3" name="dcaeDeployParameters" onChange={this.handleChange} defaultValue={this.getDcaeParameters()}></Form.Control>
sebdet8a02dd72019-07-31 17:11:11 +020099 </Form.Group>
100 );
101 }
102
xuegaob09e7df2019-07-23 14:13:06 +0200103 render() {
104 return (
sebdet8a02dd72019-07-31 17:11:11 +0200105 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} >
xuegaob09e7df2019-07-23 14:13:06 +0200106 <Modal.Header closeButton>
107 <Modal.Title>Model Properties</Modal.Title>
108 </Modal.Header>
sebdet8a02dd72019-07-31 17:11:11 +0200109 {this.renderAllParameters()}
xuegaob09e7df2019-07-23 14:13:06 +0200110 <Modal.Footer>
sebdet8a02dd72019-07-31 17:11:11 +0200111 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
112 <Button variant="primary" type="submit" onClick={this.handleSave}>Save Changes</Button>
xuegaob09e7df2019-07-23 14:13:06 +0200113 </Modal.Footer>
114 </ModalStyled>
115 );
116 }
117}